Skip to content

Commit

Permalink
dom partial reconcile on edit
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Jan 8, 2025
1 parent 588561b commit 086ffa9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions dom/edit/edit.view.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
flex-direction: column;
border-radius: var(--mol_gap_round);
flex: 1;
white-space: pre-wrap;
}

[hyoo_crus_dom_edit][contenteditable="true"] {
Expand Down
1 change: 1 addition & 0 deletions dom/edit/edit.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $hyoo_crus_dom_edit $mol_view
enabled true
hint \
auto /
<= setup null
<= selection_load null
<= selection_sync null
plugins /
Expand Down
22 changes: 19 additions & 3 deletions dom/edit/edit.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace $.$$ {
return this.enabled() ? 'true' : 'false'
}

@ $mol_mem
setup() {
// $mol_dom.document.execCommand( 'defaultParagraphSeparator', false, 'p' )
}

@ $mol_mem
sub() {
console.log('render')
Expand All @@ -25,9 +30,20 @@ namespace $.$$ {
}

save() {
let nodes = [ ... this.dom_node().childNodes ]
nodes = this.$.$mol_dom_safe( nodes )
this.node().dom( nodes as Element[] )

const sel = $mol_dom_range.from_selection()
const root = this.dom_node()
if( !$mol_dom_range.inside( root ).range_contains( sel ) ) return

let container = sel.container() as Element
while( [ 'SPAN', '#text' ].includes( container.nodeName ) ) {
container = container.parentElement!
}

const dom = this.node().land().Node( $hyoo_crus_dom ).Item( container.id )
let nodes = [ ... container.childNodes ]
nodes = this.$.$mol_dom_safe( nodes as Element[] )
dom.dom( nodes as Element[] )
this.selection_save()
}

Expand Down

0 comments on commit 086ffa9

Please sign in to comment.