Filtering event in KeyMap


I am trying to implement an editor that can be used to enter arbitrary text, but needs to seperate the words. I tried to use a KeyMap to act when a SPACE is typed and then split the current word in two, as follows.
    item description      : Break word in two then space is typed
         keystrokes       : <none> + <VK_SPACE>
         caret policy     : ANY_POSITION
         show in popup    : false
         menu always show : false
         is applicable    : (node, selectedNodes, editorCOntext)->boolean {
selectedNodes.size == 1;
         execute          : (node, selectedNodes, editorCOntext)->void {
string word = node.word;
int i = node.getCaretIndex(editorContext);
string part1 = word.substring(0,i).trim(trailing);
string part2 = word.substring(i).trim(leading);
node<Word> w2 = initialized next-sibling(Word);
w2.word.set(part2);[in: editorContext, cell: word, selecitonStart:0];
This works ok, but afterwards the SPACE is added, and thus word #2 starts with a space, despite my attempt to remove the key-event using the last statment in the execute block. (BTW, the method getCaretIndex is a custom behavior method that I added to determine in which position the cursor is positioned when the space is entered. I hope there is a better way, because my current solution only works for fixed width fonts)

Also, I want to change the behavior of the BACKSPACE and DELETE keys when the cursor is at the beginning of end of a word, but my attempts to use keymap or action maps for that have failed so far. No matter what I do, the debugger wo'nt hit my breakpoints.

Any suggestions would be most welcome.
Do you know about project?
It looks like implementing similar functionality to what you are trying to achieve.

In addition you can check MPS jetbrains.mps.baseLanguage.javadoc language. I think it contains actions handing delete/backspace in similar situations.

I'm facing the same sort of problem: after I handle a key, I want to prevent it from being typed into the editor field.


Gert, do you remember if you managed to resolve this issue?


Hi guys, we are getting a similar problem here. Anybody learned more and is willing to share it here? Or maybe a bug has been filed about this?


Please sign in to leave a comment.