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

Key simulation #1850

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Key simulation #1850

wants to merge 13 commits into from

Conversation

rksm
Copy link
Contributor

@rksm rksm commented Mar 12, 2014

This implements a simple form of triggering commands and insertions by simulating keys. Like:

var keys = require('ace/lib/keys');
// one key combo at a time
keys.simulateKey(editor, 'Shift-Right');
keys.simulateKey(editor, 'Command-Shift-d');
keys.simulateKey(editor, 'Control-a');
// or multiple
keys.simulateKeys(editor, 'H e l o Left l Command-Shift-Left');
/*...*/

todo:

  • support series of keys (like keys.simulateKeys(editor, 'Right Right Command-Down'))
  • base keys.send / old vim sendKeys code upon simulateKeys

@rksm
Copy link
Contributor Author

rksm commented Mar 26, 2014

Is there something wrong with this PR? Except for the main functionality of key simulation it is attempt to make the key handling a bit more uniform.

// we don't call the callback as we don't handle a command key here
// (it's a normal key/character input).
// 2014-03-11 rksm: command key == mac cmd? If just cmd is pressed hashId
// will be -1 and callback will be called... please clarify.
Copy link
Member

Choose a reason for hiding this comment

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

I think hashId can't be -1, it's equal to 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);

@nightwing
Copy link
Member

Sorry for the delay with reviewing this. The changes generally look good, but i don't like that this adds code needed only for testing into the main module.

@nightwing
Copy link
Member

@rksm Did you need simulateKeys in editor itself or only in tests? I want to move it and it's helpers into separate module.

@rksm
Copy link
Contributor Author

rksm commented May 20, 2014

I need it as a feature outside of tests but whether it resides in a separate module or not doesn't matter.

@knod
Copy link

knod commented May 5, 2016

Has the ability to simulate key presses been added in some fashion? Not just content keys, but modifier keys as well and the tab key functionality.

To take tab as an example - just inserting a tab works for most occasions, and indenting might be handled as described here: http://stackoverflow.com/questions/24607730/ace-editor-javascript-triggering-a-tab-press-event-for-ace-editors-event-hand/24608974#24608974. Unfortunately, more uses of tab keep popping up. With snippetManager, pressing tab navigates to the next specified text in a snippet and I want that functionality as well.

I don't want to have to recreate all the functionality for each plugin I use. I'd like to just simulate an actual key being pressed or held. Is this possible?

@rksm
Copy link
Contributor Author

rksm commented May 6, 2016

@knod Since this feature seems to be unwanted I ended up publishing it in an extension. ace.ext.keys.simulateKeys() works with modifiers and key sequences. I understand @nightwing concerns to not add "test code" but for the use in Lively we use this feature in production as well (to integrate ace and non-ace keyboard handlers).

@rksm
Copy link
Contributor Author

rksm commented May 20, 2016

@knod ace.improved has some doc now, https://github.com/rksm/ace.improved#aceextkeys

@knod
Copy link

knod commented Jul 29, 2016

@rksm Thanks, I'll look into that. I have a lot else to work on, but this will become a major issue soon, so I'm glad to see there's a way to handle it out there.

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

Successfully merging this pull request may close these issues.

4 participants