当前位置: 首页>>代码示例>>Java>>正文


Java Caret类代码示例

本文整理汇总了Java中com.intellij.openapi.editor.Caret的典型用法代码示例。如果您正苦于以下问题:Java Caret类的具体用法?Java Caret怎么用?Java Caret使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Caret类属于com.intellij.openapi.editor包,在下文中一共展示了Caret类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doExecute

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
    super.doExecute(editor, caret, dataContext);
    VirtualFile vf = (CommonDataKeys.VIRTUAL_FILE.getData(dataContext));

    if (IMWindowFactory.getDefault() == null) {
        return;
    }
    String path = VFSUtils.getPath(vf);
    if (!TextUtils.isEmpty(path)) {
        String text = editor.getSelectionModel().getSelectedText();
        int line = EditorUtils.getEditorLine(editor);
        ReviewDialog dialog = new ReviewDialog();
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setData(path, line, text);
        dialog.setVisible(true);
        dialog.dispose();
    }
}
 
开发者ID:Jamling,项目名称:SmartQQ4IntelliJ,代码行数:21,代码来源:ReviewHandler.java

示例2: executeInLookup

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) {
  if (!lookup.isCompletion()) {
    myOriginalHandler.execute(lookup.getEditor(), caret, context);
    return;
  }

  if (!lookup.performGuardedChange(new Runnable() {
    @Override
    public void run() {
      lookup.getEditor().getSelectionModel().removeSelection();
    }
  })) {
    return;
  }

  BackspaceHandler.truncatePrefix(context, lookup, myOriginalHandler, lookup.getLookupStart() - 1, caret);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LookupActionHandler.java

示例3: updateLastPastedClipboardCarets

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
private void updateLastPastedClipboardCarets(final Transferable transferable, final LinePasteCaretAdjustmentType adjustment, boolean setIfNone) {
    // if we already saved state, it means we might have adjusted caret position for line selections of the clipboard content at the time
    // we need to restore caret column positions to undo adjustments made for clipboard content that no longer applies
    final ClipboardCaretContent lastClipboardData = ClipboardCaretContent.getLastPastedClipboardCarets(myEditor);
    if (lastClipboardData != null) {
        int i = 0;
        for (Caret caret : myEditor.getCaretModel().getAllCarets()) {
            EditorPosition position = myManager.getPositionFactory().fromPosition(caret.getLogicalPosition());
            final EditorPosition atColumn = position.atColumn(lastClipboardData.getCaretColumn(i++));
            if (atColumn != position) {
                caret.moveToLogicalPosition(atColumn);
            }
        }
    }

    if (lastClipboardData != null || setIfNone) {
        final ClipboardCaretContent clipboardData = transferable != null ? ClipboardCaretContent.saveLastPastedCaretsForTransferable(myEditor, transferable, adjustment == LinePasteCaretAdjustmentType.NONE ? null : (caret, isFullLine) -> {
            if (!caret.hasSelection() && isFullLine) {
                caret.moveToOffset(adjustment.getPastePosition(myManager.getPositionFactory().fromPosition(caret.getLogicalPosition())).getOffset());
            }
            return caret.getOffset();
        }) : null;

        ClipboardCaretContent.setLastPastedClipboardCarets(myEditor, clipboardData);
    }
}
 
开发者ID:vsch,项目名称:MissingInActions,代码行数:27,代码来源:ActionSelectionAdjuster.java

示例4: actionPerformed

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (editor != null) {
        Document document = editor.getDocument();
        CharSequence chars = document.getCharsSequence();
        Plugin plugin = Plugin.getInstance();

        for (Caret caret : editor.getCaretModel().getAllCarets()) {
            if (caret.hasSelection()) {
                boolean startWord = EditHelpers.isWordStart(chars, caret.getSelectionStart(),false);
                boolean endWord = EditHelpers.isWordEnd(chars, caret.getSelectionEnd(),false);
                if (myIsRemoveWord) {
                    plugin.removeHighlightWord(chars.subSequence(caret.getSelectionStart(), caret.getSelectionEnd()));
                } else {
                    plugin.addHighlightWord(chars.subSequence(caret.getSelectionStart(), caret.getSelectionEnd()), startWord, endWord, null);
                }
            }
        }
    }
}
 
开发者ID:vsch,项目名称:MissingInActions,代码行数:22,代码来源:WordHighlightActionBase.java

示例5: updateCarets

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
protected void updateCarets(final Editor editor, final List<Caret> caretList) {
    LineSelectionManager manager = LineSelectionManager.getInstance(editor);
    if (mySingleMatch) {
        List<Caret> startMatchedCarets = new ArrayList<>();
        for (Caret caret : caretList) {
            for (Caret startCaret : myStartSearchCarets) {
                if (startCaret.getLogicalPosition().line == caret.getLogicalPosition().line) {
                    startMatchedCarets.add(startCaret);
                    break;
                }
            }
        }

        manager.setSearchFoundCaretSpawningHandler(this, myStartCarets, myStartSearchCarets, startMatchedCarets, caretList);
    } else {
        // just regular carets
        manager.clearSearchFoundCarets();
    }
}
 
开发者ID:vsch,项目名称:MissingInActions,代码行数:21,代码来源:CaretSpawningSearchHandler.java

示例6: perform

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
private void perform(Editor editor, LineSelectionManager manager, Caret caret) {
    assert caret != null;

    if (caret.hasSelection()) {
        EditorCaret editorCaret = manager.getEditorCaret(caret);
        if (editorCaret.getSelectionLineCount() > 1) {
            int column = editorCaret.getCaretPosition().column;
            editorCaret.setIsStartAnchorUpdateAnchorColumn(!editorCaret.isStartAnchor());
            if (column != 0 && editorCaret.getCaretPosition().column == 0) {
                editorCaret.restoreColumn(column);
            }
            editorCaret.commit();
        } else {
            // swap start/end
            int startOffset = caret.getSelectionStart();
            int endOffset = caret.getSelectionEnd();
            if (caret.getLeadSelectionOffset() == caret.getSelectionStart()) {
                caret.moveToOffset(startOffset);
            } else {
                caret.moveToOffset(endOffset);
            }
            caret.setSelection(endOffset, startOffset);
        }
    }
}
 
开发者ID:vsch,项目名称:MissingInActions,代码行数:26,代码来源:ToggleCaretSelectionAnchorActionHandler.java

示例7: perform

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
private void perform(Editor editor, LineSelectionManager manager, Caret caret) {
    assert caret != null;

    EditorCaret editorCaret = manager.getEditorCaret(caret);
    
    if (editorCaret.hasSelection()) {
        if (editorCaret.isLine()) {
            if (wantCharacter()) {
                editorCaret.toCharSelection()
                        .normalizeCaretPosition()
                        .commit();
            }
        } else if (wantLine()) {
            editorCaret.toLineSelection()
                    .normalizeCaretPosition()
                    .commit();
        }
    }
}
 
开发者ID:vsch,项目名称:MissingInActions,代码行数:20,代码来源:ToLineOrCharacterSelectionTypeActionHandler.java

示例8: doExecute

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
protected void doExecute(final Editor editor, @Nullable final Caret caret, final DataContext dataContext) {
    LineSelectionManager manager = LineSelectionManager.getInstance(editor);
    RangeMarker previousSelection = manager.getDummyRangeMarker();
    manager.recallLastSelection(0, true, false, true);
    RangeMarker rangeMarker = manager.getDummyRangeMarker();
    boolean handled = false;

    if (rangeMarker != null && previousSelection != null) {
        final Range range1 = new Range(rangeMarker.getStartOffset(), rangeMarker.getEndOffset());
        final Range range2 = new Range(previousSelection.getStartOffset(), previousSelection.getEndOffset());

        handled = EditHelpers.swapRangeText(editor, range1, range2);
    }

    if (!handled && previousSelection != null) {
        manager.pushSelection(true, false, false);
        editor.getSelectionModel().setSelection(previousSelection.getStartOffset(), previousSelection.getEndOffset());
        manager.recallLastSelection(0, true, true, true);
    }
}
 
开发者ID:vsch,项目名称:MissingInActions,代码行数:22,代码来源:SwapLastSelectionTextAction.java

示例9: getAllCaretsPositions

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@NotNull
public static Collection<XSourcePosition> getAllCaretsPositions(@NotNull Project project, DataContext context) {
  Editor editor = getEditor(project, context);
  if (editor == null) {
    return Collections.emptyList();
  }

  VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
  List<XSourcePosition> res = new SmartList<XSourcePosition>();
  for (Caret caret : editor.getCaretModel().getAllCarets()) {
    XSourcePositionImpl position = XSourcePositionImpl.createByOffset(file, caret.getOffset());
    if (position != null) {
      res.add(position);
    }
  }
  return res;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:XDebuggerUtilImpl.java

示例10: isSomeChangeSelected

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
private boolean isSomeChangeSelected(@NotNull ThreeSide side) {
  EditorEx editor = getEditor(side);
  List<Caret> carets = editor.getCaretModel().getAllCarets();
  if (carets.size() != 1) return true;
  Caret caret = carets.get(0);
  if (caret.hasSelection()) return true;

  int line = editor.getDocument().getLineNumber(editor.getExpectedCaretOffset());

  List<TextMergeChange> changes = getAllChanges();
  for (TextMergeChange change : changes) {
    if (!isEnabled(change)) continue;
    int line1 = change.getStartLine(side);
    int line2 = change.getEndLine(side);

    if (DiffUtil.isSelectedByLine(line, line1, line2)) return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:TextMergeTool.java

示例11: getInjectedEditorForInjectedFile

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@NotNull
public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @NotNull Caret hostCaret, @Nullable final PsiFile injectedFile) {
  if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor;
  Project project = hostEditor.getProject();
  if (project == null) project = injectedFile.getProject();
  Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile);
  if (!(document instanceof DocumentWindowImpl)) return hostEditor;
  DocumentWindowImpl documentWindow = (DocumentWindowImpl)document;
  if (hostCaret.hasSelection()) {
    int selstart = hostCaret.getSelectionStart();
    if (selstart != -1) {
      int selend = Math.max(selstart, hostCaret.getSelectionEnd());
      if (!documentWindow.containsRange(selstart, selend)) {
        // selection spreads out the injected editor range
        return hostEditor;
      }
    }
  }
  if (!documentWindow.isValid()) {
    return hostEditor; // since the moment we got hold of injectedFile and this moment call, document may have been dirtied
  }
  return EditorWindowImpl.create(documentWindow, (EditorImpl)hostEditor, injectedFile);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:InjectedLanguageUtil.java

示例12: doExecute

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
  assert caret != null;
  VisualPosition currentPosition = caret.getVisualPosition();
  if (caret.isAtBidiRunBoundary() && (myNext ^ currentPosition.leansRight)) {
    int selectionStartOffset = caret.getLeadSelectionOffset();
    VisualPosition selectionStartPosition = caret.getLeadSelectionPosition();
    caret.moveToVisualPosition(currentPosition.leanRight(!currentPosition.leansRight));
    if (myWithSelection) {
      caret.setSelection(selectionStartPosition, selectionStartOffset, caret.getVisualPosition(), caret.getOffset());
    }
  }
  else {
    if (myNext ^ caret.isAtRtlLocation()) {
      EditorActionUtil.moveCaretToNextWord(editor, myWithSelection, myInDifferentHumpsMode ^ editor.getSettings().isCamelWords());
    }
    else {
      EditorActionUtil.moveCaretToPreviousWord(editor, myWithSelection, myInDifferentHumpsMode ^ editor.getSettings().isCamelWords());
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:NextPrevWordHandler.java

示例13: iterateOverCarets

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
private static void iterateOverCarets(@NotNull final Project project,
                               @NotNull final Editor hostEditor,
                               @NotNull final MultiCaretCodeInsightActionHandler handler) {
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final PsiFile psiFile = documentManager.getCachedPsiFile(hostEditor.getDocument());
  documentManager.commitAllDocuments();

  hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
    @Override
    public void perform(Caret caret) {
      Editor editor = hostEditor;
      if (psiFile != null) {
        Caret injectedCaret = InjectedLanguageUtil.getCaretForInjectedLanguageNoCommit(caret, psiFile);
        if (injectedCaret != null) {
          caret = injectedCaret;
          editor = caret.getEditor();
        }
      }
      final PsiFile file = PsiUtilBase.getPsiFileInEditor(caret, project);
      if (file != null) {
        handler.invoke(project, editor, caret, file);
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MultiCaretCodeInsightAction.java

示例14: executeWriteAction

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  if (editor.getSelectionModel().hasSelection()) {
    int selStart = editor.getSelectionModel().getSelectionStart();
    int selEnd = editor.getSelectionModel().getSelectionEnd();
    if (selEnd > selStart && DocumentUtil.isAtLineStart(selEnd, editor.getDocument())) {
      selEnd--;
    }
    VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd));
    VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd));
    final Couple<Integer> copiedRange =
      DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd);
    if (copiedRange != null) {
      editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second);
    }
  }
  else {
    VisualPosition caretPos = editor.getCaretModel().getVisualPosition();
    DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), caretPos, caretPos);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DuplicateLinesAction.java

示例15: getFoldRegionsForSelection

import com.intellij.openapi.editor.Caret; //导入依赖的package包/类
/**
 * Returns fold regions inside selection, or all regions in editor, if selection doesn't exist or doesn't contain fold regions.
 */
protected List<FoldRegion> getFoldRegionsForSelection(@NotNull Editor editor, @Nullable Caret caret) {
  FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions();
  if (caret == null) {
    caret = editor.getCaretModel().getPrimaryCaret();
  }
  if (caret.hasSelection()) {
    List<FoldRegion> result = new ArrayList<FoldRegion>();
    for (FoldRegion region : allRegions) {
      if (region.getStartOffset() >= caret.getSelectionStart() && region.getEndOffset() <= caret.getSelectionEnd()) {
        result.add(region);
      }
    }
    if (!result.isEmpty()) {
      return result;
    }
  }
  return Arrays.asList(allRegions);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:BaseFoldingHandler.java


注:本文中的com.intellij.openapi.editor.Caret类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。