@@ -10,33 +10,34 @@ Syntax.Editor = function(container, text) {
10
10
// This function generates an array of accumulated line offsets e.g.
11
11
// If line 8 is actually in child element 6, indices[8] = -2
12
12
Syntax . Editor . prototype . getLines = function ( ) {
13
- var children = this . container . children , lines = [ ] , offsets = [ ] ;
13
+ var children = this . container . childNodes , lines = [ ] , offsets = [ ] ;
14
14
15
15
// Sometimes, e.g. when deleting text, children elements are not complete lines.
16
16
// We need to accumulate incomplete lines (1), and then append them to the
17
17
// start of the next complete line (2)
18
- var text = "" ;
18
+ var text = "" , startChild = 0 ;
19
19
for ( var i = 0 ; i < children . length ; i += 1 ) {
20
20
var childLines = Syntax . getCDATA ( [ children [ i ] ] ) . split ( '\n' ) ;
21
21
22
22
if ( childLines . length > 1 ) {
23
23
childLines [ 0 ] = text + childLines [ 0 ] ; // (2)
24
- text = "" ;
25
- childLines . pop ( ) ;
24
+ text = childLines . pop ( ) ;
26
25
} else {
27
26
text += childLines [ 0 ] ; // (1)
28
27
continue ;
29
28
}
30
29
31
30
for ( var j = 0 ; j < childLines . length ; j += 1 ) {
32
- offsets . push ( i - lines . length ) ;
31
+ offsets . push ( startChild - lines . length ) ;
33
32
lines . push ( childLines [ j ] ) ;
34
33
}
34
+
35
+ startChild = i + 1 ;
35
36
}
36
37
37
38
offsets . push ( offsets [ offsets . length - 1 ] ) ;
38
39
39
- Syntax . log ( offsets , lines , children ) ;
40
+ Syntax . log ( "getLines" , offsets , lines , children ) ;
40
41
41
42
return { lines : lines , offsets : offsets } ;
42
43
}
@@ -146,7 +147,7 @@ Syntax.Editor.prototype.updateLines = function(changed, newLines) {
146
147
147
148
Syntax . log ( "slice" , start , end )
148
149
149
- var oldLines = Array . prototype . slice . call ( this . container . children , start , end ) ;
150
+ var oldLines = Array . prototype . slice . call ( this . container . childNodes , start , end ) ;
150
151
151
152
Syntax . log ( "Replacing old lines" , oldLines , "with" , newLines ) ;
152
153
@@ -159,7 +160,7 @@ Syntax.Editor.prototype.updateLines = function(changed, newLines) {
159
160
160
161
start += this . current . offsets [ start ] ;
161
162
162
- $ ( this . container . children [ start ] ) . after ( newLines ) ;
163
+ $ ( this . container . childNodes [ start ] ) . after ( newLines ) ;
163
164
}
164
165
}
165
166
}
@@ -252,8 +253,6 @@ Syntax.layouts.editor = function(options, code/*, container*/) {
252
253
253
254
var text = editor . textForLines ( changed . start , changed . end ) ;
254
255
Syntax . log ( "textForLines" , changed . start , changed . end , text ) ;
255
- //Syntax.log("Updating lines from", changed.start, "to", changed.end, "original end", changed.originalEnd);
256
- //Syntax.log("Children length", editor.container.children.length, editor.lines.length);
257
256
258
257
if ( changed . start == changed . end ) {
259
258
editor . updateLines ( changed , [ ] ) ;
0 commit comments