in cell/src/main/java/jetbrains/jetpad/cell/text/ValidTextEditingTrait.java [123:166]
private boolean onAfterTextAdded(TextCell editor, CompletionParameters cp, boolean sideTransformationsAllowed) {
Boolean eagerCompletion = editor.get(TextEditing.EAGER_COMPLETION);
if (!eagerCompletion && isValid(editor)) return false;
String text = editor.text().get();
if (text == null || text.isEmpty()) return false;
//simple validation
CompletionItems completion = Completion.completionFor(editor, cp);
if (completion.hasSingleMatch(text, eagerCompletion)) {
completion.completeFirstMatch(text);
return true;
}
boolean completed = false;
if (sideTransformationsAllowed) {
if (editor.isEnd() && !completion.hasMatches(text)) {
//right transform
String prefix = text.substring(0, text.length() - 1);
String suffix = text.substring(text.length() - 1);
if (getValidator(editor).apply(prefix)) {
completed = handleSideTransform(editor, prefix, suffix.trim(), Side.RIGHT, eagerCompletion);
} else {
List<CompletionItem> matches = completion.matches(prefix);
if (matches.size() == 1) {
CellContainer container = editor.getContainer();
matches.get(0).complete(prefix).run();
assertValid(container.focusedCell.get());
container.keyTyped(new KeyEvent(Key.UNKNOWN, suffix.charAt(0), Collections.<ModifierKey>emptySet(), false));
// Here we don't set 'true' to 'completed' variable, because the structural completion will be performed
// on the new key event.
}
}
} else if (editor.caretPosition().get() == 1 && !CellCompletionController.isCompletionActive(editor)) {
//left transform
String prefix = text.substring(0, 1).trim();
String suffix = text.substring(1);
if (getValidator(editor).apply(suffix)) {
completed = handleSideTransform(editor, suffix, prefix, Side.LEFT, eagerCompletion);
}
}
}
return completed;
}