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

Allow select text when shift key pressed #36

Open
stevebelt opened this issue Dec 11, 2017 · 1 comment
Open

Allow select text when shift key pressed #36

stevebelt opened this issue Dec 11, 2017 · 1 comment

Comments

@stevebelt
Copy link

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

@rolandtoth
Copy link

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

(e.ctrlKey || e.shiftKey)

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

No branches or pull requests

2 participants