@Override public void selectionChanged( jetbrains.mps.openapi.editor.EditorComponent editorComponent, Selection oldSelection, Selection newSelection) { if (oldSelection == newSelection) { return; } if (myClosingBrace.isSelected() || myOpeningBrace.isSelected()) { enableBraces(); return; } EditorCell deepestSelection = editorComponent.getDeepestSelectedCell(); EditorCell lastSelectableLeaf = CellFinderUtil.findChildByCondition( EditorCell_Collection.this, LAST_SELECTABLE_LEAF_EXCLUDING_BRACE, false); EditorCell firstSelectableLeaf = CellFinderUtil.findChildByCondition( EditorCell_Collection.this, FIRST_SELECTABLE_LEAF_EXCLUDING_BRACE, true); if (deepestSelection instanceof EditorCell_Brace) { EditorCell_Collection braceOwner = (EditorCell_Collection) deepestSelection.getParent(); if (braceOwner.myClosingBrace == deepestSelection && CellFinderUtil.findChildByCondition( braceOwner, LAST_SELECTABLE_LEAF_EXCLUDING_BRACE, false) == lastSelectableLeaf) { enableBraces(); return; } if (braceOwner.myOpeningBrace == deepestSelection && CellFinderUtil.findChildByCondition( braceOwner, FIRST_SELECTABLE_LEAF_EXCLUDING_BRACE, true) == firstSelectableLeaf) { enableBraces(); return; } } if (lastSelectableLeaf == deepestSelection || firstSelectableLeaf == deepestSelection) { enableBraces(); } else { disableBraces(); } }