Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suboptions: Middle-click paste only works with single-line input boxes ! #48

Open
dnknn opened this issue Apr 16, 2022 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@dnknn
Copy link

dnknn commented Apr 16, 2022

First look at the screenshot - UI options

  • enable ☑ middle click to ScrollAnywhere.
    • and enable ☑ Use middle click to "paste" content of the clipboard
      • and enable ☑ only paste with single-line input boxes

I think you should probably understand the meaning!

In other words, it is recommended to add a new sub-option.
When this sub-option is enabled, the paste behavior will determine the element type of the input/edit box.

  • Why is such an extra suboption needed?
    Because in multi-line input/edit boxes like textarea, I want middle-click scrolling, but don't want to trigger accidental paste behavior. In a multi-line edit box, it is easy to accidentally trigger paste without knowing it. But in a simple single-line edit box, even if the paste is accidentally triggered, it can be easily found.
    Also because of this feature suggestion, it is easy to be implemented.
    So came up with the idea, for some people, to get the best balance between scrolling and pasting behavior of the middle-click.

  • single-line input boxes:
    input[type=text] input[type=search] input[type=number] ...
  • multi-line input boxes:
    textarea [contenteditable=true] / isContentEditable

Mouse events can determine the element type, so we can easily implement,

I don't understand the overall event logic of ScrollAnywhere, but the simple code of the function is about as follows

addEventListener(`mouseup`, e=>	{
	const TARGET = e.target;

	if (UserOptions.PASTE && e.button===1 && TARGET.matches(`input[type=text], input[type=search], input[type=number]` &&!e.ctrlKey&&!e.shiftKey&&!e.altKey)	{
		event.preventDefault();event.stopPropagation();event.stopImmediatePropagation();
		// Do: Use middle click to "paste" content of the clipboard
	}

	// or 👇 recommended to use the negative exclusion method to write more perfectly!

	if (UserOptions.PASTE && e.button===1 &&! (TARGET.matches(`textarea`) || TARGET.isContentEditable)  &&!e.ctrlKey&&!e.shiftKey&&!e.altKey)	{
		// Do: Use middle click to "paste" content of the clipboard
	}

});

That is to say, Paste behavior is only triggered when not (TARGET.matches('textarea') || TARGET.isContentEditable)


So, is it possible to add a suboption for this feature?❓

@dnknn dnknn added the enhancement New feature or request label Apr 16, 2022
@fastaddons
Copy link
Collaborator

Hmm... did you actually accidentally pasted a text instead of scrolling?
The pasting will happen only if you click, without a single move of the mouse, so it should be rare.

I need to test it more myself, but if this is something people would use, I don't see why not.
Also, no need to add code snippets :), I know my stuff very well :).

@dnknn
Copy link
Author

dnknn commented Apr 16, 2022

Hmm... did you actually accidentally pasted a text instead of scrolling?

It is the accident of worrying about misoperation, and I don't know that I have pasted the text.

  • For multi-line edit boxes such as textarea, it is best to be careful when editing, right?
  • For the clipboard, there may be dozens of hundreds of thousands of lines of text, if you accidentally paste it by middle-click....
  • In general, in a multi-line edit box, I don't want the middle-click to trigger the paste. Although pressing the middle button and middle-click are two different events, they are deeply related after all...

For a simple single-line edit box, we don't need to think too much and don't need too much careful.
At the same time, the common scenarios of middle-click paste are enabled.
For example, sometimes you don't want to use the keyboard(Ctrl+V) or right-click contextmenu, but directly paste the keyword with the middle-click of the mouse in the search box of the page, and then click the search button to open the search results!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant