fastaddons / ScrollAnywhere

This repository is for tracking bugs and documentation only
Other
27 stars 1 forks source link

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

Open dnknn opened 2 years ago

dnknn commented 2 years ago

First look at the screenshot - UI options


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.

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?❓

fastaddons commented 2 years ago

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 commented 2 years ago

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 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!