UNPKG

@textbus/platform-browser

Version:

Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.

72 lines (71 loc) 2.8 kB
import { Observable } from '@tanbo/stream'; import { NativeSelectionBridge, NativeSelectionConnector, SelectionPosition, AbstractSelection, RootComponentRef, Controller, Selection, Textbus, Scheduler } from '@textbus/core'; import { Rect } from './_utils/uikit'; import { Input } from './types'; import { ViewOptions } from './browser-module'; import { DomAdapter } from './dom-adapter'; /** * Textbus PC 端选区桥接实现 */ export declare class SelectionBridge implements NativeSelectionBridge { private config; private selection; private rootComponentRef; private input; private scheduler; private domAdapter; onSelectionChange: Observable<Range | null>; nativeSelection: globalThis.Selection; syncSelectionFromNativeSelectionChange: boolean; private selectionChangeEvent; private subs; private sub; private connector; private ignoreSelectionChange; private changeFromUser; private docContainer; private cacheCaretPositionTimer; private oldCaretPosition; constructor(config: ViewOptions, textbus: Textbus, controller: Controller, selection: Selection, rootComponentRef: RootComponentRef, input: Input, scheduler: Scheduler, domAdapter: DomAdapter); connect(connector: NativeSelectionConnector): void; disConnect(): void; getRect(location: SelectionPosition): Rect | null; restore(abstractSelection: AbstractSelection | null, fromLocal: boolean): void; destroy(): void; getPositionByRange(abstractSelection: AbstractSelection): { focus: { node: Node; offset: number; } | null; anchor: { node: Node; offset: number; } | null; }; getPreviousLinePositionByCurrent(position: SelectionPosition): SelectionPosition | null; getNextLinePositionByCurrent(position: SelectionPosition): SelectionPosition | null; private getLinePosition; /** * 通过遍历模型位置 + 视觉 rect 判断换行,计算光标到下一行或上一行的位置。 * 不使用 Selection.modify(),避免复杂布局中的死循环。 */ private getVerticalMovePosition; /** 目标位置是否已离开起始行 */ private isDifferentLine; /** * 沿目标行微调位置。 * 起点在 targetX 右侧 → 向左找到离 targetX 最近的右侧位置; * 起点在 targetX 左侧 → 向右找到第一个右侧位置。 */ private refineXOnLine; /** 跳转到文档开头或结尾 */ private getDocumentBoundary; private caretPositionFromPoint; private unListen; private listen; private syncSelection; private findSelectedNodeAndOffset; private getCorrectedPosition; private findFocusNode; private findFocusNodeByParent; }