@Override public void execute(final jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = ((EditorComponent) context.getEditorComponent()); SelectionManager selectionManager = editorComponent.getSelectionManager(); Selection selection = selectionManager.getSelection(); if (selection instanceof SingularSelection) { EditorCell selectedCell = ((SingularSelection) selection).getEditorCell(); SNode selectedNode = selectedCell.getSNode(); SNode topMostNodeInSingularContainment = findTopMostNodeWithSingularContainment(selectedNode); if (topMostNodeInSingularContainment != selectedNode) { EditorCell nodeCell = editorComponent.findNodeCell(topMostNodeInSingularContainment); if (nodeCell != null) { editorComponent.pushSelection(nodeCell); editorComponent.scrollToCell(nodeCell); } } else { Selection newSelection = selectionManager.createRangeSelection(selectedNode, selectedNode); if (newSelection instanceof NodeRangeSelection && selectedCell.isBigCell()) { newSelection = ((NodeRangeSelection) newSelection).enlargeSelection(myUp); } if (newSelection != null) { selectionManager.pushSelection(newSelection); newSelection.ensureVisible(); } } } else if (selection instanceof NodeRangeSelection) { Selection newSelection = ((NodeRangeSelection) selection).enlargeSelection(myUp); if (newSelection != null) { selectionManager.pushSelection(newSelection); newSelection.ensureVisible(); } } }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = ((EditorComponent) context.getEditorComponent()); EditorCell target = findTarget(editorComponent); if (target instanceof EditorCell_Label) { EditorCell_Label label = (EditorCell_Label) target; label.end(); editorComponent.resetLastCaretX(); } editorComponent.changeSelection(target); }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorCell selectedCell = getDeepestSelectedCell(context); int caretX = selectedCell.getCaretX(); EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); if (editorComponent.hasLastCaretX()) { caretX = editorComponent.getLastCaretX(); } editorComponent.saveLastCaretX(caretX); EditorCell target = findTarget(selectedCell, caretX); target.setCaretX(caretX); editorComponent.changeSelection(target, false); }
public void execute_internal(EditorContext editorContext, SNode node) { SNode expression = SLinkOperations.getTarget(node, "processHandler", true); SNodeOperations.replaceWithAnother(node, expression); // some stuff I copied from binary operation // it does some magic with selection editorContext.flushEvents(); EditorComponent editor = editorContext.getEditorComponent(); EditorCell cell = (EditorCell) editor.findNodeCell(expression); if (cell != null) { EditorCell lastLeaf = cell.getLastLeaf(CellConditions.SELECTABLE); editor.changeSelection(lastLeaf); if (lastLeaf instanceof EditorCell_Label) { ((EditorCell_Label) lastLeaf).end(); } } }
private EditorCell findTarget(EditorComponent editorComponent) { Selection selection = editorComponent.getSelectionManager().getSelection(); if (selection == null) { return null; } List<EditorCell> selectedCells = selection.getSelectedCells(); EditorCell cell = selectedCells.get(selectedCells.size() - 1); return cell.getEndCell(CellConditions.SELECTABLE); }
public static boolean isCellOrSelectionReadOnlyInEditor( jetbrains.mps.openapi.editor.EditorComponent editorComponent, @Nullable jetbrains.mps.openapi.editor.cells.EditorCell cell) { if (editorComponent.isReadOnly()) { return true; } if (cell == null) { return isSelectionReadOnlyInEditor(editorComponent); } return isCellReadOnly(cell); }
public static boolean isCellsReadOnlyInEditor( jetbrains.mps.openapi.editor.EditorComponent editorComponent, Iterable<jetbrains.mps.openapi.editor.cells.EditorCell> cells) { if (editorComponent.isReadOnly()) { return true; } for (jetbrains.mps.openapi.editor.cells.EditorCell cell : cells) { if (isCellOrSelectionReadOnlyInEditor(editorComponent, cell)) { return true; } } return false; }
private void doUpdateWarnings(final MPSFileNodeEditor editor) { List<WarningPanel> newWarnings = new ArrayList<WarningPanel>(); Editor nodeEditor = editor.getNodeEditor(); if (nodeEditor == null) return; EditorComponent editorComponent = nodeEditor.getCurrentEditorComponent(); if (editorComponent != null && editorComponent.isDisposed()) return; SNode node = editor.getFile().getNode(); if (node == null) return; EditorWarningsProvider[] providers = Extensions.getExtensions(EditorWarningsProvider.EP_NAME); for (EditorWarningsProvider provider : providers) { WarningPanel panel = provider.getWarningPanel(node, myProject); if (panel != null) { newWarnings.add(panel); } } replaceWarningPanels(editor, newWarnings); }
@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(); } }
private static void navigatePage( jetbrains.mps.openapi.editor.EditorContext context, boolean isDown) { EditorComponent editor = (EditorComponent) context.getEditorComponent(); jetbrains.mps.openapi.editor.cells.EditorCell selection = editor.getSelectedCell(); Rectangle rect = editor.getVisibleRect(); int height = (int) rect.getHeight(); height = isDown ? height : -height; int caretX = selection.getCaretX(); int y = selection.getY() + (selection.getHeight() / 2); int newY = y + height; jetbrains.mps.openapi.editor.cells.EditorCell target = editor.findCellWeak(caretX, newY); if (target == null) { target = isDown ? editor.myRootCell.findChild(CellFinders.LAST_SELECTABLE_LEAF) : editor.myRootCell.findChild(CellFinders.FIRST_SELECTABLE_LEAF); editor.changeSelection(target); } else { target.setCaretX(caretX); editor.changeSelection(target); } }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); EditorCell selection = editorComponent.getSelectedCell(); editorComponent.changeSelection(selection.getPrevLeaf(CellConditions.EDITABLE)); }
public static boolean isSelectionReadOnlyInEditor( jetbrains.mps.openapi.editor.EditorComponent editorComponent) { Selection selection = editorComponent.getSelectionManager().getSelection(); return selection == null || isCellsReadOnlyInEditor(editorComponent, selection.getSelectedCells()); }