-
Notifications
You must be signed in to change notification settings - Fork 156
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
Add line selection shortcuts #403
Conversation
@@ -76,6 +94,13 @@ export const DEFAULT_KEY_COMMANDS = [{ | |||
} | |||
} | |||
}, { | |||
str: 'META+SHIFT+LEFT', | |||
run(editor) { | |||
if (Browser.isMac) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker for this PR, but we've really got to figure out a more generic solution for environment-dependent hotkeys. Phew.
@lessless in a multi-line section, wouldn't this highlight to the start of a section and tail of a section from the cursor and not the line? |
This looks pretty good. The Range constructor takes a third argument for direction, and that is the preferred way to construct new ranges (instead of setting the .direction property on the range). I'll take a closer look at the tests later. |
@mixonic good catch! Can you suggest how to get an end of the line? |
@bantic what are you thinking about:
|
@lessless we should be wary of introducing cursor controls (or any hotkeys) that aren't compatible with the native experience. Creating our own set of bindings would be fairly trivial from an engineering perspective, but a bit trolling from the perspective of user experience. I'd like to see the implementation of this rule be accurate to what a native text editing surface (like TextEdit on OSX) would do. In general our goal for user interactions should be that they are as unsurprising as possible. The mobiledoc-kit editing surface has avoided introspection of layout as much as possible. @bantic mentioned we do it for one spot in the code earlier this morning in passing, we can find a link shortly. The algorithm for finding the start/end of the line can probably be fairly boring- identify the cursor's y-position and the x-position of the side of the text area, create a bounding rectangle and see what part of a text node is there, map that text node and char back to a marker. |
@mixonic are we talking about |
@lessless no mouse involved- the aim is to determine what the left-most and right-most characters are in a line. Mobiledoc-kit knows nothing about line wrapping today. To accurately implement the cursor behavior you're building here, we need to have a way to determine the edge positions for a selection. |
Just to keep conversation in one place:
|
@lessless Thank you very much for this PR, and I'm sorry that it has lingered so long! We opted to use selection polling to keep the editor's range in sync with the dom's range, which greatly simplifies the internal code for reacting to keyboard-related movement key combinations. Using the modifier keys + arrow keys to move now "just works" without having to whitelist particular browser key combinations. Unfortunately the movement key combos with delete don't benefit from this, so option- and alt + delete is implemented separately and as a result we still don't have delete-to-end-of-line (meta+delete on Mac, e.g.). I'll add an issue to track that (we'll need to use a positioning heuristic to find the start/end of a given line; |
This PR is intended to introduce line selection functionality on OS X:
CMD+SHIFT+LEFT
text is selected from the cursor position till the beginning of the lineCMD+SHIFT+RIGHT
text is selected from the cursor position till the end of the line