1
1
import { printTree , type Printable } from 'tree-dump' ;
2
+ import { AvlMap } from "sonic-forest/lib/avl/AvlMap" ;
2
3
import { InputController } from './InputController' ;
3
4
import { CursorController } from './CursorController' ;
4
5
import { RichTextController } from './RichTextController' ;
@@ -8,12 +9,12 @@ import {AnnalsController} from './annals/AnnalsController';
8
9
import { ElementAttr } from '../constants' ;
9
10
import { Anchor } from '../../../json-crdt-extensions/peritext/rga/constants' ;
10
11
import { UiHandle } from '../../events/defaults/ui/UiHandle' ;
11
- import type { ITimestampStruct } from '../../../json-crdt-patch' ;
12
+ import { compare , type ITimestampStruct } from '../../../json-crdt-patch' ;
12
13
import type { PeritextEventDefaults } from '../../events/defaults/PeritextEventDefaults' ;
13
14
import type { PeritextEventTarget } from '../../events/PeritextEventTarget' ;
14
15
import type { Rect , UiLifeCycles } from '../types' ;
15
16
import type { Log } from '../../../json-crdt/log/Log' ;
16
- import type { Inline } from '../../../json-crdt-extensions' ;
17
+ import type { Inline , Peritext } from '../../../json-crdt-extensions' ;
17
18
import type { Range } from '../../../json-crdt-extensions/peritext/rga/Range' ;
18
19
import type { PeritextUiApi } from '../../events/defaults/ui/types' ;
19
20
@@ -24,17 +25,20 @@ export interface DomControllerOpts {
24
25
}
25
26
26
27
export class DomController implements UiLifeCycles , Printable , PeritextUiApi {
28
+ public readonly txt : Peritext ;
27
29
public readonly et : PeritextEventTarget ;
28
30
public readonly keys : KeyController ;
29
31
public readonly comp : CompositionController ;
30
32
public readonly input : InputController ;
31
33
public readonly cursor : CursorController ;
32
34
public readonly richText : RichTextController ;
33
35
public readonly annals : AnnalsController ;
36
+ public readonly boundaries = new AvlMap < ITimestampStruct , Element > ( compare ) ;
34
37
35
38
constructor ( public readonly opts : DomControllerOpts ) {
36
39
const { source, events, log} = opts ;
37
40
const { txt} = events ;
41
+ this . txt = txt ;
38
42
const et = ( this . et = opts . events . et ) ;
39
43
const keys = ( this . keys = new KeyController ( { source} ) ) ;
40
44
const comp = ( this . comp = new CompositionController ( { et, source, txt} ) ) ;
@@ -77,6 +81,12 @@ export class DomController implements UiLifeCycles, Printable, PeritextUiApi {
77
81
}
78
82
79
83
protected findSpanContaining ( range : Range ) : [ span : HTMLSpanElement , inline : Inline ] | undefined {
84
+ const start = range . start ;
85
+ const marker = this . txt . overlay . getOrNextLowerMarker ( start ) ;
86
+ const markerId = marker ?. id ;
87
+ const el = this . boundaries . get ( markerId ) ;
88
+ // console.log('markerId', markerId);
89
+
80
90
const spans = this . getSpans ( ) ;
81
91
const length = spans . length ;
82
92
for ( let i = 0 ; i < length ; i ++ ) {
0 commit comments