Skip to content

Commit a374993

Browse files
peterflynnAJDBenner
authored andcommitted
- Fix bug: pressing Enter to close Quick Open or Goto Line inserted newline
in editor (new, cmv4-only issue) - Fix bug: clicking Ctrl+T item without typing any text didn't work - Fix bug: pressing Enter to finish Goto Line didn't set cursor pos - Clean up docs, remove some TODOs - Remove unused keyup listener code (jQuery was silently no-oping when asked to attach a null event handler) - Simplify "@" detection in the three core Ctrl+T providers
1 parent 1f5d825 commit a374993

5 files changed

Lines changed: 32 additions & 49 deletions

File tree

src/extensions/default/QuickOpenCSS/main.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ define(function (require, exports, module) {
8484
* @param {boolean} returns true if this plugin wants to provide results for this query
8585
*/
8686
function match(query) {
87-
// TODO: match any location of @ when QuickOpen._handleItemFocus() is modified to
88-
// dynamic open files
89-
//if (query.indexOf("@") !== -1) {
90-
if (query.indexOf("@") === 0) {
87+
if (query[0] === "@") {
9188
return true;
9289
}
9390
}
@@ -97,8 +94,8 @@ define(function (require, exports, module) {
9794
* in which case the topmost list item is irrelevant)
9895
* @param {?SearchResult} selectedItem
9996
*/
100-
function itemFocus(selectedItem, query) {
101-
if (!selectedItem || query.length < 2) {
97+
function itemFocus(selectedItem, query, force) {
98+
if (!selectedItem || (query.length < 2 && !force)) {
10299
return;
103100
}
104101
var selectorInfo = selectedItem.selectorInfo;
@@ -109,7 +106,7 @@ define(function (require, exports, module) {
109106
}
110107

111108
function itemSelect(selectedItem, query) {
112-
itemFocus(selectedItem, query);
109+
itemFocus(selectedItem, query, true);
113110
}
114111

115112

src/extensions/default/QuickOpenHTML/main.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ define(function (require, exports, module) {
118118
* @param {boolean} returns true if this plug-in wants to provide results for this query
119119
*/
120120
function match(query) {
121-
// TODO: match any location of @ when QuickOpen._handleItemFocus() is modified to
122-
// dynamic open files
123-
//if (query.indexOf("@") !== -1) {
124-
if (query.indexOf("@") === 0) {
121+
if (query[0] === "@") {
125122
return true;
126123
}
127124
}
@@ -132,8 +129,8 @@ define(function (require, exports, module) {
132129
* in which case the topmost list item is irrelevant)
133130
* @param {?SearchResult} selectedItem
134131
*/
135-
function itemFocus(selectedItem, query) {
136-
if (!selectedItem || query.length < 2) {
132+
function itemFocus(selectedItem, query, force) {
133+
if (!selectedItem || (query.length < 2 && !force)) {
137134
return;
138135
}
139136
var fileLocation = selectedItem.fileLocation;
@@ -144,7 +141,7 @@ define(function (require, exports, module) {
144141
}
145142

146143
function itemSelect(selectedItem, query) {
147-
itemFocus(selectedItem, query);
144+
itemFocus(selectedItem, query, true);
148145
}
149146

150147

src/extensions/default/QuickOpenJavaScript/main.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ define(function (require, exports, module) {
112112
*/
113113
function match(query) {
114114
// only match @ at beginning of query for now
115-
// TODO: match any location of @ when QuickOpen._handleItemFocus() is modified to
116-
// dynamic open files
117-
//if (query.indexOf("@") !== -1) {
118-
if (query.indexOf("@") === 0) {
115+
if (query[0] === "@") {
119116
return true;
120117
}
121118
}
@@ -125,8 +122,8 @@ define(function (require, exports, module) {
125122
* in which case the topmost list item is irrelevant)
126123
* @param {?SearchResult} selectedItem
127124
*/
128-
function itemFocus(selectedItem, query) {
129-
if (!selectedItem || query.length < 2) {
125+
function itemFocus(selectedItem, query, force) {
126+
if (!selectedItem || (query.length < 2 && !force)) {
130127
return;
131128
}
132129
var fileLocation = selectedItem.fileLocation;
@@ -137,7 +134,7 @@ define(function (require, exports, module) {
137134
}
138135

139136
function itemSelect(selectedItem, query) {
140-
itemFocus(selectedItem, query);
137+
itemFocus(selectedItem, query, true);
141138
}
142139

143140

src/search/QuickOpen.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,16 @@ define(function (require, exports, module) {
292292
if (currentPlugin) {
293293
currentPlugin.itemSelect(selectedItem, query);
294294
} else {
295-
// extract line number, if any
295+
// Extract line/col number, if any
296296
var cursorPos = extractCursorPos(query);
297297

298298
// Navigate to file and line number
299299
var fullPath = selectedItem && selectedItem.fullPath;
300300
if (fullPath) {
301-
// This case is tricky. We want to switch editors, so we need to deal with
302-
// resizing/rescrolling the current editor first. But we don't actually want
303-
// to start the animation of the ModalBar until afterward (otherwise it glitches
304-
// because it gets starved of cycles during the creation of the new editor).
305-
// So we call `prepareClose()` first, and finish the close later.
306-
// FIXME: what about this case??
301+
// We need to fix up the current editor's scroll pos before switching to the next one. But if
302+
// we run the full close() now, ModalBar's animate-out won't be smooth (gets starved of cycles
303+
// during creation of the new editor). So we call prepareClose() to do *only* the scroll pos
304+
// fixup, and let the full close() be triggered later when the new editor takes focus.
307305
doClose = false;
308306
this.modalBar.prepareClose();
309307
CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: fullPath})
@@ -312,9 +310,6 @@ define(function (require, exports, module) {
312310
var editor = EditorManager.getCurrentFullEditor();
313311
editor.setCursorPos(cursorPos.line, cursorPos.ch, true);
314312
}
315-
})
316-
.always(function () {
317-
self.close();
318313
});
319314
} else if (cursorPos) {
320315
EditorManager.getCurrentFullEditor().setCursorPos(cursorPos.line, cursorPos.ch, true);
@@ -338,13 +333,13 @@ define(function (require, exports, module) {
338333
};
339334

340335
/**
341-
* Make sure ModalBar doesn't restore the scroll pos in cases where we're doing our own restoring instead.
336+
* Make sure ModalBar doesn't touch the scroll pos in cases where we're doing our own restoring instead.
342337
*/
343338
QuickNavigateDialog.prototype._handleBeforeClose = function (reason) {
344339
console.log("QuickOpen._handleBeforeClose()", this.isOpen, this.closePromise, reason);
345340
if (reason === ModalBar.CLOSE_ESCAPE) {
346-
// Don't actually restore scroll pos yet though: wait for _handleCloseBar() when the editor has
347-
// been resized back to its original height, matching the state it was in when we saved the pos.
341+
// Don't let ModalBar adjust scroll pos: we're going to revert it to its original pos. (In _handleCloseBar(),
342+
// when the editor has been resized back to its original height, matching state when we saved the pos)
348343
return { restoreScrollPos: false };
349344
}
350345
};
@@ -378,13 +373,13 @@ define(function (require, exports, module) {
378373
}
379374
}
380375

381-
// Close popup & ensure we avoid any still-pending result promises
376+
// Close popup & ensure we ignore any still-pending result promises
382377
this.searchField.destroy();
383378

384379
// Restore original selection / scroll pos if closed via Escape
385380
if (reason === ModalBar.CLOSE_ESCAPE) {
386381
console.log("QO restoring pos");
387-
// We reset the scroll position synchronously on the ModalBar "close" event (before the animation
382+
// We can reset the scroll position synchronously on the ModalBar "close" event (before the animation
388383
// completes) since the editor has already been resized at this point.
389384
var editor = EditorManager.getCurrentFullEditor();
390385
if (this._origSelection) {
@@ -617,7 +612,7 @@ define(function (require, exports, module) {
617612
initialString = initialString || "";
618613
initialString = prefix + initialString;
619614

620-
this.searchField.setText(initialString, true);
615+
this.searchField.setText(initialString);
621616

622617
// Select just the text after the prefix
623618
this.$searchField[0].setSelectionRange(prefix.length, initialString.length);
@@ -680,11 +675,10 @@ define(function (require, exports, module) {
680675
$(this.modalBar).on("close", this._handleCloseBar);
681676

682677
this.$searchField = $("input#quickOpenSearch");
683-
this.$searchField.keyup(this._handleKeyUp);
684678

685679
this.searchField = new QuickSearchField(this.$searchField, {
686680
maxResults: 20,
687-
verticalAdjust: this.modalBar.getRoot().outerHeight(), // FIXME: hide popup until animation done! (setExtraDropdownCSS()?)
681+
verticalAdjust: this.modalBar.getRoot().outerHeight(),
688682
resultProvider: this._filterCallback,
689683
formatter: this._resultsFormatterCallback,
690684
onCommit: this._handleItemSelect,

src/search/QuickSearchField.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
* And the text field is:
3838
* input
3939
* input.no-results
40-
*
41-
* BUGS to verify:
42-
* #1855, #1384
4340
*/
4441
define(function (require, exports, module) {
4542
"use strict";
@@ -60,10 +57,11 @@ define(function (require, exports, module) {
6057
*
6158
* @param {!function(*, string):string} options.formatter
6259
* Converts one result object to a string of HTML text. Passed the item and the current query.
63-
* @param {!function(*, string):void} options.onCommit
60+
* @param {!function(?*, string):void} options.onCommit
6461
* Called when an item is selected by clicking or pressing Enter. Passed the item and the current
6562
* query. If the current result list is not up to date with the query text at the time Enter is
66-
* pressed, waits until it is before running this callback. The popup remains open after this event.
63+
* pressed, waits until it is before running this callback. If Enter pressed with no results, passed
64+
* null. The popup remains open after this event.
6765
* @param {!function(*, string):void} options.onHighlight
6866
* Called when an item is highlighted via the arrow keys. Passed the item and the current query.
6967
* Always called once with the top item in the result list, each time the list is updated (because
@@ -132,6 +130,7 @@ define(function (require, exports, module) {
132130
QuickSearchField.prototype._handleKeyDown = function (event) {
133131
if (event.keyCode === KeyEvent.DOM_VK_RETURN) {
134132
if (this._displayedQuery === this.$input.val()) {
133+
event.preventDefault(); // prevents keyup from going to someone else after we close
135134
this._doCommit();
136135
} else {
137136
// Once the current wait resolves, _render() will run the commit
@@ -163,10 +162,12 @@ define(function (require, exports, module) {
163162
}
164163
};
165164
QuickSearchField.prototype._doCommit = function (clickedIndex) {
165+
var item;
166166
if (this._displayedResults && this._displayedResults.length) {
167167
var committedIndex = clickedIndex !== undefined ? clickedIndex : (this._highlightIndex || 0);
168-
this.options.onCommit(this._displayedResults[committedIndex], this._displayedQuery);
168+
item = this._displayedResults[committedIndex];
169169
}
170+
this.options.onCommit(item, this._displayedQuery);
170171
};
171172
QuickSearchField.prototype._updateHighlight = function () {
172173
var $items = this._$dropdown.find("li");
@@ -233,8 +234,6 @@ define(function (require, exports, module) {
233234
}
234235
this._$dropdown.html(htmlContent);
235236
};
236-
// QuickSearchField.prototype._setExtraDropdownCSS = function (cssProps) {
237-
// };
238237

239238
QuickSearchField.prototype._render = function (results, query) {
240239
this._displayedQuery = query;
@@ -275,11 +274,10 @@ define(function (require, exports, module) {
275274

276275
/**
277276
* Programmatically changes the search text and updates the results.
278-
* FIXME: is this needed if we listen for "input" events?
279277
*/
280278
QuickSearchField.prototype.setText = function (value) {
281279
this.$input.val(value);
282-
this.updateResults();
280+
this.updateResults(); // programmatic changes don't trigger "input" event
283281
};
284282

285283
/**

0 commit comments

Comments
 (0)