Skip to content

事件 ​

用类型化助手或 EventBus 订阅。

kotlin
val unsub = controller.onTextChanged { event ->
    // event.changes, event.kind, event.source
}
unsub()

controller.events.subscribe<CursorChangedEvent> { }

dispose() 会清空 bus。Composable detach 时不会自动清 events(除非你调用 dispose)。

EditorEvent 类型 ​

类型字段
TextChangedEventchanges: List<TextChange>、kind、source
CursorChangedEventcursorPosition
SelectionChangedEventhasSelection、selection、cursorPosition
ScrollChangedEventscrollX、scrollY
ScaleChangedEventscale
DocumentLoadedEventlineCount
FoldToggleEventline
GutterIconClickEventline、column、iconId、locationInEditor
InlayHintClickEventline、column、locationInEditor
CodeLensClickEventline、column、locationInEditor
LongPressEventcursorPosition、locationInEditor
DoubleTapEventcursorPosition、locationInEditor
ContextMenuEventcursorPosition、locationInEditor
ContextMenuItemClickEventitem、request
SelectionMenuItemClickEventitemId
LinkClickEventline、column、target、locationInEditor

TextChange 是 range + newText。

来源与种类 ​

EditorActionSource:NONE、SETUP、PROGRAMMATIC、KEYBOARD、IME、GESTURE、ANIMATION、DECORATION、FOLDING、SEARCH、LINKED_EDITING、DIFF。

TextChangeKind:NONE、INSERTION、REPLACEMENT、DELETION、MOVE、UNDO、REDO、MIXED。

查询 API 不返回动作结果。变更走 session 唯一派发,再变成这些事件。