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

Add more of OS X's native Emacs keybindings #4743

Closed

Conversation

nopdotcom
Copy link
Contributor

OS X supports many simple Emacs keybindings in native text fields. (It can do this because the system UI uses Cmd instead of Ctrl as its main modifier key.) Add bindings to functions which already exist in
DefaultEditorKit.

I have a Ctrl-k (cut to end of line) implementation, but it is an additional static RecordableTextAction class. I have not included it.

OS X supports many simple Emacs keybindings in native text fields. (It
can do this because the system UI uses Cmd instead of Ctrl as its main
modifier key.) Add bindings to functions which already exist in
DefaultEditorKit.

I have a Ctrl-k (cut to end of line) implementation, but it is an
additional static RecordableTextAction class. I have not included it.
@cmaglie
Copy link
Member

cmaglie commented Mar 24, 2016

Interesting, never know that, are those key-bindings standard in OSX?

@cmaglie
Copy link
Member

cmaglie commented Mar 24, 2016

@ArduinoBot build this please

@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) Component: IDE user interface The Arduino IDE's user interface labels Mar 24, 2016
put(KeyStroke.getKeyStroke(KeyEvent.VK_F, ctrl), DefaultEditorKit.forwardAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_D, ctrl), DefaultEditorKit.deleteNextCharAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_Y, ctrl), DefaultEditorKit.pasteAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_W, ctrl), DefaultEditorKit.cutAction);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'cut' actions that here is set as Ctrl-W seems to be Ctrl-K instead.
From various sources I see that the mnemonics are:

Ctrl-K -> Kill (cut)
Ctrl-Y -> Yank (paste)

is that right?
All the other shortcuts works as expected.

@cmaglie
Copy link
Member

cmaglie commented Mar 25, 2016

ok after commenting here https://github.com/arduino/Arduino/pull/4743/files#r57473913 I re-read the OP comment:

I have a Ctrl-k (cut to end of line) implementation, but it is an additional static RecordableTextAction class. I have not included it.

and now I've all the pieces together: it seems that Ctrl-K works as "cut to the end of the line" if no text is selected, otherwise it works as a normal "cut".

@nopdotcom do you agree?

@nopdotcom
Copy link
Contributor Author

tl;dr; Your described behavior is a good improvement; for example, Ctrl-K then Ctrl-Y should put the line back the way it was. The real Ctrl-K is complicated,

Long version: I hadn’t realized how complicated it actually is.

The native OS X behavior for Ctrl-K mimics Emacs very well, but it is confusing. There is a separate cut buffer used by OS X Ctrl-K and Ctrl-Y, unrelated to the clipboard.

Every action taken with Ctrl-K appends to the special buffer:

  • If the cursor has moved since the last Ctrl-K, start with an empty special buffer.
  • If there is a selection, append the selection into the special buffer, and delete the selection.
  • If not at end of line, append the remainder of the line to the special buffer, and delete.
  • If at end of line, add a newline to the special buffer, and delete the newline.

Ctrl-Y pastes the special buffer.

The end effect of this is that:

  • Pressing Ctrl-K any number of times followed by Ctrl-Y is a no-op.
  • From the start of line, Ctrl-K Ctrl-K cuts the whole line in a buffer, which you can then paste multiple times. In particular, Ctrl-A (beginning of line) Ctrl-K (cut line) Ctrl-K (cut newline) Ctrl-Y Ctrl-Y duplicates the current line.

These are wired into my fingers. But I would find it acceptable for Ctrl-A Ctrl-K Ctrl-Y RETURN C-y to duplicate the current line. Which would work with the mapping you described.

@nopdotcom
Copy link
Contributor Author

Would you like me to clean up my Ctrl-K code and add it to this branch?

@cmaglie
Copy link
Member

cmaglie commented Mar 29, 2016

@nopdotcom
Yes, thank you!
If you can keep the implementation of CTRL-K / CTRL-Y on a separate commit I can start to cherry-pick the other shortcuts.

cmaglie added a commit that referenced this pull request Apr 6, 2016
for a better explanation see @nopdotcom comment here:
#4743 (comment)
@cmaglie cmaglie added this to the Release 1.6.9 milestone Apr 6, 2016
@cmaglie
Copy link
Member

cmaglie commented Apr 6, 2016

@nopdotcom I've merged your commit without the Ctrl+W and Ctrl+Y part, so we can move forward and close this PR.

02914d7
f74afc4

Feel free to open another PR when you have a correct implementation of the Kill/Yank feature!

Thank you!

@cmaglie cmaglie closed this Apr 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE user interface The Arduino IDE's user interface feature request A request to make an enhancement (not a bug fix)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants