Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAllows mac shortcuts to be used when inside a input element #12549
Conversation
highfive
commented
Jul 22, 2016
|
Heads up! This PR modifies the following files:
|
This adds the following navigation helpers on macOS: Alt+LeftArrow / Alt+RightArrow - Jump to previous / next word in the input. Control+Alt+B / Control+Alt+F - Jump to previous / next word in the input. CMD+LeftArrow / CMD+RightArrow - Jump to beginning / end of the input. Control+A / Control+E - Jump to the beginning / end of the input. It also respects shift when using these shortcuts to make a selection.
46e5777
to
f35888b
|
Thank you for the PR. Maybe in the future we'll want to use widget code for keybindings. For example: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html |
|
r? @paulrouget |
|
@bors-servo delegate=paulrouget |
|
|
|
I can review the behavior, but I'd like someone else to review the rust code (It looks good to me though). Cmd+up/down, Ctrl+up/down, Cmd+home/end, Ctrl+a/e should move the cursor at the beginning/end of the whole text. Option+up/down, should move the cursor at the beginning/end of the current line or of the next line if at the beginning/end of the current line. There's probably more moves I missed. I think we should cover the bindings found in Gecko:
We don't have to support the editing related bindings in this PR I think. Let's focus on getting the moves right. |
| // UTF-8 character has variable size. | ||
| for ch in current_line[self.edit_point.index..].chars() { | ||
| i = i + (ch.len_utf8() as isize); | ||
| } |
This comment has been minimized.
This comment has been minimized.
pcwalton
Aug 8, 2016
•
Contributor
How about current_line[self.edit_point.index..].chars().map(char::len_utf8()).sum() as isize?
| Some(ch) => i = i - (ch.len_utf8() as isize), | ||
| None => break, | ||
| } | ||
| } |
This comment has been minimized.
This comment has been minimized.
pcwalton
Aug 8, 2016
Contributor
How about i -= current_line[..self.edit_point.index].chars().map(char::len_utf8()).sum() as isize?
| (Some('c'), _) if is_control_key(mods) => { | ||
| if let Some(text) = self.get_selection_text() { | ||
| self.clipboard_provider.set_clipboard_contents(text); | ||
| } | ||
| KeyReaction::DispatchInput | ||
| }, | ||
| #[cfg(target_os = "macos")] | ||
| (Some('e'), _) if (mods == CONTROL) || (mods == CONTROL | SHIFT) => { |
This comment has been minimized.
This comment has been minimized.
| (None, Key::Right) => { | ||
| self.adjust_horizontal_by_one(Direction::Forward, maybe_select); | ||
| KeyReaction::RedrawSelection | ||
| } | ||
| }, |
This comment has been minimized.
This comment has been minimized.
| let mut found_non_whitespace = false; | ||
| let mut edit_point_index = Some(self.edit_point.index); | ||
|
|
||
| 'line: for line in self.lines[self.edit_point.line..].iter() { |
This comment has been minimized.
This comment has been minimized.
| None => line.chars(), | ||
| }; | ||
|
|
||
| 'chars: for ch in char_iter { |
This comment has been minimized.
This comment has been minimized.
pcwalton
Aug 8, 2016
Contributor
Could just be for ch in line[edit_point_index.unwrap_or(0)..].chars() {. Also no need for the 'chars:
| // of the next line. | ||
| if found_non_whitespace { break 'line; } | ||
|
|
||
| adjust = adjust + 1; // Account for newline character |
This comment has been minimized.
This comment has been minimized.
|
r? @pcwalton |
|
|
|
Closing due to lack of activity. |
jimberlage commentedJul 22, 2016
•
edited by larsbergstrom
This adds the following navigation helpers on macOS:
Alt+LeftArrow / Alt+RightArrow - Jump to previous / next word in the
input.
Control+Alt+B / Control+Alt+F - Jump to previous / next word in the
input.
CMD+LeftArrow / CMD+RightArrow - Jump to beginning / end of the input.
Control+A / Control+E - Jump to the beginning / end of the
input.
It also respects shift when using these shortcuts to make a selection.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is