in hybrid/src/main/java/jetbrains/jetpad/hybrid/TokenCellTraits.java [154:190]
public void onCellTraitEvent(Cell cell, CellTraitEventSpec<?> spec, Event event) {
if (spec == Cells.BECAME_EMPTY) {
int index = tokenCells(cell).indexOf(cell);
Token current = tokens(cell).get(index);
Token prev = index == 0 ? null : tokens(cell).get(index - 1);
Token next = index == tokens(cell).size() - 1 ? null : tokens(cell).get(index + 1);
if (
(prev != null && (prev.noSpaceToRight() || current.noSpaceToLeft()) ||
(next != null && (next.noSpaceToLeft()) || current.noSpaceToRight()) || prev == null && next == null)) {
tokenOperations(cell).deleteToken(cell, 0).run();
} else {
tokenOperations(cell).replaceToken(cell, new ErrorToken("")).run();
}
event.consume();
return;
}
if (spec == Cells.BECAME_INVALID && cell.getParent() != null) {
int index = tokenCells(cell).indexOf(cell);
Token current = tokens(cell).get(index);
if (current instanceof CommentToken) {
CommentToken commentToken = (CommentToken) current;
if (isUncomment(event, commentToken.getPrefix())) {
tokenOperations(cell).replaceCommentToken(cell, (TextCell) cell).run();
event.consume();
return;
}
}
}
super.onCellTraitEvent(cell, spec, event);
}