Java Code Examples for com.intellij.openapi.editor.EditorModificationUtil#deleteSelectedText()
The following examples show how to use
com.intellij.openapi.editor.EditorModificationUtil#deleteSelectedText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhpClassInsertHandler.java From intellij-latte with MIT License | 6 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { // for removing first `\` (because class completion is triggered if prev element is `\` and PHP completion adding `\` before) super.handleInsert(context, lookupElement); PsiElement prev = context.getFile().findElementAt(context.getStartOffset() - 1); PsiElement element = context.getFile().findElementAt(context.getStartOffset()); String prevText = prev != null ? prev.getText() : null; String text = element != null ? element.getText() : null; if (prevText == null || text == null || (prevText.startsWith("\\") && !text.startsWith("\\"))) { return; } LattePhpClassUsage classUsage = element.getParent() instanceof LattePhpClassUsage ? (LattePhpClassUsage) element.getParent() : null; String[] className = (classUsage != null ? classUsage.getClassName() : "").split("\\\\"); if ((prevText.length() > 0 || className.length > 1) && element.getNode().getElementType() == LatteTypes.T_PHP_NAMESPACE_RESOLUTION) { Editor editor = context.getEditor(); CaretModel caretModel = editor.getCaretModel(); int offset = caretModel.getOffset(); caretModel.moveToOffset(element.getTextOffset()); editor.getSelectionModel().setSelection(element.getTextOffset(), element.getTextOffset() + 1); EditorModificationUtil.deleteSelectedText(editor); caretModel.moveToOffset(offset - 1); PsiDocumentManager.getInstance(context.getProject()).commitDocument(editor.getDocument()); } }
Example 2
Source File: CutAfterJumpCommand.java From emacsIDEAs with Apache License 2.0 | 6 votes |
@Override public void afterJump() { final Runnable runnable = new Runnable() { @Override public void run() { if (inSameEditor()) { selectJumpArea(); _se.getSelectionModel().copySelectionToClipboard(); EditorModificationUtil.deleteSelectedText(_se); _se.getSelectionModel().removeSelection(); } } }; AppUtil.runWriteAction(runnable, _se); }
Example 3
Source File: DeleteSelectionHandler.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { if (caret == null ? editor.getSelectionModel().hasSelection(true) : caret.hasSelection()) { EditorUIUtil.hideCursorInEditor(editor); CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP); CopyPasteManager.getInstance().stopKillRings(); CaretAction action = c -> EditorModificationUtil.deleteSelectedText(editor); if (caret == null) { editor.getCaretModel().runForEachCaret(action); } else { action.perform(caret); } } else { myOriginalHandler.execute(editor, caret, dataContext); } }
Example 4
Source File: JustOneSpace.java From emacsIDEAs with Apache License 2.0 | 5 votes |
private void makeOneSpaceBetween(final int begin, final int end) { Runnable runnable = new Runnable() { @Override public void run() { _editor.getSelectionModel().setSelection(begin, end); EditorModificationUtil.deleteSelectedText(_editor); EditorModificationUtil.insertStringAtCaret(_editor, " "); } }; AppUtil.runWriteAction(runnable, _editor); }
Example 5
Source File: CopyCutWithoutSelectAction.java From emacsIDEAs with Apache License 2.0 | 5 votes |
private void cutSelection() { Runnable cutRunnable = new Runnable() { @Override public void run() { _editor.getSelectionModel().copySelectionToClipboard(); EditorModificationUtil.deleteSelectedText(_editor); } }; AppUtil.runWriteAction(cutRunnable, _editor); }
Example 6
Source File: BackspaceHandler.java From consulo with Apache License 2.0 | 5 votes |
public static void deleteToTargetPosition(@Nonnull Editor editor, @Nonnull LogicalPosition pos) { final int offset = editor.getCaretModel().getOffset(); final int targetOffset = editor.logicalPositionToOffset(pos); editor.getSelectionModel().setSelection(targetOffset, offset); EditorModificationUtil.deleteSelectedText(editor); editor.getCaretModel().moveToLogicalPosition(pos); }
Example 7
Source File: EditorUtils.java From emacsIDEAs with Apache License 2.0 | 4 votes |
public static void deleteRange(Class<? extends Selector> selectorClass, Editor editor) { selectRangeOf(selectorClass, editor); EditorModificationUtil.deleteSelectedText(editor); }
Example 8
Source File: EditorUtils.java From emacsIDEAs with Apache License 2.0 | 4 votes |
public static void deleteRange(TextRange tr, Editor editor) { selectTextRange(editor, new TextRange[] {tr} ); EditorModificationUtil.deleteSelectedText(editor); }
Example 9
Source File: MoveRangeAfterJumpCommand.java From emacsIDEAs with Apache License 2.0 | 4 votes |
@Override public void afterJump() { final Runnable runnable = new Runnable() { @Override public void run() { TextRange sourceRange = EditorUtils.getRangeOf(_selectorClass, _te); if (inSameEditor()) { boolean noNeedToMove = sourceRange.contains(_soff); if (noNeedToMove) { _se.getCaretModel().moveToOffset(_soff); return; } } int textSourceStartOffset = sourceRange.getStartOffset(); EditorUtils.copyRange(_selectorClass, _te); if ( !inSameEditor() || textSourceStartOffset > _soff) { deleteTextSource(_te); pasteClipboardToOffset(); } else { pasteClipboardToOffset(); focusTargetCaret(); deleteTextSource(_te); focusSourceCaret(); int cur_offset = _se.getCaretModel().getOffset(); if (_config._needSelectTextAfterJump) { EditorUtils.selectTextRange(_se, cur_offset - _length, cur_offset); } } } private void deleteTextSource(Editor editor) { EditorUtils.selectRangeOf(_selectorClass, editor); EditorModificationUtil.deleteSelectedText(editor); } private void pasteClipboardToOffset() { focusSourceCaret(); TextRange[] tr = EditorCopyPasteHelperImpl.getInstance().pasteFromClipboard(_se); if (_config._needSelectTextAfterJump) { EditorUtils.selectTextRange(_se, tr); } _length = tr[0].getEndOffset() - tr[0].getStartOffset(); } }; AppUtil.runWriteAction(runnable, _se); }