This repository was archived by the owner on May 5, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
packages/plugin-dom-layout/src Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -122,9 +122,7 @@ export class DomLayoutEngine extends LayoutEngine {
122
122
this . _currentlyRedrawing = true ;
123
123
124
124
if ( nodes ) {
125
- nodes = nodes . filter ( node => {
126
- return node . ancestors ( ) . pop ( ) === this . root ;
127
- } ) ;
125
+ nodes = this . _filterNodeInRoot ( nodes ) ;
128
126
} else {
129
127
nodes = [ ] ;
130
128
// Redraw all.
@@ -221,6 +219,26 @@ export class DomLayoutEngine extends LayoutEngine {
221
219
// Private
222
220
//--------------------------------------------------------------------------
223
221
222
+ private _filterNodeInRoot ( nodes : VNode [ ] ) : VNode [ ] {
223
+ const ancestorInRoot = new Set < VNode > ( ) ;
224
+ const nodesToKeep : VNode [ ] = [ ] ;
225
+ for ( const node of nodes ) {
226
+ const parents : VNode [ ] = [ ] ;
227
+ let ancestor = node . parent ;
228
+ while ( ancestor ) {
229
+ if ( ancestor === this . root || ancestorInRoot . has ( ancestor ) ) {
230
+ nodesToKeep . push ( node ) ;
231
+ for ( const parent of parents ) {
232
+ ancestorInRoot . add ( parent ) ;
233
+ }
234
+ break ;
235
+ }
236
+ parents . push ( ancestor ) ;
237
+ ancestor = ancestor . parent ;
238
+ }
239
+ }
240
+ return nodesToKeep ;
241
+ }
224
242
/**
225
243
* Render the given VSelection as a DOM selection in the given target.
226
244
*
You can’t perform that action at this time.
0 commit comments