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 upadded keyboard shortcuts for navigation inside text box #15666
Conversation
highfive
commented
Feb 21, 2017
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
highfive
commented
Feb 21, 2017
|
Mostly looks good, though there are some UI issues that I'm not sure about, not being a UI person. |
| @@ -4,11 +4,14 @@ | |||
|
|
|||
| //! Common handling of keyboard input and state management for text input controls | |||
|
|
|||
| extern crate unicode_segmentation; | |||
This comment has been minimized.
This comment has been minimized.
| use clipboard_provider::ClipboardProvider; | ||
| use dom::bindings::str::DOMString; | ||
| use dom::keyboardevent::KeyboardEvent; | ||
| use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; | ||
| use msg::constellation_msg::{Key, KeyModifiers}; | ||
| use self::unicode_segmentation::UnicodeSegmentation; |
This comment has been minimized.
This comment has been minimized.
| None => 0, | ||
| Some(i) => { | ||
| - (input.len() as isize + newline_adjustment as isize | ||
| - input.rfind(i).expect("no words to the left on this line") as isize) |
This comment has been minimized.
This comment has been minimized.
asajeffrey
Feb 21, 2017
Member
Is there a way to avoid using rfind here? We're finding the last word, then searching back for it, which is less efficient than it could be.
This comment has been minimized.
This comment has been minimized.
clementmiao
Feb 27, 2017
Author
Contributor
I just updated with a new commit that does not use rfind
| (_, Key::E) if mods.contains(CONTROL | ALT) => { | ||
| self.adjust_horizontal_to_end(Direction::Forward, maybe_select); | ||
| KeyReaction::RedrawSelection | ||
| } |
This comment has been minimized.
This comment has been minimized.
asajeffrey
Feb 21, 2017
Member
Do we want these key bindings on all OSs? On, e.g. Linux, CTRL-F is "find", not "forward".
This comment has been minimized.
This comment has been minimized.
clementmiao
Feb 22, 2017
Author
Contributor
this will be for if CONTROL + ALT + F are all pressed together, so in theory it should not trigger the CTRL-F shortcut. I can add that as a test though
This comment has been minimized.
This comment has been minimized.
| (Some('a'), _) if is_control_key(mods) => { | ||
| self.select_all(); | ||
| KeyReaction::RedrawSelection | ||
| }, | ||
| } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
clementmiao
Feb 22, 2017
Author
Contributor
I noticed before my commit that some are them are without commas between match branches, not sure which one is more idiomatic. Do you prefer with commas or without?
This comment has been minimized.
This comment has been minimized.
| (None, Key::Right) if mods.contains(ALT) => { | ||
| self.adjust_horizontal_by_word(Direction::Forward, maybe_select); | ||
| KeyReaction::RedrawSelection | ||
| } |
This comment has been minimized.
This comment has been minimized.
asajeffrey
Feb 21, 2017
Member
Should ALT-Left and ALT-Right be forward and backward traversal of the session history?
This comment has been minimized.
This comment has been minimized.
clementmiao
Feb 22, 2017
Author
Contributor
I was going by the instructions in issue #12278 , but I can change it if you would prefer ALT-LEFT and ALT-Right to be used for something else. This would be within a text box only though.
This comment has been minimized.
This comment has been minimized.
asajeffrey
Feb 22, 2017
Member
Not sure about this, I'm not exactly a UI person! @paulrouget, any opinions?
| assert_eq!(textinput.edit_point.index, 0); | ||
| } | ||
|
|
||
| #[test] |
This comment has been minimized.
This comment has been minimized.
| None => break, | ||
| Some(x) => { | ||
| shift_temp += - (x.len() as isize); | ||
| if x.chars().any(|x| x.is_alphabetic() || x.is_numeric()) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
clementmiao
Feb 27, 2017
•
Author
Contributor
The unicode-segmentation crate (using .split_word_bounds()) determines word boundaries differently than how it should be implemented for this keyboard shortcut.
For example, "hello .. world" would be split up as ["hello", " ", ".", ".", " ","world"], whereas if the cursor was for example at the end of "hello", you would want this function to jump to the end of the "world" word. Hence you want it to ignore whitespaces and non alphabetic or numeric characters when evaluating where the next jump to is.
This comment has been minimized.
This comment has been minimized.
|
At this point, the code looks good from a programming point of view, it could do with a review from a UI perspective though. @paulrouget? |
|
It's pretty good! I've found 2 issues:
Also, a more general issue: we should use physical lines (ends where text wraps) not text lines (ends at But I think this can be addressed in another issue. |
|
@paulrouget thanks! @clementmiao if you address Paul's comments, this is good to go. |
Depends which shortcut you are talking about. |
|
@paulrouget So I did not know this, but actually Fn+Left is doing Home, and Fn+Right does End at the OS level on OSX/macos. In chrome though, it seems it is overriden and instead does "top of page" and "bottom of page" instead. Should I override the OS behavior to do Home/End for Fn+Left and Fn+Right respectively? |
It's surprising that Fn+Left/Right doesn't do anything in the textbox itself. So yep, I guess we should not do anything special for Fn+Arrows then. |
|
Not committed yet, but I have added Fn+Left/Right to do nothing inside the text box. Cmd+Up and Cmd+Down were relatively straightforward. Now regarding control+A and Control+E for macos, the distinction between text line end and text wrap end is not very clear. Being unfamiliar with how text boxes work, is there a way to determine if something is wrapped? |
|
@clementmiao I think it's going to be quite difficult to use physical lines rather than logical lines, since the linebreaking is (I believe) done by layout, and not very easily accessible in script. I'm okay with this going through as-is, and dealing with logical/physical lines separately. |
|
sorry for the delay (been busy at work, ironically with rust stuff). I added the last remaining shortcuts as discussed. Ideally it would be as we talked to physical lines vs logical lines, but that's done in the layout logic. |
|
The unit tests aren't compiling, can you run |
|
replaced test function calls with new names. This is why you run your tests. Thanks! |
|
The tests appear to still be failing:
|
|
@clementmiao Are you still working on this? |
|
@nox I am, not sure why I did not get an e-mail notification. Let me see what's going on. |
|
all the checks have passed now @nox |
|
LGTM, can you squash the commits? |
7c2ae65
to
f42d4d0
f42d4d0
to
ea3c840
|
@asajeffrey Squashed |
|
@bors-servo: r=asajeffrey |
|
|
added keyboard shortcuts for navigation inside text box PR to implement keyboard shortcuts per issue #12278, r? jdm Thanks for letting me help! --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12278 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15666) <!-- Reviewable:end -->
|
|
|
Yay, it landed, thanks @clementmiao! |
|
Yay, This was a lot of fun! Thank you @asajeffrey, @paulrouget and @nox for your help! Let me know if there's anything I can help on. |
clementmiao commentedFeb 21, 2017
•
edited by larsbergstrom
PR to implement keyboard shortcuts per issue #12278, r? jdm
Thanks for letting me help!
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is