Java Code Examples for com.intellij.codeInsight.template.impl.TemplateState#getCurrentVariableRange()
The following examples show how to use
com.intellij.codeInsight.template.impl.TemplateState#getCurrentVariableRange() .
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: TemplateLineStartEndHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { final TextRange range = templateState.getCurrentVariableRange(); final int caretOffset = editor.getCaretModel().getOffset(); if (range != null && shouldStayInsideVariable(range, caretOffset)) { int selectionOffset = editor.getSelectionModel().getLeadSelectionOffset(); int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset(); LogicalPosition logicalPosition = editor.offsetToLogicalPosition(offsetToMove).leanForward(myIsHomeHandler); editor.getCaretModel().moveToLogicalPosition(logicalPosition); EditorModificationUtil.scrollToCaret(editor); if (myWithSelection) { editor.getSelectionModel().setSelection(selectionOffset, offsetToMove); } else { editor.getSelectionModel().removeSelection(); } return; } } myOriginalHandler.execute(editor, caret, dataContext); }
Example 2
Source File: BaseCompleteMacro.java From consulo with Apache License 2.0 | 5 votes |
private static void considerNextTab(Editor editor) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null) { TextRange range = templateState.getCurrentVariableRange(); if (range != null && range.getLength() > 0) { int caret = editor.getCaretModel().getOffset(); if (caret == range.getEndOffset()) { templateState.nextTab(); } else if (caret > range.getEndOffset()) { templateState.cancelTemplate(); } } } }
Example 3
Source File: SelectAllHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void execute(Editor editor, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { final TextRange range = templateState.getCurrentVariableRange(); final int caretOffset = editor.getCaretModel().getOffset(); if (range != null && range.getStartOffset() <= caretOffset && caretOffset <= range.getEndOffset()) { editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); return; } } myOriginalHandler.execute(editor, dataContext); }
Example 4
Source File: TemplateLineStartEndHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean isEnabledForCaret(@Nonnull Editor editor, @Nonnull Caret caret, DataContext dataContext) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { TextRange range = templateState.getCurrentVariableRange(); int caretOffset = editor.getCaretModel().getOffset(); if (range != null && range.containsOffset(caretOffset)) return true; } return myOriginalHandler.isEnabled(editor, caret, dataContext); }
Example 5
Source File: AbstractInplaceIntroducer.java From consulo with Apache License 2.0 | 5 votes |
public void restartInplaceIntroduceTemplate() { Runnable restartTemplateRunnable = new Runnable() { @Override public void run() { final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); if (templateState != null) { myEditor.putUserData(INTRODUCE_RESTART, true); try { final TextRange range = templateState.getCurrentVariableRange(); if (range != null && range.isEmpty()) { final String[] names = suggestNames(isReplaceAllOccurrences(), getLocalVariable()); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { myEditor.getDocument().insertString(myEditor.getCaretModel().getOffset(), names[0]); } }); } templateState.gotoEnd(true); try { myShouldSelect = false; startInplaceIntroduceTemplate(); } finally { myShouldSelect = true; } } finally { myEditor.putUserData(INTRODUCE_RESTART, false); } } updateTitle(getVariable()); } }; CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, getCommandName(), getCommandName()); }