@@ -15,19 +15,19 @@ import { signalLater } from "../util/operation_group"
15
15
//
16
16
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
17
17
18
- export class LeafChunk {
19
- constructor ( lines ) {
20
- this . lines = lines
21
- this . parent = null
22
- let height = 0
23
- for ( let i = 0 ; i < lines . length ; ++ i ) {
24
- lines [ i ] . parent = this
25
- height += lines [ i ] . height
26
- }
27
- this . height = height
18
+ export function LeafChunk ( lines ) {
19
+ this . lines = lines
20
+ this . parent = null
21
+ let height = 0
22
+ for ( let i = 0 ; i < lines . length ; ++ i ) {
23
+ lines [ i ] . parent = this
24
+ height += lines [ i ] . height
28
25
}
26
+ this . height = height
27
+ }
29
28
30
- chunkSize ( ) { return this . lines . length }
29
+ LeafChunk . prototype = {
30
+ chunkSize ( ) { return this . lines . length } ,
31
31
32
32
// Remove the n lines at offset 'at'.
33
33
removeInner ( at , n ) {
@@ -38,20 +38,20 @@ export class LeafChunk {
38
38
signalLater ( line , "delete" )
39
39
}
40
40
this . lines . splice ( at , n )
41
- }
41
+ } ,
42
42
43
43
// Helper used to collapse a small branch into a single leaf.
44
44
collapse ( lines ) {
45
45
lines . push . apply ( lines , this . lines )
46
- }
46
+ } ,
47
47
48
48
// Insert the given array of lines at offset 'at', count them as
49
49
// having the given height.
50
50
insertInner ( at , lines , height ) {
51
51
this . height += height
52
52
this . lines = this . lines . slice ( 0 , at ) . concat ( lines ) . concat ( this . lines . slice ( at ) )
53
53
for ( let i = 0 ; i < lines . length ; ++ i ) lines [ i ] . parent = this
54
- }
54
+ } ,
55
55
56
56
// Used to iterate over a part of the tree.
57
57
iterN ( at , n , op ) {
@@ -60,21 +60,21 @@ export class LeafChunk {
60
60
}
61
61
}
62
62
63
- export class BranchChunk {
64
- constructor ( children ) {
65
- this . children = children
66
- let size = 0 , height = 0
67
- for ( let i = 0 ; i < children . length ; ++ i ) {
68
- let ch = children [ i ]
69
- size += ch . chunkSize ( ) ; height += ch . height
70
- ch . parent = this
71
- }
72
- this . size = size
73
- this . height = height
74
- this . parent = null
63
+ export function BranchChunk ( children ) {
64
+ this . children = children
65
+ let size = 0 , height = 0
66
+ for ( let i = 0 ; i < children . length ; ++ i ) {
67
+ let ch = children [ i ]
68
+ size += ch . chunkSize ( ) ; height += ch . height
69
+ ch . parent = this
75
70
}
71
+ this . size = size
72
+ this . height = height
73
+ this . parent = null
74
+ }
76
75
77
- chunkSize ( ) { return this . size }
76
+ BranchChunk . prototype = {
77
+ chunkSize ( ) { return this . size } ,
78
78
79
79
removeInner ( at , n ) {
80
80
this . size -= n
@@ -98,11 +98,11 @@ export class BranchChunk {
98
98
this . children = [ new LeafChunk ( lines ) ]
99
99
this . children [ 0 ] . parent = this
100
100
}
101
- }
101
+ } ,
102
102
103
103
collapse ( lines ) {
104
104
for ( let i = 0 ; i < this . children . length ; ++ i ) this . children [ i ] . collapse ( lines )
105
- }
105
+ } ,
106
106
107
107
insertInner ( at , lines , height ) {
108
108
this . size += lines . length
@@ -128,7 +128,7 @@ export class BranchChunk {
128
128
}
129
129
at -= sz
130
130
}
131
- }
131
+ } ,
132
132
133
133
// When a node has grown, check whether it should be split.
134
134
maybeSpill ( ) {
@@ -151,7 +151,7 @@ export class BranchChunk {
151
151
sibling . parent = me . parent
152
152
} while ( me . children . length > 10 )
153
153
me . parent . maybeSpill ( )
154
- }
154
+ } ,
155
155
156
156
iterN ( at , n , op ) {
157
157
for ( let i = 0 ; i < this . children . length ; ++ i ) {
0 commit comments