dragscroll icon indicating copy to clipboard operation
dragscroll copied to clipboard

Allow select text when shift key pressed

Open stevebelt opened this issue 7 years ago • 1 comments

Excellent Library - Thanks!

Our users want to be able to select text within the dragscroll area. So I modified your code to verify the user pressed the left-button, and they did NOT have the shift key pressed. This works perfect in Chrome, but IE and Firefox have trouble selecting text when I press the shift key: These browsers ignore where my drag started, so they assume I am selecting from the start of the webpage to the current cursor position. Here is a snippet of the change I made:

...
(cont = el.container || el)[addEventListener](
   mousedown,
   cont.md = function(e) {
    if (
      e.button === 0
      &&
      !e.shiftKey
      &&
      (!el.hasAttribute('nochilddrag') ||
      _document.elementFromPoint(
      e.pageX, e.pageY) == cont )
    ) {
      pushed = 1;
      ...

As I say, works perfectly in Chrome. I am thinking I need to add some kind of javascript to onmousedown which says, "range selection starts here". I am not sure how to do this.

Here is a jsfiddle to see it in action

stevebelt avatar Dec 11 '17 21:12 stevebelt

I've modified your code to scroll only if shift or ctrl key is pressed, and select text if not:

(e.ctrlKey || e.shiftKey)

rolandtoth avatar Sep 13 '18 10:09 rolandtoth