Skip to content

Commit e273ee1

Browse files
committed
Fixed a bug where the last offset would not be applied correctly.
1 parent e32c0ce commit e273ee1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

source/jquery.syntax.core.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,35 @@ Syntax.convertTabsToSpaces = function (text, tabSize) {
114114
return {text: text, offsets: offsets};
115115
};
116116

117+
// This function converts from a compressed set of offsets of the form:
118+
// [
119+
// [offset, width, totalOffset],
120+
// ...
121+
// ]
122+
// This means that at a $offset, a tab (single character) was expanded to $width
123+
// single space characters.
124+
// This function produces a lookup table of offsets, where a given character offset
125+
// is mapped to how far the character has been offset.
117126
Syntax.convertToLinearOffsets = function (offsets, length) {
118127
var current = 0, changes = [];
119128

120129
// Anything with offset after offset[current][0] but smaller than offset[current+1][0]
121130
// has been shifted right by offset[current][2]
122131
for (var i = 0; i < length; i++) {
123132
if (offsets[current] && i > offsets[current][0]) {
124-
if (offsets[current+1] && i <= offsets[current+1][0]) {
125-
changes.push(offsets[current][2]);
133+
// Is there a next offset?
134+
if (offsets[current+1]) {
135+
// Is the index less than the start of the next offset?
136+
if (i <= offsets[current+1][0]) {
137+
changes.push(offsets[current][2]);
138+
} else {
139+
// If so, move to the next offset.
140+
current += 1;
141+
i -= 1;
142+
}
126143
} else {
127-
current += 1;
128-
i -= 1;
144+
// If there is no next offset we assume this one to the end.
145+
changes.push(offsets[current][2]);
129146
}
130147
} else {
131148
changes.push(changes[changes.length-1] || 0);

0 commit comments

Comments
 (0)