Skip to content

Commit 26ec705

Browse files
committed
Improved editing accuracy in Firefox.
1 parent 5aac5f2 commit 26ec705

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

source/jquery.syntax.layout.editor.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@ Syntax.Editor = function(container, text) {
1010
// This function generates an array of accumulated line offsets e.g.
1111
// If line 8 is actually in child element 6, indices[8] = -2
1212
Syntax.Editor.prototype.getLines = function() {
13-
var children = this.container.children, lines = [], offsets = [];
13+
var children = this.container.childNodes, lines = [], offsets = [];
1414

1515
// Sometimes, e.g. when deleting text, children elements are not complete lines.
1616
// We need to accumulate incomplete lines (1), and then append them to the
1717
// start of the next complete line (2)
18-
var text = "";
18+
var text = "", startChild = 0;
1919
for (var i = 0; i < children.length; i += 1) {
2020
var childLines = Syntax.getCDATA([children[i]]).split('\n');
2121

2222
if (childLines.length > 1) {
2323
childLines[0] = text + childLines[0]; // (2)
24-
text = "";
25-
childLines.pop();
24+
text = childLines.pop();
2625
} else {
2726
text += childLines[0]; // (1)
2827
continue;
2928
}
3029

3130
for (var j = 0; j < childLines.length; j += 1) {
32-
offsets.push(i - lines.length);
31+
offsets.push(startChild - lines.length);
3332
lines.push(childLines[j]);
3433
}
34+
35+
startChild = i + 1;
3536
}
3637

3738
offsets.push(offsets[offsets.length-1]);
3839

39-
Syntax.log(offsets, lines, children);
40+
Syntax.log("getLines", offsets, lines, children);
4041

4142
return {lines: lines, offsets: offsets};
4243
}
@@ -146,7 +147,7 @@ Syntax.Editor.prototype.updateLines = function(changed, newLines) {
146147

147148
Syntax.log("slice", start, end)
148149

149-
var oldLines = Array.prototype.slice.call(this.container.children, start, end);
150+
var oldLines = Array.prototype.slice.call(this.container.childNodes, start, end);
150151

151152
Syntax.log("Replacing old lines", oldLines, "with", newLines);
152153

@@ -159,7 +160,7 @@ Syntax.Editor.prototype.updateLines = function(changed, newLines) {
159160

160161
start += this.current.offsets[start];
161162

162-
$(this.container.children[start]).after(newLines);
163+
$(this.container.childNodes[start]).after(newLines);
163164
}
164165
}
165166
}
@@ -252,8 +253,6 @@ Syntax.layouts.editor = function(options, code/*, container*/) {
252253

253254
var text = editor.textForLines(changed.start, changed.end);
254255
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);
257256

258257
if (changed.start == changed.end) {
259258
editor.updateLines(changed, []);

0 commit comments

Comments
 (0)