public final class EditorUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
addBulkSelectionListener(Editor editor,
SelectionListener listener,
Disposable disposable)
This is similar to
SelectionModel.addSelectionListener(SelectionListener, Disposable) , but when selection changes happen within
the scope of CaretModel.runForEachCaret(CaretAction) call, there will be only one notification at the end of iteration over
carets. |
static boolean |
attributesImpactFontStyleOrColor(TextAttributes attributes) |
static Pair<LogicalPosition,LogicalPosition> |
calcCaretLineRange(Caret caret) |
static Pair<LogicalPosition,LogicalPosition> |
calcCaretLineRange(Editor editor)
Delegates to the
calcSurroundingRange(Editor, VisualPosition, VisualPosition) with the
caret visual position as an argument. |
static int |
calcColumnNumber(Editor editor,
java.lang.CharSequence text,
int start,
int offset) |
static int |
calcColumnNumber(Editor editor,
java.lang.CharSequence text,
int start,
int offset,
int tabSize) |
static int |
calcRelativeCaretPosition(Editor editor) |
static Pair<LogicalPosition,LogicalPosition> |
calcSurroundingRange(Editor editor,
VisualPosition start,
VisualPosition end)
Calculates logical positions that surround given visual positions and conform to the following criteria:
|
static float |
calcVerticalScrollProportion(Editor editor) |
static int |
charWidth(char c,
int fontType,
Editor editor) |
static int |
columnsNumber(float width,
float plainSpaceSize) |
static int |
columnsNumber(int width,
int plainSpaceSize)
Allows to answer how many visual columns are occupied by the given width.
|
static java.lang.String |
displayCharInEditor(char c,
TextAttributesKey textAttributesKey,
java.lang.String fallback) |
static void |
disposeWithEditor(Editor editor,
Disposable disposable) |
static void |
fillVirtualSpaceUntil(Editor editor,
int columnNumber,
int lineNumber) |
static void |
fillVirtualSpaceUntilCaret(Editor editor) |
static FontInfo |
fontForChar(char c,
int style,
Editor editor) |
static int |
getDefaultCaretWidth() |
static EditorEx |
getEditorEx(FileEditor fileEditor) |
static java.awt.Font |
getEditorFont()
This returns a
Font.PLAIN font from family, used in editor, with size matching editor font size (except in
presentation mode, when adjusted presentation mode font size is used). |
static int |
getInlaysHeight(Editor editor,
int visualLine,
boolean above) |
static int |
getLastVisualLineColumnNumber(Editor editor,
int line) |
static int |
getNotFoldedLineEndOffset(Editor editor,
int offset)
Finds the end offset of visual line at which given offset is located, not taking soft wraps into account.
|
static int |
getNotFoldedLineStartOffset(Editor editor,
int offset)
Finds the start offset of visual line at which given offset is located, not taking soft wraps into account.
|
static int |
getPlainSpaceWidth(Editor editor) |
static TextRange |
getSelectionInAnyMode(Editor editor) |
static int |
getSoftWrapCountAfterLineStart(Editor editor,
LogicalPosition position)
Number of virtual soft wrap introduced lines on a current logical line before the visual position that corresponds
to the current logical position.
|
static int |
getSpaceWidth(int fontType,
Editor editor) |
static int |
getTabSize(Editor editor) |
static int |
getTotalInlaysHeight(java.util.List<? extends Inlay> inlays) |
static int |
getVisualLineAreaEndY(Editor editor,
int visualLine)
Returns bottom Y coordinate of editor visual line's area.
|
static int |
getVisualLineAreaStartY(Editor editor,
int visualLine)
Returns top Y coordinate of editor visual line's area.
|
static int |
getVisualLineEndOffset(Editor editor,
int line) |
static VisualPosition |
inlayAwareOffsetToVisualPosition(Editor editor,
int offset)
Performs inlay-aware conversion of offset to visual position in editor.
|
static boolean |
inVirtualSpace(Editor editor,
LogicalPosition logicalPosition) |
static boolean |
isAtLineEnd(Editor editor,
int offset) |
static boolean |
isCaretInVirtualSpace(Editor editor) |
static boolean |
isChangeFontSize(java.awt.event.MouseWheelEvent e) |
static boolean |
isCurrentCaretPrimary(Editor editor) |
static boolean |
isPasswordEditor(Editor editor) |
static boolean |
isPointOverText(Editor editor,
java.awt.Point point)
Virtual space (after line end, and after end of text), inlays and space between visual lines (where block inlays are located) is
excluded
|
static boolean |
isPrimaryCaretVisible(Editor editor) |
static boolean |
isRealFileEditor(Editor editor) |
static int |
logicalToVisualLine(Editor editor,
int logicalLine) |
static float |
nextTabStop(float x,
float plainSpaceWidth,
int tabSize) |
static int |
nextTabStop(int x,
Editor editor) |
static int |
nextTabStop(int x,
Editor editor,
int tabSize) |
static int |
nextTabStop(int x,
int plainSpaceWidth,
int tabSize) |
static void |
performBeforeCommandEnd(java.lang.Runnable task)
If a command is currently executing (see
CommandProcessor ), schedules the execution of given task before the end of that
command (so that it becomes part of it), otherwise does nothing. |
static void |
reinitSettings() |
static void |
runBatchFoldingOperationOutsideOfBulkUpdate(Editor editor,
java.lang.Runnable operation) |
static void |
runWithAnimationDisabled(Editor editor,
java.lang.Runnable taskWithScrolling) |
static javax.swing.Icon |
scaleIconAccordingEditorFont(javax.swing.Icon icon,
Editor editor) |
static void |
scrollToTheEnd(Editor editor) |
static void |
scrollToTheEnd(Editor editor,
boolean preferVerticalScroll) |
static void |
setRelativeCaretPosition(Editor editor,
int position) |
static void |
setSelectionExpandingFoldedRegionsIfNeeded(Editor editor,
int startOffset,
int endOffset)
Setting selection using
SelectionModel.setSelection(int, int) or Caret.setSelection(int, int) methods can result
in resulting selection range to be larger than requested (in case requested range intersects with collapsed fold regions). |
static void |
setVerticalScrollProportion(Editor editor,
float proportion) |
static int |
textWidth(Editor editor,
java.lang.CharSequence text,
int start,
int end,
int fontType,
int x)
Allows to answer what width in pixels is required to draw fragment of the given char array from
[start; end) interval
at the given editor. |
static int |
textWidthInColumns(Editor editor,
java.lang.CharSequence text,
int start,
int end,
int x) |
static int |
yPositionToLogicalLine(Editor editor,
int y) |
static int |
yPositionToLogicalLine(Editor editor,
java.awt.event.MouseEvent event) |
static int |
yPositionToLogicalLine(Editor editor,
java.awt.Point point) |
static int |
yToLogicalLineNoBlockInlays(Editor editor,
int y)
Maps
y to a logical line in editor (in the same way as yPositionToLogicalLine(Editor, int) does), except that for
coordinates, corresponding to block inlay locations, -1 is returned. |
public static boolean isRealFileEditor(Editor editor)
public static boolean isPasswordEditor(Editor editor)
public static EditorEx getEditorEx(FileEditor fileEditor)
public static int getLastVisualLineColumnNumber(Editor editor, int line)
public static int getVisualLineEndOffset(Editor editor, int line)
public static float calcVerticalScrollProportion(Editor editor)
public static void setVerticalScrollProportion(Editor editor, float proportion)
public static int calcRelativeCaretPosition(Editor editor)
public static void setRelativeCaretPosition(Editor editor, int position)
public static void fillVirtualSpaceUntilCaret(Editor editor)
public static void fillVirtualSpaceUntil(Editor editor, int columnNumber, int lineNumber)
public static int calcColumnNumber(Editor editor, java.lang.CharSequence text, int start, int offset)
public static int calcColumnNumber(Editor editor, java.lang.CharSequence text, int start, int offset, int tabSize)
public static javax.swing.Icon scaleIconAccordingEditorFont(javax.swing.Icon icon, Editor editor)
public static int charWidth(char c, int fontType, Editor editor)
public static int getSpaceWidth(int fontType, Editor editor)
public static int getPlainSpaceWidth(Editor editor)
public static int getTabSize(Editor editor)
public static int nextTabStop(int x, Editor editor)
public static int nextTabStop(int x, Editor editor, int tabSize)
public static int nextTabStop(int x, int plainSpaceWidth, int tabSize)
public static float nextTabStop(float x, float plainSpaceWidth, int tabSize)
public static int textWidthInColumns(Editor editor, java.lang.CharSequence text, int start, int end, int x)
public static int columnsNumber(int width, int plainSpaceSize)
width
- target widthplainSpaceSize
- width of the single space symbol within the target editor (in plain font style)public static int columnsNumber(float width, float plainSpaceSize)
public static int textWidth(Editor editor, java.lang.CharSequence text, int start, int end, int fontType, int x)
[start; end)
interval
at the given editor.
Tabulation symbols is processed specially, i.e. it's ta
Note: it's assumed that target text fragment remains to the single line, i.e. line feed symbols within it are not
treated specially.editor
- editor that will be used for target text representationtext
- target text holderstart
- offset within the given char array that points to target text start (inclusive)end
- offset within the given char array that points to target text end (exclusive)fontType
- font type to use for target text representationx
- 'x'
coordinate that should be used as a starting point for target text representation.
It's necessity is implied by the fact that IDEA editor may represent tabulation symbols in any range
from [1; tab size]
(check nextTabStop(int, Editor)
for more details)public static Pair<LogicalPosition,LogicalPosition> calcCaretLineRange(Editor editor)
calcSurroundingRange(Editor, VisualPosition, VisualPosition)
with the
caret visual position
as an argument.editor
- target editorcalcSurroundingRange(Editor, VisualPosition, VisualPosition)
public static Pair<LogicalPosition,LogicalPosition> calcCaretLineRange(Caret caret)
public static Pair<LogicalPosition,LogicalPosition> calcSurroundingRange(Editor editor, VisualPosition start, VisualPosition end)
first line [soft-wrap] some [start-position] text [end-position] [fold-start] fold line 1 fold line 2 fold line 3[fold-end] [soft-wrap] end textThe very first and the last positions will be returned here.
editor
- target editor to usestart
- target start coordinateend
- target end coordinategetNotFoldedLineStartOffset(Editor, int)
,
getNotFoldedLineEndOffset(Editor, int)
public static int getNotFoldedLineStartOffset(Editor editor, int offset)
public static int getNotFoldedLineEndOffset(Editor editor, int offset)
public static void scrollToTheEnd(Editor editor)
public static void scrollToTheEnd(Editor editor, boolean preferVerticalScroll)
public static boolean isChangeFontSize(java.awt.event.MouseWheelEvent e)
public static boolean isCaretInVirtualSpace(Editor editor)
public static boolean inVirtualSpace(Editor editor, LogicalPosition logicalPosition)
public static void reinitSettings()
public static int logicalToVisualLine(Editor editor, int logicalLine)
public static int yPositionToLogicalLine(Editor editor, java.awt.event.MouseEvent event)
public static int yPositionToLogicalLine(Editor editor, java.awt.Point point)
public static int yPositionToLogicalLine(Editor editor, int y)
public static int yToLogicalLineNoBlockInlays(Editor editor, int y)
y
to a logical line in editor (in the same way as yPositionToLogicalLine(Editor, int)
does), except that for
coordinates, corresponding to block inlay locations, -1
is returned.public static boolean isAtLineEnd(Editor editor, int offset)
public static void setSelectionExpandingFoldedRegionsIfNeeded(Editor editor, int startOffset, int endOffset)
SelectionModel.setSelection(int, int)
or Caret.setSelection(int, int)
methods can result
in resulting selection range to be larger than requested (in case requested range intersects with collapsed fold regions).
This method will make sure interfering collapsed regions are expanded first, so that resulting selection range is exactly as
requested.public static java.awt.Font getEditorFont()
Font.PLAIN
font from family, used in editor, with size matching editor font size (except in
presentation mode, when adjusted presentation mode font size is used). Returned font has fallback variants (i.e. if main font doesn't
support certain Unicode characters, some other font may be used to display them), but fallback mechanism differs from the one used in
editor.public static int getDefaultCaretWidth()
public static int getSoftWrapCountAfterLineStart(Editor editor, LogicalPosition position)
public static boolean attributesImpactFontStyleOrColor(TextAttributes attributes)
public static boolean isCurrentCaretPrimary(Editor editor)
public static void disposeWithEditor(Editor editor, Disposable disposable)
public static void runBatchFoldingOperationOutsideOfBulkUpdate(Editor editor, java.lang.Runnable operation)
public static void runWithAnimationDisabled(Editor editor, java.lang.Runnable taskWithScrolling)
public static java.lang.String displayCharInEditor(char c, TextAttributesKey textAttributesKey, java.lang.String fallback)
public static VisualPosition inlayAwareOffsetToVisualPosition(Editor editor, int offset)
Caret.moveToOffset(int)
call.
NOTE: if editor is an EditorWindow
, corresponding offset is treated as an offset in injected editor, but returned position
is always related to host editor.
Inlay.isRelatedToPrecedingText()
public static int getTotalInlaysHeight(java.util.List<? extends Inlay> inlays)
public static int getInlaysHeight(Editor editor, int visualLine, boolean above)
public static int getVisualLineAreaStartY(Editor editor, int visualLine)
public static int getVisualLineAreaEndY(Editor editor, int visualLine)
public static void addBulkSelectionListener(Editor editor, SelectionListener listener, Disposable disposable)
SelectionModel.addSelectionListener(SelectionListener, Disposable)
, but when selection changes happen within
the scope of CaretModel.runForEachCaret(CaretAction)
call, there will be only one notification at the end of iteration over
carets.public static void performBeforeCommandEnd(java.lang.Runnable task)
CommandProcessor
), schedules the execution of given task before the end of that
command (so that it becomes part of it), otherwise does nothing.public static boolean isPrimaryCaretVisible(Editor editor)
public static boolean isPointOverText(Editor editor, java.awt.Point point)