-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix 2663: MultiRangeInlineEditor case #3819
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,26 +324,75 @@ define(function (require, exports, module) { | |
return false; | ||
} | ||
|
||
var contiguousCount = 0; | ||
|
||
// This function peeks back through the results to see how many contiguous | ||
// characters the user has typed. It's possbile that those characters will | ||
// cross the SpecialMatch/NormalMatch boundaries. In other words, it's | ||
// possible that we jumped ahead to the next special character to find a match | ||
// when in reality that was the next character. | ||
function _computeContiguousCount() { | ||
var count = 1; | ||
if (result.length === 1) { | ||
if (strCounter - 1 !== result[0].index) { | ||
count = 0; | ||
} | ||
return count; | ||
} | ||
|
||
var i = result.length - 1; | ||
var lastMatch = result[i].index; | ||
for (--i; i >= 0; i--) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This expression looks like it should be a complex emoticon of some sort. :) |
||
if (result[i].index !== lastMatch - 1) { | ||
break; | ||
} | ||
count++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (If there is indeed a bug here, that probably means it's worth adding a test case with more than 2 consecutive ambiguous matches.) |
||
} | ||
return count; | ||
} | ||
|
||
while (true) { | ||
|
||
// keep looping until we've either exhausted the query or the string | ||
while (queryCounter < query.length && strCounter < str.length && strCounter <= deadBranches[queryCounter]) { | ||
if (state === SPECIALS_MATCH) { | ||
if (!findMatchingSpecial()) { | ||
state = ANY_MATCH; | ||
} | ||
} | ||
|
||
if (state === ANY_MATCH) { | ||
// we look character by character for matches | ||
// If the user has already typed two characters in a row that match, | ||
// try to keep it going. | ||
if (contiguousCount > 1) { | ||
if (query[queryCounter] === str[strCounter]) { | ||
// got a match! record it, and switch back to searching specials | ||
contiguousCount++; | ||
queryCounter++; | ||
result.push(new NormalMatch(strCounter++)); | ||
state = SPECIALS_MATCH; | ||
if (specials.indexOf(strCounter) > -1) { | ||
result.push(new SpecialMatch(strCounter++)); | ||
} else { | ||
result.push(new NormalMatch(strCounter++)); | ||
} | ||
} else { | ||
// no match, keep looking | ||
strCounter++; | ||
contiguousCount = 0; | ||
} | ||
} | ||
|
||
if (contiguousCount < 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be a little clearer as |
||
if (state === SPECIALS_MATCH) { | ||
if (!findMatchingSpecial()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that there's an |
||
state = ANY_MATCH; | ||
} else { | ||
contiguousCount = _computeContiguousCount(); | ||
} | ||
} | ||
|
||
if (state === ANY_MATCH) { | ||
// we look character by character for matches | ||
if (query[queryCounter] === str[strCounter]) { | ||
// got a match! record it, and switch back to searching specials | ||
queryCounter++; | ||
result.push(new NormalMatch(strCounter++)); | ||
state = SPECIALS_MATCH; | ||
contiguousCount = _computeContiguousCount(); | ||
} else { | ||
// no match, keep looking | ||
strCounter++; | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need to check for this in the case where
result.length > 1
? It seems like the code below that handles that case will return a contiguous count even if the contiguous matches are all further back in the string from where we're currently matching.I guess another way to put it is, why isn't this whole function just something like: