1- import { deepEqual } from '@/js/util' ;
21import { CodeMirror } from '@/cm' ;
2+ import { deepEqual } from '@/js/util' ;
33import { trimCommentLabel } from './util' ;
44
55export default function MozSectionFinder ( cm ) {
@@ -17,6 +17,12 @@ export default function MozSectionFinder(cm) {
1717 const minPos = ( a , b ) => cmpPos ( a , b ) < 0 ? a : b ;
1818 const maxPos = ( a , b ) => cmpPos ( a , b ) > 0 ? a : b ;
1919 const keptAlive = new Map ( ) ;
20+ const state = /** @namespace MozSectionCmState */ {
21+ /** @type {Set<function> } */
22+ listeners : new Set ( ) ,
23+ /** @type {MozSection[] } */
24+ sections : [ ] ,
25+ } ;
2026 /** @type {CodeMirror.Pos } */
2127 let updFrom ;
2228 /** @type {CodeMirror.Pos } */
@@ -32,9 +38,7 @@ export default function MozSectionFinder(cm) {
3238 'valueEnd' ,
3339 'sticky' , // added by TextMarker::find()
3440 ] ,
35- get sections ( ) {
36- return getState ( ) . sections ;
37- } ,
41+ sections : state . sections ,
3842 keepAliveFor ( id , ms ) {
3943 let data = keptAlive . get ( id ) ;
4044 if ( data ) {
@@ -49,7 +53,7 @@ export default function MozSectionFinder(cm) {
4953 } ,
5054
5155 on ( fn ) {
52- const { listeners} = getState ( ) ;
56+ const { listeners} = state ;
5357 const needsInit = ! listeners . size ;
5458 listeners . add ( fn ) ;
5559 if ( needsInit ) {
@@ -59,7 +63,7 @@ export default function MozSectionFinder(cm) {
5963 } ,
6064
6165 off ( fn ) {
62- const { listeners, sections} = getState ( ) ;
66+ const { listeners, sections} = state ;
6367 if ( listeners . size ) {
6468 listeners . delete ( fn ) ;
6569 if ( ! listeners . size ) {
@@ -76,24 +80,10 @@ export default function MozSectionFinder(cm) {
7680
7781 /** @param {MozSection } [section] */
7882 updatePositions ( section ) {
79- ( section ? [ section ] : getState ( ) . sections ) . forEach ( setPositionFromMark ) ;
83+ ( section ? [ section ] : state . sections ) . forEach ( setPositionFromMark ) ;
8084 } ,
8185 } ;
8286
83- /** @returns {MozSectionCmState } */
84- function getState ( ) {
85- let state = cm . state [ KEY ] ;
86- if ( ! state ) {
87- state = cm . state [ KEY ] = /** @namespace MozSectionCmState */ {
88- /** @type {Set<function> } */
89- listeners : new Set ( ) ,
90- /** @type {MozSection[] } */
91- sections : [ ] ,
92- } ;
93- }
94- return state ;
95- }
96-
9787 function onCmChanges ( _cm , changes ) {
9888 if ( ! updFrom ) updFrom = { line : Infinity , ch : 0 } ;
9989 if ( ! updTo ) updTo = { line : - 1 , ch : 0 } ;
@@ -109,7 +99,7 @@ export default function MozSectionFinder(cm) {
10999 }
110100
111101 function update ( ) {
112- const { sections, listeners} = getState ( ) ;
102+ const { sections, listeners} = state ;
113103 // Cloning to avoid breaking the internals of CodeMirror
114104 let from = updFrom ? { line : updFrom . line , ch : updFrom . ch } : { line : 0 , ch : 0 } ;
115105 let to = updTo ? { line : updTo . line , ch : updTo . ch } : { line : cm . doc . size , ch : 0 } ;
0 commit comments