本文整理了Java中com.intellij.openapi.editor.Editor.getScrollingModel()
方法的一些代码示例,展示了Editor.getScrollingModel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Editor.getScrollingModel()
方法的具体详情如下:
包路径:com.intellij.openapi.editor.Editor
类名称:Editor
方法名:getScrollingModel
暂无
代码示例来源:origin: JetBrains/ideavim
/**
* Gets the number of characters that are visible on a screen line
*
* @param editor The editor
* @return The number of screen columns
*/
public static int getScreenWidth(@NotNull final Editor editor) {
Rectangle rect = editor.getScrollingModel().getVisibleArea();
Point pt = new Point(rect.width, 0);
VisualPosition vp = editor.xyToVisualPosition(pt);
return vp.column;
}
代码示例来源:origin: JetBrains/ideavim
public static int getVisualLineAtMiddleOfScreen(@NotNull final Editor editor) {
final ScrollingModel scrollingModel = editor.getScrollingModel();
final Rectangle visibleArea = scrollingModel.getVisibleArea();
return editor.yToVisualLine(visibleArea.y + (visibleArea.height / 2));
}
代码示例来源:origin: JetBrains/ideavim
/**
* Gets the column currently displayed at the left edge of the editor.
*
* @param editor The editor
* @return The column number
*/
public static int getVisualColumnAtLeftOfScreen(@NotNull final Editor editor) {
int cw = getColumnWidth(editor);
if (cw == 0) return 0;
return (editor.getScrollingModel().getHorizontalScrollOffset() + cw - 1) / cw;
}
代码示例来源:origin: JetBrains/ideavim
/**
* Gets the number of pixels per column of text.
*
* @param editor The editor
* @return The number of pixels
*/
public static int getColumnWidth(@NotNull final Editor editor) {
Rectangle rect = editor.getScrollingModel().getVisibleArea();
if (rect.width == 0) return 0;
Point pt = new Point(rect.width, 0);
VisualPosition vp = editor.xyToVisualPosition(pt);
if (vp.column == 0) return 0;
return rect.width / vp.column;
}
代码示例来源:origin: JetBrains/ideavim
public static int getVisualLineAtTopOfScreen(@NotNull final Editor editor) {
final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
return getFullVisualLine(editor, visibleArea.y, visibleArea.y, visibleArea.y + visibleArea.height);
}
代码示例来源:origin: JetBrains/ideavim
public static int getVisualLineAtBottomOfScreen(@NotNull final Editor editor) {
final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
return getFullVisualLine(editor, visibleArea.y + visibleArea.height, visibleArea.y, visibleArea.y + visibleArea.height);
}
代码示例来源:origin: JetBrains/ideavim
private static void scrollColumnToLeftOfScreen(@NotNull Editor editor, int column) {
editor.getScrollingModel().scrollHorizontally(column * EditorHelper.getColumnWidth(editor));
}
代码示例来源:origin: JetBrains/ideavim
/**
* Gets the number of lines than can be displayed on the screen at one time. This is rounded down to the
* nearest whole line if there is a partial line visible at the bottom of the screen.
*
* Note that this value is only approximate and should be avoided whenever possible!
*
* @param editor The editor
* @return The number of screen lines
*/
private static int getApproximateScreenHeight(@NotNull final Editor editor) {
int lh = editor.getLineHeight();
int height = editor.getScrollingModel().getVisibleArea().y +
editor.getScrollingModel().getVisibleArea().height -
getVisualLineAtTopOfScreen(editor) * lh;
return height / lh;
}
代码示例来源:origin: JetBrains/ideavim
/**
* Scrolls the editor to place the given visual line in the middle of the current window.
*
* @param editor The editor to scroll
* @param visualLine The visual line to place in the middle of the current window
*/
public static void scrollVisualLineToMiddleOfScreen(@NotNull Editor editor, int visualLine) {
final ScrollingModel scrollingModel = editor.getScrollingModel();
int y = editor.visualLineToY(visualLine);
int lineHeight = editor.getLineHeight();
int height = scrollingModel.getVisibleArea().height;
scrollingModel.scrollVertically(y - ((height - lineHeight) / 2));
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Override
public void invoke(@NotNull Project project,
@NotNull PsiFile file,
@Nullable("is null when called from inspection") Editor editor,
@NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
if (!(file instanceof GoFile) || editor == null || !(startElement instanceof GoBlock)) return;
PsiElement brace = ((GoBlock)startElement).getRbrace();
if (brace == null) return;
Template template = TemplateSettings.getInstance().getTemplateById("go_lang_add_return");
if (template == null) return;
int start = brace.getTextRange().getStartOffset();
editor.getCaretModel().moveToOffset(start);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
template.setToReformat(true);
TemplateManager.getInstance(project).startTemplate(editor, template, true, Collections.emptyMap(), null);
}
}
代码示例来源:origin: JetBrains/ideavim
/**
* Scrolls the editor to put the given visual line at the top of the current window. Ensures that any block inlay
* elements above the given line are also visible.
*
* @param editor The editor to scroll
* @param visualLine The visual line to place at the top of the current window
* @return Returns true if the window was moved
*/
public static boolean scrollVisualLineToTopOfScreen(@NotNull final Editor editor, int visualLine) {
final ScrollingModel scrollingModel = editor.getScrollingModel();
int inlayHeight = getHeightOfVisualLineInlays(editor, visualLine, true);
int y = editor.visualLineToY(visualLine) - inlayHeight;
int verticalPos = scrollingModel.getVerticalScrollOffset();
scrollingModel.scrollVertically(y);
return verticalPos != scrollingModel.getVerticalScrollOffset();
}
代码示例来源:origin: JetBrains/ideavim
private static int scrollFullPageUp(@NotNull final Editor editor, int pages) {
final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
final int lineHeight = editor.getLineHeight();
int y = visibleArea.y;
int topBound = visibleArea.y;
int bottomBound = visibleArea.y + visibleArea.height;
int line = 0;
int caretLine = -1;
// We know pages is negative
for (int i = pages; i < 0; i++) {
// E.g. a window showing 73-107 has page size 33. Scrolling up puts 74 at the bottom of the screen
line = getFullVisualLine(editor, y, topBound, bottomBound) + 1;
if (line == 1) {
break;
}
y = editor.visualLineToY(line);
bottomBound = y + lineHeight;
topBound = bottomBound - visibleArea.height;
y = topBound;
caretLine = line;
}
scrollVisualLineToBottomOfScreen(editor, line);
return caretLine;
}
代码示例来源:origin: JetBrains/ideavim
private static int getScrollScreenTargetCaretVisualLine(@NotNull final Editor editor, int rawCount, boolean down) {
final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
final int caretVisualLine = editor.getCaretModel().getVisualPosition().line;
final int scrollOption = getScrollOption(rawCount);
int targetCaretVisualLine;
if (scrollOption == 0) {
// Scroll up/down half window size by default. We can't use line count here because of block inlays
final int offset = down ? (visibleArea.height / 2) : editor.getLineHeight() - (visibleArea.height / 2);
targetCaretVisualLine = editor.yToVisualLine(editor.visualLineToY(caretVisualLine) + offset);
} else {
targetCaretVisualLine = down ? caretVisualLine + scrollOption : caretVisualLine - scrollOption;
}
return targetCaretVisualLine;
}
代码示例来源:origin: JetBrains/ideavim
private static int scrollFullPageDown(@NotNull final Editor editor, int pages) {
final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
final int lineCount = getVisualLineCount(editor);
代码示例来源:origin: JetBrains/ideavim
final ScrollingModel scrollingModel = editor.getScrollingModel();
final Rectangle visibleArea = scrollingModel.getVisibleArea();
final int caretScreenOffset = editor.visualLineToY(editor.getCaretModel().getVisualPosition().line) - visibleArea.y;
代码示例来源:origin: JetBrains/ideavim
/**
* Turns off the ex entry field and optionally puts the focus back to the original component
*/
public void deactivate(boolean refocusOwningEditor) {
logger.info("deactivate");
if (!active) return;
active = false;
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (refocusOwningEditor && parent != null) {
UiHelper.requestFocus(parent);
}
oldGlass.removeComponentListener(adapter);
oldGlass.setVisible(false);
oldGlass.remove(this);
oldGlass.setOpaque(wasOpaque);
oldGlass.setLayout(oldLayout);
if (isIncSearchEnabled(label.getText())) {
entry.getDocument().removeDocumentListener(documentListener);
final Editor editor = entry.getEditor();
editor.getScrollingModel().scrollVertically(verticalOffset);
editor.getScrollingModel().scrollHorizontally(horizontalOffset);
if (incHighlighter != null) {
editor.getMarkupModel().removeHighlighter(incHighlighter);
}
}
}
parent = null;
}
代码示例来源:origin: JetBrains/ideavim
final ScrollingModel scrollingModel = editor.getScrollingModel();
int inlayHeight = getHeightOfVisualLineInlays(editor, visualLine, false);
int y = editor.visualLineToY(visualLine);
代码示例来源:origin: JetBrains/ideavim
final ScrollingModel scrollingModel = editor.getScrollingModel();
final Rectangle visibleArea = scrollingModel.getVisibleArea();
代码示例来源:origin: JetBrains/ideavim
public boolean selectPreviousVisualMode(@NotNull Editor editor) {
final SelectionType lastSelectionType = EditorData.getLastSelectionType(editor);
if (lastSelectionType == null) {
return false;
}
final TextRange visualMarks = VimPlugin.getMark().getVisualSelectionMarks(editor);
if (visualMarks == null) {
return false;
}
editor.getCaretModel().removeSecondaryCarets();
CommandState.getInstance(editor)
.pushState(CommandState.Mode.VISUAL, lastSelectionType.toSubMode(), MappingMode.VISUAL);
Caret primaryCaret = editor.getCaretModel().getPrimaryCaret();
CaretData.setVisualStart(primaryCaret, visualMarks.getStartOffset());
CaretData.setVisualEnd(primaryCaret, visualMarks.getEndOffset());
CaretData.setVisualOffset(primaryCaret, visualMarks.getEndOffset());
updateSelection(editor, primaryCaret, visualMarks.getEndOffset());
primaryCaret.moveToOffset(visualMarks.getEndOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
return true;
}
代码示例来源:origin: JetBrains/ideavim
public boolean swapVisualSelections(@NotNull Editor editor) {
final SelectionType lastSelectionType = EditorData.getLastSelectionType(editor);
final TextRange lastVisualRange = EditorData.getLastVisualRange(editor);
if (lastSelectionType == null || lastVisualRange == null) {
return false;
}
final SelectionType selectionType = SelectionType.fromSubMode(CommandState.getInstance(editor).getSubMode());
EditorData.setLastSelectionType(editor, selectionType);
editor.getCaretModel().removeSecondaryCarets();
Caret primaryCaret = editor.getCaretModel().getPrimaryCaret();
CaretData.setVisualStart(primaryCaret, lastVisualRange.getStartOffset());
CaretData.setVisualEnd(primaryCaret, lastVisualRange.getEndOffset());
CaretData.setVisualOffset(primaryCaret, lastVisualRange.getEndOffset());
CommandState.getInstance(editor).setSubMode(lastSelectionType.toSubMode());
updateSelection(editor, primaryCaret, lastVisualRange.getEndOffset());
primaryCaret.moveToOffset(lastVisualRange.getEndOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
return true;
}
内容来源于网络,如有侵权,请联系作者删除!