Skip to main content

Overview

The EditorView class provides a complete text editing UI component with viewport management, text selection, visual cursor control, and text wrapping. It works with an EditBuffer to provide the visual rendering layer for text editing.

Constructor

RenderLib
required
The render library instance.
Pointer
required
Pointer to the native view.
EditBuffer
required
The EditBuffer instance to render.

Static Methods

create

Creates a new EditorView instance.
EditBuffer
required
The EditBuffer to render.
number
required
The width of the viewport in characters.
number
required
The height of the viewport in lines.
EditorView
A new EditorView instance.

Properties

ptr

Pointer
The native pointer to the view.

extmarks

any
The extmarks controller for managing editor marks.

Viewport Management

setViewportSize

Sets the viewport dimensions.
number
required
The viewport width in characters.
number
required
The viewport height in lines.

setViewport

Sets the complete viewport configuration.
number
required
The horizontal offset.
number
required
The vertical offset (line number).
number
required
The viewport width in characters.
number
required
The viewport height in lines.
boolean
default:"true"
Whether to move the cursor into view.

getViewport

Gets the current viewport configuration.
Viewport
Object containing offsetX, offsetY, width, and height.

setScrollMargin

Sets the scroll margin for cursor visibility.
number
required
The scroll margin in lines.

Text Wrapping

setWrapMode

Sets the text wrapping mode.
'none' | 'char' | 'word'
required
The wrapping mode: “none” (no wrap), “char” (wrap at character), or “word” (wrap at word boundary).

Line Information

getVirtualLineCount

Gets the number of virtual lines visible in the viewport.
number
The number of visible virtual lines.

getTotalVirtualLineCount

Gets the total number of virtual lines (including wrapping).
number
The total number of virtual lines.

getLineInfo

Gets line information for the current viewport.
LineInfo
Line information including offsets and positions.

getLogicalLineInfo

Gets logical line information (without wrapping).
LineInfo
Logical line information.

Selection

setSelection

Sets the text selection by character offsets.
number
required
The start character offset.
number
required
The end character offset.
RGBA
Background color for the selection.
RGBA
Foreground color for the selection.

updateSelection

Updates the end position of the current selection.
number
required
The new end character offset.
RGBA
Background color for the selection.
RGBA
Foreground color for the selection.

resetSelection

Clears the current selection.

getSelection

Gets the current selection range.
{ start: number; end: number } | null
The selection range or null if no selection.

hasSelection

Checks if there is an active selection.
boolean
True if there is an active selection.

setLocalSelection

Sets selection using viewport-relative coordinates.
number
required
The anchor X position in viewport.
number
required
The anchor Y position in viewport.
number
required
The focus X position in viewport.
number
required
The focus Y position in viewport.
RGBA
Background color for the selection.
RGBA
Foreground color for the selection.
boolean
default:"false"
Whether to update the cursor position.
boolean
default:"false"
Whether to follow the cursor.
boolean
True if the selection was set successfully.

updateLocalSelection

Updates selection using viewport-relative coordinates.
number
required
The anchor X position in viewport.
number
required
The anchor Y position in viewport.
number
required
The focus X position in viewport.
number
required
The focus Y position in viewport.
RGBA
Background color for the selection.
RGBA
Foreground color for the selection.
boolean
default:"false"
Whether to update the cursor position.
boolean
default:"false"
Whether to follow the cursor.
boolean
True if the selection was updated successfully.

resetLocalSelection

Clears the local selection.

getSelectedText

Gets the currently selected text.
string
The selected text or empty string if no selection.

deleteSelectedText

Deletes the currently selected text.

Cursor Operations

getCursor

Gets the current cursor position.
{ row: number; col: number }
The cursor position.

getVisualCursor

Gets the visual cursor position (accounting for wrapping).
VisualCursor
The visual cursor position with row, col, and offset.

setCursorByOffset

Sets the cursor by character offset.
number
required
The character offset (0-based).

moveUpVisual

Moves the cursor up one visual line.

moveDownVisual

Moves the cursor down one visual line.

getNextWordBoundary

Finds the next word boundary from the cursor.
VisualCursor
The position of the next word boundary.

getPrevWordBoundary

Finds the previous word boundary from the cursor.
VisualCursor
The position of the previous word boundary.

getEOL

Gets the end-of-line position for the current line.
VisualCursor
The end-of-line position.

getVisualSOL

Gets the visual start-of-line position.
VisualCursor
The visual start-of-line position.

getVisualEOL

Gets the visual end-of-line position.
VisualCursor
The visual end-of-line position.

Text Retrieval

getText

Gets the text content visible in the view.
string
The visible text content.

Placeholder Text

setPlaceholderStyledText

Sets placeholder text with styling.
Array<{ text: string; fg?: RGBA; bg?: RGBA; attributes?: number }>
required
Array of styled text chunks for the placeholder.

Tab Indicators

setTabIndicator

Sets the character to display for tab characters.
string | number
required
The character or Unicode code point to display for tabs.

setTabIndicatorColor

Sets the color for tab indicator characters.
RGBA
required
The color for tab indicators.

Measurement

measureForDimensions

Measures the text for given dimensions.
number
required
The width to measure for.
number
required
The height to measure for.
{ lineCount: number; maxWidth: number } | null
Measurement result with line count and max width, or null on error.

Memory Management

destroy

Destroys the view and frees native resources.

Types

Viewport

number
required
The vertical offset (line number).
number
required
The horizontal offset (column).
number
required
The viewport height in lines.
number
required
The viewport width in characters.

VisualCursor

number
required
The visual row position.
number
required
The visual column position.
number
required
The character offset from start of buffer.

Example