@@ -9,25 +9,39 @@ export default () => {
99 return new Plugin ( {
1010 props : {
1111 decorations : ( state ) => {
12+ const counts = new Map < string , number > ( ) ;
1213 const decorations : Decoration [ ] = [ ] ;
1314 state . doc . descendants ( ( node , pos ) => {
14- if (
15- node . type . name === "table_row" ||
16- node . type . name === "table_cell" ||
17- node . type . name === "table_header"
18- ) {
19- // Don't add decorations to table rows or cells
15+ let nodeIsDescendantOfTable = false ;
16+ state . doc . nodesBetween ( pos , pos , ( node ) => {
17+ if (
18+ node . type . name === "table" ||
19+ node . type . name === "table_row" ||
20+ node . type . name === "table_cell" ||
21+ node . type . name === "table_header"
22+ ) {
23+ nodeIsDescendantOfTable = true ;
24+ }
25+ } ) ;
26+ if ( nodeIsDescendantOfTable ) {
2027 return ;
2128 }
29+ const count = counts . get ( node . type . name ) || 0 ;
30+ counts . set ( node . type . name , count + 1 ) ;
2231 if ( node . type . isBlock ) {
23- // TODO: is there a better key we can use?
24- decorations . push ( widget ( pos , BlockDecoration , { key : `node-${ pos } ` } ) ) ;
32+ decorations . push (
33+ widget ( pos , BlockDecoration , {
34+ key : `node-${ node . type . name } -${ count } ` ,
35+ } )
36+ ) ;
2537 } else {
26- const hasMarks = ! ! node . marks . length ;
27- const isMath = node . type . name === "math_inline" ;
28- if ( hasMarks || isMath ) {
29- /* If it's an inline node with marks OR is inline math */
30- decorations . push ( widget ( pos , InlineDecoration , { key : `mark-${ pos } ` } ) ) ;
38+ // If it's an inline node with marks OR is inline math
39+ if ( node . marks . length > 0 || node . type . name === "math_inline" ) {
40+ decorations . push (
41+ widget ( pos , InlineDecoration , {
42+ key : `mark-${ node . type . name } -${ count } ` ,
43+ } )
44+ ) ;
3145 }
3246 }
3347 } ) ;
0 commit comments