Skip to main content

LensStudio:Ui.TextCursor

Class

Represents cursor position in text.

Index

Example

export class TextCursorPanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.UiTextCursorExample';
d.name = 'TextCursor Example';
d.defaultDockState = DockState.Detached;
d.defaultSize = new Size(400, 300);
return d;
}
constructor(pluginSystem: Editor.PluginSystem, descriptor?: Descriptor) {
super(pluginSystem, descriptor);
this.connections = [];
}
createWidget(parent: Widget): Widget {
const root = new Widget(parent);
const layout = new BoxLayout();
layout.setDirection(Direction.TopToBottom);
layout.spacing = 8;
root.layout = layout;

const title = new Label(root);
title.text = 'TextCursor Demo';
title.fontRole = FontRole.TitleBold;
layout.addWidget(title);

const edit = new TextEdit(root);
edit.plainText = 'Hello World\nSecond line\nThird line';
layout.addWidget(edit);

const selectAllBtn = new PushButton(root);
selectAllBtn.text = 'Select All (Start -> End with KeepAnchor)';
layout.addWidget(selectAllBtn);

const moveStartBtn = new PushButton(root);
moveStartBtn.text = 'Move to Start';
layout.addWidget(moveStartBtn);

this.connections.push(
selectAllBtn.onClick.connect(() => {
// TextCursor.movePosition navigates within the text
const cursor = edit.textCursor;
cursor.movePosition(TextCursor.MoveOperation.Start, TextCursor.MoveMode.MoveAnchor);
cursor.movePosition(TextCursor.MoveOperation.End, TextCursor.MoveMode.KeepAnchor);
edit.textCursor = cursor;
}),
moveStartBtn.onClick.connect(() => {
const cursor = edit.textCursor;
cursor.movePosition(TextCursor.MoveOperation.Start, TextCursor.MoveMode.MoveAnchor);
edit.textCursor = cursor;
})
);

return root;
}
deinit(): void {
this.connections.forEach((c: any) => c?.disconnect());
this.connections = [];
}
}

Methods

movePosition()

movePosition(operation, mode): boolean

Moves the cursor using the given operation and mode, returns true if the position changed.

Parameters

ParameterType
operationMoveOperation
modeMoveMode

Returns

boolean

Nested types

Enumerations

EnumerationDescription
MoveModeEnum controlling whether moving the cursor moves the anchor or keeps it to extend the selection.
MoveOperationEnum of cursor movement operations such as Start, End, NextWord, StartOfLine, and others.