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

Allows mac shortcuts to be used when inside a input element #12549

Closed
wants to merge 1 commit into from

Conversation

@jimberlage
Copy link
Contributor

jimberlage commented Jul 22, 2016

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 -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 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.
@jimberlage jimberlage force-pushed the jimberlage:12278/keybindings branch from 46e5777 to f35888b Jul 22, 2016
@paulrouget
Copy link
Contributor

paulrouget commented Jul 22, 2016

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

@KiChjang
Copy link
Member

KiChjang commented Jul 24, 2016

@highfive highfive assigned paulrouget and unassigned KiChjang Jul 24, 2016
@KiChjang
Copy link
Member

KiChjang commented Jul 24, 2016

@bors-servo delegate=paulrouget

@bors-servo
Copy link
Contributor

bors-servo commented Jul 24, 2016

✌️ @paulrouget can now approve this pull request

@paulrouget
Copy link
Contributor

paulrouget commented Jul 26, 2016

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.

@jdm jdm assigned KiChjang and unassigned paulrouget Aug 3, 2016
// 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.

@pcwalton

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.

@pcwalton

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.

@pcwalton

pcwalton Aug 8, 2016

Contributor

Some of these parentheses are unnecessary.

(None, Key::Right) => {
self.adjust_horizontal_by_one(Direction::Forward, maybe_select);
KeyReaction::RedrawSelection
}
},

This comment has been minimized.

@pcwalton

pcwalton Aug 8, 2016

Contributor

nit: Remove this comma (and likewise for the above pattern arms)

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.

@pcwalton

pcwalton Aug 8, 2016

Contributor

nit: for line in &self.lines[self.edit_point.line..] {

None => line.chars(),
};

'chars: for ch in char_iter {

This comment has been minimized.

@pcwalton

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.

@pcwalton

pcwalton Aug 8, 2016

Contributor

adjust += 1;

@KiChjang
Copy link
Member

KiChjang commented Aug 8, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 9, 2016

The latest upstream changes (presumably #13205) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Jan 27, 2017

Closing due to lack of activity.

@jdm jdm closed this Jan 27, 2017
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.