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

added keyboard shortcuts for navigation inside text box #15666

Merged
merged 1 commit into from Apr 12, 2017

Conversation

@clementmiao
Copy link
Contributor

clementmiao commented Feb 21, 2017

PR to implement keyboard shortcuts per issue #12278, r? jdm

Thanks for letting me help!

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #12278 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

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
Copy link

highfive commented Feb 21, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/Cargo.toml, components/script/textinput.rs
  • @KiChjang: components/script/Cargo.toml, components/script/textinput.rs
Copy link
Member

asajeffrey left a comment

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.

@asajeffrey

asajeffrey Feb 21, 2017

Member

Add this extern crate to lib.rs?

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.

@asajeffrey

asajeffrey Feb 21, 2017

Member

Can we make this use unicode... rather than use self::unicode...?

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.

@asajeffrey

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.

@clementmiao

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.

@asajeffrey

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.

@clementmiao

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.

@asajeffrey

asajeffrey Feb 22, 2017

Member

Silly me, forgot about the semantics of | on bitflags!

(Some('a'), _) if is_control_key(mods) => {
self.select_all();
KeyReaction::RedrawSelection
},
}

This comment has been minimized.

@asajeffrey

asajeffrey Feb 21, 2017

Member

Why are commas vanishing?

This comment has been minimized.

@clementmiao

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.

@asajeffrey

asajeffrey Feb 22, 2017

Member

I prefer with, but it's not exactly urgent.

(None, Key::Right) if mods.contains(ALT) => {
self.adjust_horizontal_by_word(Direction::Forward, maybe_select);
KeyReaction::RedrawSelection
}

This comment has been minimized.

@asajeffrey

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.

@clementmiao

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.

@asajeffrey

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.

@asajeffrey

asajeffrey Feb 21, 2017

Member

Yay tests!

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.

@asajeffrey

asajeffrey Feb 27, 2017

Member

Why the test for alphanumerics?

This comment has been minimized.

@clementmiao

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.

@asajeffrey

asajeffrey Feb 27, 2017

Member

OK, seems sensible.

@asajeffrey
Copy link
Member

asajeffrey commented Feb 27, 2017

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?

@paulrouget
Copy link
Contributor

paulrouget commented Feb 28, 2017

It's pretty good!

I've found 2 issues:

  • fn+option+right/left go at the end/beginning of the line. I don't think it's supposed to
  • ctrl+a and ctrl+e, cmd+up, cmd+down are missing

Also, a more general issue: we should use physical lines (ends where text wraps) not text lines (ends at \n) when moving the cursor around. For example, cmd+right should jump right before where the line wraps, not before the \n.

But I think this can be addressed in another issue.

@asajeffrey
Copy link
Member

asajeffrey commented Feb 28, 2017

@paulrouget thanks!

@clementmiao if you address Paul's comments, this is good to go.

@nox
Copy link
Member

nox commented Mar 3, 2017

Also, a more general issue: we should use physical lines (ends where text wraps) not text lines (ends at \n) when moving the cursor around. For example, cmd+right should jump right before where the line wraps, not before the \n.

Depends which shortcut you are talking about. C^e should go at the end of the text line.

@clementmiao
Copy link
Contributor Author

clementmiao commented Mar 5, 2017

@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?

@paulrouget
Copy link
Contributor

paulrouget commented Mar 6, 2017

@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.

@clementmiao
Copy link
Contributor Author

clementmiao commented Mar 14, 2017

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. TextPoint.line is based on text line end (\n) and not on wrap-based lines, so it's not clear to me how I determine if something is on the next physical line with wrap (vs logical line with \n). line 0 can wrap unto the next physical line but is still line 0.

Being unfamiliar with how text boxes work, is there a way to determine if something is wrapped?

@asajeffrey
Copy link
Member

asajeffrey commented Mar 16, 2017

@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.

@clementmiao
Copy link
Contributor Author

clementmiao commented Mar 23, 2017

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.

@asajeffrey
Copy link
Member

asajeffrey commented Mar 23, 2017

The unit tests aren't compiling, can you run ./mach test-unit -p script? Thanks!

@clementmiao
Copy link
Contributor Author

clementmiao commented Mar 24, 2017

replaced test function calls with new names. This is why you run your tests. Thanks!

@asajeffrey
Copy link
Member

asajeffrey commented Mar 27, 2017

The tests appear to still be failing:

error[E0412]: cannot find type `DummyClipboardContext` in this scope
  --> C:\projects\servo\tests\unit\script\textinput.rs:17:51
   |
17 | fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> {
   |                                                   ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = help: possible candidate is found in another module, you can import it into scope:
             `use script::clipboard_provider::DummyClipboardContext;`
@nox
Copy link
Member

nox commented Apr 4, 2017

@clementmiao Are you still working on this?

@clementmiao
Copy link
Contributor Author

clementmiao commented Apr 5, 2017

@nox I am, not sure why I did not get an e-mail notification. Let me see what's going on.

@clementmiao
Copy link
Contributor Author

clementmiao commented Apr 6, 2017

all the checks have passed now @nox

@asajeffrey
Copy link
Member

asajeffrey commented Apr 6, 2017

LGTM, can you squash the commits?

@clementmiao clementmiao force-pushed the clementmiao:keyboard_shortcuts branch from 7c2ae65 to f42d4d0 Apr 7, 2017
@clementmiao clementmiao force-pushed the clementmiao:keyboard_shortcuts branch from f42d4d0 to ea3c840 Apr 7, 2017
@clementmiao
Copy link
Contributor Author

clementmiao commented Apr 7, 2017

@asajeffrey Squashed

@jdm jdm removed the S-needs-squash label Apr 7, 2017
@jdm
Copy link
Member

jdm commented Apr 12, 2017

@bors-servo: r=asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Apr 12, 2017

📌 Commit ea3c840 has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Apr 12, 2017

Testing commit ea3c840 with merge 45f20f0...

bors-servo added a commit that referenced this pull request Apr 12, 2017
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 12, 2017

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-msvc-dev
Approved by: asajeffrey
Pushing 45f20f0 to master...

@bors-servo bors-servo merged commit ea3c840 into servo:master Apr 12, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@asajeffrey
Copy link
Member

asajeffrey commented Apr 17, 2017

Yay, it landed, thanks @clementmiao!

@clementmiao
Copy link
Contributor Author

clementmiao commented Apr 17, 2017

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.

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

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.