Skip to content

Commit

Permalink
+1
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Jan 4, 2025
1 parent cfbd96c commit 1fb0405
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions dom/point/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ namespace $ {
tail() {
return $mol_dom_point.tail( this.node )
}

native() {
if( this.is_tail() ) return [
this.node.parentNode!,
[ ... this.node.parentNode!.childNodes ].indexOf( this.node as ChildNode ),
] as const
return [ this.node, this.pos ] as const
}

/** Point near the node. -1: before, +1: after. */
static near( node: Node, axis: -1 | 1 ) {
Expand Down
18 changes: 13 additions & 5 deletions dom/range/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@ namespace $ {
}

point_compare( point: $mol_dom_point ) {
if( point.is_tail() ) return this.native().comparePoint(
point.node.parentNode!,
[ ... point.node.parentNode!.childNodes ].indexOf( point.node as ChildNode ),
)
else return this.native().comparePoint( point.node, point.pos )
return this.native().comparePoint( ... point.native() )
}

point_bound( point: $mol_dom_point ) {
const zone = this.point_compare( point )
return zone < 0 ? this.anchor : zone > 0 ? this.extend : point
}

range_contains( range: $mol_dom_range ) {
return ( this.point_compare( range.anchor ) === 0 )&&( this.point_compare( range.extend ) === 0 )
}

range_bounds( range: $mol_dom_range ) {
return new $mol_dom_range(
this.point_bound( range.anchor ),
this.point_bound( range.extend ),
)
}

select() {
const sel = $mol_dom_context.document.getSelection()!
sel.removeAllRanges()
Expand Down

0 comments on commit 1fb0405

Please sign in to comment.