Bug 583816 - Tab should move to the page when there's nothing to complete in the Web Console r=sdwilsh a=dietrich

This commit is contained in:
Mihai Sucan 2010-10-11 14:37:23 -07:00
Родитель 161fca6c35
Коммит b7ac4108ef
3 изменённых файлов: 79 добавлений и 11 удалений

Просмотреть файл

@ -4286,20 +4286,19 @@ JSTerm.prototype = {
// If there are more than one possible completion, pressing tab // If there are more than one possible completion, pressing tab
// means taking the next completion, shift_tab means taking // means taking the next completion, shift_tab means taking
// the previous completion. // the previous completion.
var completionResult;
if (aEvent.shiftKey) { if (aEvent.shiftKey) {
self.complete(self.COMPLETE_BACKWARD); completionResult = self.complete(self.COMPLETE_BACKWARD);
} }
else { else {
self.complete(self.COMPLETE_FORWARD); completionResult = self.complete(self.COMPLETE_FORWARD);
} }
var bool = aEvent.cancelable; if (completionResult) {
if (bool) { if (aEvent.cancelable) {
aEvent.preventDefault(); aEvent.preventDefault();
} }
else {
// noop
}
aEvent.target.focus(); aEvent.target.focus();
}
break; break;
case 8: case 8:
// backspace key // backspace key
@ -4410,7 +4409,8 @@ JSTerm.prototype = {
* the inputNode.value is set to this value and the selection is set * the inputNode.value is set to this value and the selection is set
* from the current cursor position to the end of the completed text. * from the current cursor position to the end of the completed text.
* *
* @returns void * @returns boolean true if there existed a completion for the current input,
* or false otherwise.
*/ */
complete: function JSTF_complete(type) complete: function JSTF_complete(type)
{ {
@ -4418,7 +4418,7 @@ JSTerm.prototype = {
let inputValue = inputNode.value; let inputValue = inputNode.value;
// If the inputNode has no value, then don't try to complete on it. // If the inputNode has no value, then don't try to complete on it.
if (!inputValue) { if (!inputValue) {
return; return false;
} }
let selStart = inputNode.selectionStart, selEnd = inputNode.selectionEnd; let selStart = inputNode.selectionStart, selEnd = inputNode.selectionEnd;
@ -4432,7 +4432,7 @@ JSTerm.prototype = {
// Only complete if the selection is at the end of the input. // Only complete if the selection is at the end of the input.
if (selEnd != inputValue.length) { if (selEnd != inputValue.length) {
this.lastCompletion = null; this.lastCompletion = null;
return; return false;
} }
// Remove the selected text from the inputValue. // Remove the selected text from the inputValue.
@ -4460,7 +4460,7 @@ JSTerm.prototype = {
// Look up possible completion values. // Look up possible completion values.
let completion = this.propertyProvider(this.sandbox.window, inputValue); let completion = this.propertyProvider(this.sandbox.window, inputValue);
if (!completion) { if (!completion) {
return; return false;
} }
matches = completion.matches; matches = completion.matches;
matchIndexToUse = 0; matchIndexToUse = 0;
@ -4500,7 +4500,11 @@ JSTerm.prototype = {
else { else {
inputNode.setSelectionRange(selEnd, selEnd); inputNode.setSelectionRange(selEnd, selEnd);
} }
return completionStr ? true : false;
} }
return false;
} }
}; };

Просмотреть файл

@ -89,6 +89,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_582201_duplicate_errors.js \ browser_webconsole_bug_582201_duplicate_errors.js \
browser_webconsole_bug_580454_timestamp_l10n.js \ browser_webconsole_bug_580454_timestamp_l10n.js \
browser_webconsole_netlogging.js \ browser_webconsole_netlogging.js \
browser_webconsole_bug_583816_tab_focus.js \
head.js \ head.js \
$(NULL) $(NULL)

Просмотреть файл

@ -0,0 +1,63 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* Contributor(s):
* Mihai Șucan <mihai.sucan@gmail.com>
*
* ***** END LICENSE BLOCK ***** */
const TEST_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-console.html";
let inputNode;
function tabLoad(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
waitForFocus(function() {
openConsole();
let hudId = HUDService.getHudIdByWindow(content);
HUD = HUDService.hudWeakReferences[hudId].get();
let display = HUDService.getOutputNodeById(hudId);
inputNode = display.querySelector(".jsterm-input-node");
inputNode.focus();
executeSoon(function() {
is(inputNode.getAttribute("focused"), "true", "inputNode is focused");
HUD.jsterm.setInputValue("doc");
inputNode.addEventListener("keyup", firstTab, false);
EventUtils.synthesizeKey("VK_TAB", {});
});
}, content);
}
function firstTab(aEvent) {
this.removeEventListener(aEvent.type, arguments.callee, false);
is(inputNode.getAttribute("focused"), "true", "inputNode is still focused");
isnot(this.value, "doc", "input autocompleted");
HUD.jsterm.setInputValue("foobarbaz" + Date.now());
EventUtils.synthesizeKey("VK_TAB", {});
executeSoon(secondTab);
}
function secondTab() {
isnot(inputNode.getAttribute("focused"), "true",
"inputNode is no longer focused");
HUD = inputNode = null;
HUDService.deactivateHUDForContext(gBrowser.selectedTab);
executeSoon(finish);
}
function test() {
addTab(TEST_URI);
browser.addEventListener("load", tabLoad, true);
}