Left Transform - Why they behave like they behave?
Hello to everybody! Can you please explain the subject to me? Why left transforms do not give us behavior of a usual text editor? Why it should look like this:
<caret>1 -> press '+', then '2' -> 2 + 1
?
I'm sure the usual behavior of a text editor was considered and decided to be not implementable. So, why isn't it implementable?
<caret>1 -> press '+', then '2' -> 2 + 1
?
I'm sure the usual behavior of a text editor was considered and decided to be not implementable. So, why isn't it implementable?
Please sign in to leave a comment.
In principal, nothing should stop you from transforming into 1 + 2.
<caret>1 -> press '2' -> 2<caret>1 -> press '+' -> 2 + 1
Then you may like a sketch of a demo KeyMap I created for a simplified expression language, which does exactly that:
keymap IntegerConstant
everyModel true
applicable concept: SimpleMathIntegerConstant
keymap items:
item description : <no description>
keystrokes : <any> + <+>
caret policy : INTERMEDIATE_POSITION
show in popup : false
menu always shown : false
is applicable : <always>
execute : (node, selectedNodes, editorContext)->void {
int index = ((EditorCell_Label) editorContext.getSelectedCell()).getSelectionStart();
String operator = "+";
string value = "" + node.value;
String leftValue = value.substring(0, index);
String rightValue = value.substring(index);
node<ArithmeticSimpleMathExpression> arithmeticNode = new initialized node<ArithmeticSimpleMathExpression>();
node<SimpleMathIntegerConstant> leftNode = new initialized node<SimpleMathIntegerConstant>();
leftNode.value = Integer.parseInt(leftValue);
node<SimpleMathIntegerConstant> rightNode = new initialized node<SimpleMathIntegerConstant>();
rightNode.value = Integer.parseInt(rightValue);
arithmeticNode.left = leftNode;
arithmeticNode.operator = operator;
arithmeticNode.right = rightNode;
node.replace with(arithmeticNode);
}
;
I'm undecided regarding the discussed ability to seamlessly expand expressions to the left. The keymap-based trick is quite limited and would not allow future language extensions to hook in their additional operators and so they would not benefit from the key-map. While this may be a limitation to BaseLanguage, it may be acceptable for more focused single-purpose expression DSLs, though.