Filtering event in KeyMap

Hi,

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.set(part1);
node<Word> w2 = node.new initialized next-sibling(Word);
w2.word.set(part2);
f2.select[in: editorContext, cell: word, selecitonStart:0];
editorContext.flushEvents();
            }
prettyPrint();
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.
3 comments
Do you know about https://github.com/slisson/mps-richtext 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.
1

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?

1

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?

1

Please sign in to leave a comment.