update tests for word highlighting happening on timeout

This commit is contained in:
nightwing 2012-05-04 19:44:44 +04:00
commit 3e6d6563f1
2 changed files with 23 additions and 3 deletions

View file

@ -896,10 +896,15 @@ var Editor = function(renderer, session) {
return; return;
this.$highlightSelectedWord = shouldHighlight; this.$highlightSelectedWord = shouldHighlight;
if (shouldHighlight) if (shouldHighlight) {
this.session.getMode().highlightSelection(this); this.session.getMode().highlightSelection(this);
else } else {
this.session.getMode().clearSelectionHighlight(this); this.session.getMode().clearSelectionHighlight(this);
if (this.$wordHighlightTimer) {
clearTimeout(this.$wordHighlightTimer);
this.$wordHighlightTimer = null;
}
}
}; };
/** /**

View file

@ -87,6 +87,9 @@ module.exports = {
this.editor.moveCursorTo(0, 9); this.editor.moveCursorTo(0, 9);
this.selection.selectWord(); this.selection.selectWord();
assert.ok(this.editor.$wordHighlightTimer != null);
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "ipsum"); assert.equal(this.session.getTextRange(range), "ipsum");
assert.equal(this.session.$selectionOccurrences.length, 1); assert.equal(this.session.$selectionOccurrences.length, 1);
@ -95,6 +98,7 @@ module.exports = {
"test: highlight a word and clear highlight": function() { "test: highlight a word and clear highlight": function() {
this.editor.moveCursorTo(0, 8); this.editor.moveCursorTo(0, 8);
this.selection.selectWord(); this.selection.selectWord();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "ipsum"); assert.equal(this.session.getTextRange(range), "ipsum");
@ -107,6 +111,7 @@ module.exports = {
"test: highlight another word": function() { "test: highlight another word": function() {
this.selection.moveCursorTo(0, 14); this.selection.moveCursorTo(0, 14);
this.selection.selectWord(); this.selection.selectWord();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolor"); assert.equal(this.session.getTextRange(range), "dolor");
@ -115,13 +120,18 @@ module.exports = {
"test: no selection, no highlight": function() { "test: no selection, no highlight": function() {
this.selection.clearSelection(); this.selection.clearSelection();
this.session.$mode.highlightSelection(this.editor);
assert.equal(this.session.$selectionOccurrences.length, 0); assert.equal(this.session.$selectionOccurrences.length, 0);
}, },
"test: select a word, no highlight": function() { "test: select a word, no highlight": function() {
this.editor.setHighlightSelectedWord(false);
this.selection.moveCursorTo(0, 14); this.selection.moveCursorTo(0, 14);
this.selection.selectWord(); this.selection.selectWord();
this.session.$mode.highlightSelection(this.editor);
this.editor.setHighlightSelectedWord(false);
assert.ok(this.editor.$wordHighlightTimer == null);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolor"); assert.equal(this.session.getTextRange(range), "dolor");
@ -146,6 +156,7 @@ module.exports = {
this.search.set(currentOptions); this.search.set(currentOptions);
this.selection.setSelectionRange(match); this.selection.setSelectionRange(match);
this.session.$mode.highlightSelection(this.editor);
assert.equal(this.session.getTextRange(match), "Mauris"); assert.equal(this.session.getTextRange(match), "Mauris");
assert.equal(this.session.$selectionOccurrences.length, 0); assert.equal(this.session.$selectionOccurrences.length, 0);
@ -155,6 +166,7 @@ module.exports = {
this.selection.moveCursorTo(0, 14); this.selection.moveCursorTo(0, 14);
this.selection.selectWord(); this.selection.selectWord();
this.selection.selectLeft(); this.selection.selectLeft();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolo"); assert.equal(this.session.getTextRange(range), "dolo");
@ -165,6 +177,7 @@ module.exports = {
this.selection.moveCursorTo(0, 13); this.selection.moveCursorTo(0, 13);
this.selection.selectWord(); this.selection.selectWord();
this.selection.selectRight(); this.selection.selectRight();
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "dolor "); assert.equal(this.session.getTextRange(range), "dolor ");
@ -176,6 +189,7 @@ module.exports = {
this.selection.selectWord(); this.selection.selectWord();
this.selection.selectLeft(); this.selection.selectLeft();
this.selection.shiftSelection(1); this.selection.shiftSelection(1);
this.session.$mode.highlightSelection(this.editor);
var range = this.selection.getRange(); var range = this.selection.getRange();
assert.equal(this.session.getTextRange(range), "olor"); assert.equal(this.session.getTextRange(range), "olor");
@ -202,6 +216,7 @@ module.exports = {
this.search.set(currentOptions); this.search.set(currentOptions);
this.selection.setSelectionRange(match); this.selection.setSelectionRange(match);
this.session.$mode.highlightSelection(this.editor);
assert.equal(this.session.getTextRange(match), "consectetur"); assert.equal(this.session.getTextRange(match), "consectetur");
assert.equal(this.session.$selectionOccurrences.length, 2); assert.equal(this.session.$selectionOccurrences.length, 2);