Add setting for dragging to select text. - #17
Conversation
For use in apps (e.g., some PDF viewers) that do not support clicking to set an insertion point position, nor using the keyboard to select.
wolfmanstout
left a comment
There was a problem hiding this comment.
Thank you for putting this together!
| click_offset_right: int = 0, | ||
| hold_shift: bool = False, | ||
| start_drag: bool = False, | ||
| end_drag: bool = False, |
There was a problem hiding this comment.
This is unused. I suspect the reason why it is still working is brittle: click() is probably implemented as "click_down(); click_up()", and so the click_down() is a no-op and click() has the effect of click_up(). I don't think we want to rely on that; it's not hard to imagine that calling click() when the button is already down could become an error, or it could call click_up() at the start, etc.
I'd suggest adding an end_drag arg to _move_text_cursor_to_word_locations, having that perform click_up(), and then you can pass this along to that.
| return None | ||
| finally: | ||
| self.keyboard.shift_up() | ||
| if drag: |
There was a problem hiding this comment.
This needs to be pulled out into a separate & larger try/finally block, so that any early returns in the function won't leave the mouse in a bad (down) state. Since this risk is introduced very early in the function with the call to move_text_cursor_to_words_generator, the simplest might be to simply rename this function with an "_unsafe" suffix and then reimplement this whole function as simply a try block that wraps the call to the unsafe() function and a finally block that calls click_up().
For use in apps (e.g., some PDF viewers) that do not support clicking to set an insertion point position, nor using the keyboard to select.