本文整理了Java中com.intellij.openapi.editor.Editor
类的一些代码示例,展示了Editor
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Editor
类的具体详情如下:
包路径:com.intellij.openapi.editor.Editor
类名称:Editor
暂无
代码示例来源:origin: JetBrains/ideavim
public List<Integer> getOrderedLines(@NotNull Editor editor, @NotNull DataContext context,
@NotNull CaretOrder caretOrder) {
final ArrayList<Integer> lines = new ArrayList<>(editor.getCaretModel().getCaretCount());
for (Caret caret : EditorHelper.getOrderedCaretsList(editor, caretOrder)) {
final int line = getLine(editor, caret, context);
lines.add(line);
}
return lines;
}
代码示例来源:origin: JetBrains/ideavim
public void displayHexInfo(@NotNull Editor editor) {
int offset = editor.getCaretModel().getOffset();
char ch = editor.getDocument().getCharsSequence().charAt(offset);
VimPlugin.showMessage(Long.toHexString(ch));
}
代码示例来源:origin: JetBrains/ideavim
private void deinitLineNumbers(@NotNull Editor editor) {
editor.getCaretModel().removeCaretListener(myLineNumbersCaretListener);
EditorData.setEditorGroup(editor, false);
editor.getGutter().closeAllAnnotations();
final Project project = editor.getProject();
if (project == null || project.isDisposed()) return;
editor.getSettings().setLineNumbersShown(EditorData.isLineNumbersShown(editor));
}
代码示例来源:origin: JetBrains/ideavim
/**
* Gets the offset of the end of the line containing the supplied offset
*
* @param editor The editor
* @param offset The offset within the line
* @return The offset of the line end
*/
public static int getLineEndForOffset(@NotNull final Editor editor, final int offset) {
LogicalPosition pos = editor.offsetToLogicalPosition(normalizeOffset(editor, offset));
return editor.getDocument().getLineEndOffset(pos.line);
}
代码示例来源:origin: JetBrains/ideavim
@NotNull
public static RangeHighlighter highlightMatch(@NotNull Editor editor, int start, int end) {
TextAttributes color = editor.getColorsScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
return editor.getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.ADDITIONAL_SYNTAX + 1,
color, HighlighterTargetArea.EXACT_RANGE);
}
代码示例来源:origin: JetBrains/ideavim
private static void resetCursor(@NotNull Editor editor, boolean insert) {
Document doc = editor.getDocument();
VirtualFile vf = FileDocumentManager.getInstance().getFile(doc);
if (vf != null) {
resetCursor(vf, editor.getProject(), insert);
}
else {
editor.getSettings().setBlockCursor(!insert);
}
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Override
public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) {
if (myOriginalHandler != null) myOriginalHandler.execute(editor, c, dataContext);
if (c != 'e') return;
Project project = editor.getProject();
if (project == null) return;
int offset = editor.getCaretModel().getOffset();
if (offset < 4) return;
TextRange from = TextRange.from(offset - 4, 4);
String text = editor.getDocument().getText(from);
if ("case".equals(text)) {
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
ApplicationManager.getApplication().runWriteAction(() -> {
if (project.isDisposed()) return;
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
if (file == null) return;
CodeStyleManager.getInstance(project).adjustLineIndent(file, from);
});
}
}
}
代码示例来源:origin: JetBrains/ideavim
/***
* @see :help visualmode()
*/
@Nullable
public static SelectionType getLastSelectionType(@NotNull Editor editor) {
return editor.getDocument().getUserData(LAST_SELECTION_TYPE);
}
代码示例来源:origin: JetBrains/ideavim
private void processMouseReleased(@NotNull Editor editor, @NotNull CommandState.SubMode mode, int startOff,
int endOff) {
if (ExEntryPanel.getInstance().isActive()) {
ExEntryPanel.getInstance().deactivate(false);
}
ExOutputModel.getInstance(editor).clear();
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
CommandState.getInstance(editor).popState();
}
int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
if (start == end) return;
if (mode == CommandState.SubMode.VISUAL_LINE) {
end--;
endOff--;
}
if (end == startOff || end == endOff) {
int t = start;
start = end;
end = t;
if (mode == CommandState.SubMode.VISUAL_CHARACTER) {
start--;
}
}
MotionGroup.moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), start);
toggleVisual(editor, 1, 0, mode);
MotionGroup.moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), end);
KeyHandler.getInstance().reset(editor);
}
代码示例来源:origin: JetBrains/ideavim
public static void moveCaret(@NotNull Editor editor, @NotNull Caret caret, int offset, boolean forceKeepVisual) {
if (offset >= 0 && offset <= editor.getDocument().getTextLength()) {
final boolean keepVisual = forceKeepVisual || keepVisual(editor);
if (caret.getOffset() != offset) {
caret.moveToOffset(offset);
CaretData.setLastColumn(editor, caret, caret.getVisualPosition().column);
if (caret == editor.getCaretModel().getPrimaryCaret()) {
scrollCaretIntoView(editor);
}
}
if (keepVisual) {
VimPlugin.getMotion().updateSelection(editor, caret, offset);
}
else {
editor.getSelectionModel().removeSelection();
}
}
}
代码示例来源:origin: JetBrains/ideavim
private void updateBlockSelection(@NotNull Editor editor, int offset) {
EditorData.setVisualBlockEnd(editor, offset);
EditorData.setVisualBlockOffset(editor, offset);
int start = EditorData.getVisualBlockStart(editor);
int end = EditorData.getVisualBlockEnd(editor);
LogicalPosition blockStart = editor.offsetToLogicalPosition(start);
LogicalPosition blockEnd = editor.offsetToLogicalPosition(end);
if (blockStart.column < blockEnd.column) {
blockEnd = new LogicalPosition(blockEnd.line, blockEnd.column + 1);
}
else {
blockStart = new LogicalPosition(blockStart.line, blockStart.column + 1);
}
editor.getSelectionModel().setBlockSelection(blockStart, blockEnd);
for (Caret caret : editor.getCaretModel().getAllCarets()) {
int line = caret.getLogicalPosition().line;
int lineEndOffset = EditorHelper.getLineEndOffset(editor, line, true);
if (CaretData.getLastColumn(editor.getCaretModel().getPrimaryCaret()) >= MotionGroup.LAST_COLUMN) {
caret.setSelection(caret.getSelectionStart(), lineEndOffset);
}
if (!EditorHelper.isLineEmpty(editor, line, false)) {
caret.moveToOffset(caret.getSelectionEnd() - 1);
}
}
editor.getCaretModel().getPrimaryCaret().moveToOffset(end);
VimPlugin.getMark().setVisualSelectionMarks(editor, new TextRange(start, end));
}
代码示例来源:origin: JetBrains/ideavim
/**
* This processes all "regular" keystrokes entered while in insert/replace mode
*
* @param editor The editor the character was typed into
* @param context The data context
* @param key The user entered keystroke
* @return true if this was a regular character, false if not
*/
public boolean processKey(@NotNull final Editor editor, @NotNull final DataContext context,
@NotNull final KeyStroke key) {
if (logger.isDebugEnabled()) {
logger.debug("processKey(" + key + ")");
}
if (key.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
final Document doc = editor.getDocument();
CommandProcessor.getInstance().executeCommand(editor.getProject(),
() -> ApplicationManager.getApplication().runWriteAction(
() -> KeyHandler.getInstance().getOriginalHandler().execute(
editor, key.getKeyChar(), context)), "", doc,
UndoConfirmationPolicy.DEFAULT, doc);
return true;
}
return false;
}
代码示例来源:origin: JetBrains/ideavim
@Override
protected void textChanged(DocumentEvent e) {
final Editor editor = entry.getEditor();
final boolean forwards = !label.getText().equals("?");
if (incHighlighter != null) {
editor.getMarkupModel().removeHighlighter(incHighlighter);
}
final String pattern = entry.getText();
final TextRange range = SearchGroup.findNext(editor, pattern, editor.getCaretModel().getOffset(), true, forwards);
if (range != null) {
final TextAttributes color = editor.getColorsScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
incHighlighter = SearchGroup.highlightMatch(editor, range.getStartOffset(), range.getEndOffset());
incHighlighter.setErrorStripeMarkColor(color.getBackgroundColor());
incHighlighter.setErrorStripeTooltip(pattern);
MotionGroup.scrollPositionIntoView(editor, editor.offsetToVisualPosition(range.getStartOffset()), true);
}
}
};
代码示例来源:origin: JetBrains/ideavim
private void initLineNumbers(@NotNull final Editor editor) {
editor.getCaretModel().addCaretListener(myLineNumbersCaretListener);
EditorData.setEditorGroup(editor, true);
final EditorSettings settings = editor.getSettings();
EditorData.setLineNumbersShown(editor, settings.isLineNumbersShown());
updateLineNumbers(editor);
}
代码示例来源:origin: JetBrains/ideavim
int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
editor.getSelectionModel().setSelection(start, Math.max(start, end - 1));
final CaretModel caretModel = editor.getCaretModel();
if (CommandState.getInstance(editor).getSubMode() != CommandState.SubMode.NONE) {
caretModel.removeSecondaryCarets();
break;
case VISUAL_LINE:
caretModel.moveToLogicalPosition(editor.xyToLogicalPosition(event.getPoint()));
break;
代码示例来源:origin: JetBrains/ideavim
@NotNull
private LineRange getLineRange(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
@NotNull ExCommand cmd) {
final LineRange range = cmd.getLineRange(editor, caret, context);
final LineRange normalizedRange;
// Something like "30,20sort" gets converted to "20,30sort"
if (range.getEndLine() < range.getStartLine()) {
normalizedRange = new LineRange(range.getEndLine(), range.getStartLine());
}
else {
normalizedRange = range;
}
// If we don't have a range, we either have "sort", a selection, or a block
if (normalizedRange.getEndLine() - normalizedRange.getStartLine() == 0) {
// If we have a selection.
final SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.hasSelection()) {
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final int startLine = editor.offsetToLogicalPosition(start).line;
final int endLine = editor.offsetToLogicalPosition(end).line;
return new LineRange(startLine, endLine);
}
// If we have a generic selection, i.e. "sort" entire document
else {
return new LineRange(0, editor.getDocument().getLineCount() - 1);
}
}
return normalizedRange;
}
代码示例来源:origin: JetBrains/ideavim
public void selectionChanged(@NotNull SelectionEvent selectionEvent) {
final Editor editor = selectionEvent.getEditor();
final Document document = editor.getDocument();
if (myMakingChanges || (document instanceof DocumentEx && ((DocumentEx) document).isInEventsHandling())) {
return;
}
myMakingChanges = true;
try {
final com.intellij.openapi.util.TextRange newRange = selectionEvent.getNewRange();
for (Editor e : EditorFactory.getInstance().getEditors(document)) {
if (!e.equals(editor)) {
e.getSelectionModel().setSelection(newRange.getStartOffset(), newRange.getEndOffset());
}
}
} finally {
myMakingChanges = false;
}
}
}
代码示例来源:origin: JetBrains/ideavim
int start = editor.getDocument().getLineStartOffset(line1);
int end = editor.getDocument().getLineEndOffset(line2);
if (do_ask) {
RangeHighlighter hl = highlightConfirm(editor, startoff, endoff);
MotionGroup.scrollPositionIntoView(editor, editor.offsetToVisualPosition(startoff), true);
MotionGroup.moveCaret(editor, caret, start);
final ReplaceConfirmationChoice choice = confirmChoice(editor, match);
editor.getMarkupModel().removeHighlighter(hl);
switch (choice) {
case SUBSTITUTE_THIS:
editor.getDocument().replaceString(startoff, endoff, match);
lastMatch = startoff;
newpos = EditorHelper.offsetToCharacterPosition(editor, newend);
editor.offsetToLogicalPosition(
lastMatch).line));
代码示例来源:origin: JetBrains/ideavim
@Nullable
private Editor selectEditor(@NotNull Editor editor, @NotNull VirtualFile file) {
return VimPlugin.getFile().selectEditor(editor.getProject(), file);
}
代码示例来源:origin: JetBrains/ideavim
public void addEditorSelectionListener(@NotNull Editor editor, @NotNull SelectionListener listener) {
editor.getSelectionModel().addSelectionListener(listener);
}
内容来源于网络,如有侵权,请联系作者删除!