зеркало из https://github.com/mozilla/gecko-dev.git
Bug 714942 - Implement minimal UI for Jump to line in the Source Editor. r=rcampbell
This commit is contained in:
Родитель
f2c52c371a
Коммит
1f22704ce5
|
@ -166,6 +166,10 @@
|
|||
command="cmd_findPrevious"
|
||||
modifiers="shift"/>
|
||||
#endif
|
||||
<key id="key_gotoLine"
|
||||
key="&gotoLineCmd.key;"
|
||||
command="cmd_gotoLine"
|
||||
modifiers="accel"/>
|
||||
</keyset>
|
||||
|
||||
|
||||
|
@ -258,6 +262,12 @@
|
|||
accesskey="&findAgainCmd.accesskey;"
|
||||
key="key_findAgain"
|
||||
command="cmd_findAgain"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="sp-menu-gotoLine"
|
||||
label="&gotoLineCmd.label;"
|
||||
accesskey="&gotoLineCmd.accesskey;"
|
||||
key="key_gotoLine"
|
||||
command="cmd_gotoLine"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
|
|
|
@ -58,11 +58,12 @@ _BROWSER_TEST_FILES = \
|
|||
browser_scratchpad_bug_679467_falsy.js \
|
||||
browser_scratchpad_bug_699130_edit_ui_updates.js \
|
||||
browser_scratchpad_bug_669612_unsaved.js \
|
||||
head.js \
|
||||
browser_scratchpad_bug_653427_confirm_close.js \
|
||||
browser_scratchpad_bug684546_reset_undo.js \
|
||||
browser_scratchpad_bug690552_display_outputs_errors.js \
|
||||
browser_scratchpad_bug650345_find_ui.js \
|
||||
browser_scratchpad_bug714942_goto_line_ui.js \
|
||||
head.js \
|
||||
|
||||
libs:: $(_BROWSER_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function test()
|
||||
{
|
||||
waitForExplicitFinish();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function browserLoad() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", browserLoad, true);
|
||||
openScratchpad(runTests);
|
||||
}, true);
|
||||
|
||||
content.location = "data:text/html,<p>test the 'Jump to line' feature in Scratchpad";
|
||||
}
|
||||
|
||||
function runTests(aWindow, aScratchpad)
|
||||
{
|
||||
let editor = aScratchpad.editor;
|
||||
let text = "foobar bug650345\nBug650345 bazbaz\nfoobar omg\ntest";
|
||||
editor.setText(text);
|
||||
editor.setCaretOffset(0);
|
||||
|
||||
let oldPrompt = Services.prompt;
|
||||
let desiredValue = null;
|
||||
Services.prompt = {
|
||||
prompt: function(aWindow, aTitle, aMessage, aValue) {
|
||||
aValue.value = desiredValue;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
desiredValue = 3;
|
||||
EventUtils.synthesizeKey("J", {accelKey: true}, aWindow);
|
||||
is(editor.getCaretOffset(), 34, "caret offset is correct");
|
||||
|
||||
desiredValue = 2;
|
||||
aWindow.goDoCommand("cmd_gotoLine")
|
||||
is(editor.getCaretOffset(), 17, "caret offset is correct (again)");
|
||||
|
||||
Services.prompt = oldPrompt;
|
||||
|
||||
finish();
|
||||
}
|
|
@ -292,6 +292,7 @@ SourceEditor.prototype = {
|
|||
"Find...": [this.ui.find, this.ui],
|
||||
"Find Next Occurrence": [this.ui.findNext, this.ui],
|
||||
"Find Previous Occurrence": [this.ui.findPrevious, this.ui],
|
||||
"Goto Line...": [this.ui.gotoLine, this.ui],
|
||||
};
|
||||
|
||||
for (let name in actions) {
|
||||
|
|
|
@ -42,5 +42,6 @@
|
|||
<command id="cmd_find" oncommand="goDoCommand('cmd_find')"/>
|
||||
<command id="cmd_findAgain" oncommand="goDoCommand('cmd_findAgain')" disabled="true"/>
|
||||
<command id="cmd_findPrevious" oncommand="goDoCommand('cmd_findPrevious')" disabled="true"/>
|
||||
<command id="cmd_gotoLine" oncommand="goDoCommand('cmd_gotoLine')"/>
|
||||
</commandset>
|
||||
</overlay>
|
||||
|
|
|
@ -75,6 +75,34 @@ SourceEditorUI.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The "go to line" command UI. This displays a prompt that allows the user to
|
||||
* input the line number to jump to.
|
||||
*/
|
||||
gotoLine: function SEU_gotoLine()
|
||||
{
|
||||
let oldLine = this.editor.getCaretPosition ?
|
||||
this.editor.getCaretPosition().line : null;
|
||||
let newLine = {value: oldLine !== null ? oldLine + 1 : ""};
|
||||
|
||||
let result = Services.prompt.prompt(this._ownerWindow,
|
||||
SourceEditorUI.strings.GetStringFromName("gotoLineCmd.promptTitle"),
|
||||
SourceEditorUI.strings.GetStringFromName("gotoLineCmd.promptMessage"),
|
||||
newLine, null, {});
|
||||
|
||||
newLine.value = parseInt(newLine.value);
|
||||
if (result && !isNaN(newLine.value) && --newLine.value != oldLine) {
|
||||
if (this.editor.getLineCount) {
|
||||
let lines = this.editor.getLineCount() - 1;
|
||||
this.editor.setCaretPosition(Math.max(0, Math.min(lines, newLine.value)));
|
||||
} else {
|
||||
this.editor.setCaretPosition(Math.max(0, newLine.value));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* The "find" command UI. This displays a prompt that allows the user to input
|
||||
* the string to search for in the code. By default the current selection is
|
||||
|
@ -191,6 +219,7 @@ SourceEditorController.prototype = {
|
|||
case "cmd_find":
|
||||
case "cmd_findAgain":
|
||||
case "cmd_findPrevious":
|
||||
case "cmd_gotoLine":
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
|
@ -215,6 +244,7 @@ SourceEditorController.prototype = {
|
|||
|
||||
switch (aCommand) {
|
||||
case "cmd_find":
|
||||
case "cmd_gotoLine":
|
||||
result = true;
|
||||
break;
|
||||
case "cmd_findAgain":
|
||||
|
@ -248,6 +278,9 @@ SourceEditorController.prototype = {
|
|||
case "cmd_findPrevious":
|
||||
this._editor.ui.findPrevious();
|
||||
break;
|
||||
case "cmd_gotoLine":
|
||||
this._editor.ui.gotoLine();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -83,6 +83,10 @@
|
|||
-->
|
||||
<!ENTITY findPreviousCmd.key "G">
|
||||
|
||||
<!ENTITY gotoLineCmd.label "Jump to line…">
|
||||
<!ENTITY gotoLineCmd.key "J">
|
||||
<!ENTITY gotoLineCmd.accesskey "J">
|
||||
|
||||
<!ENTITY run.label "Run">
|
||||
<!ENTITY run.accesskey "R">
|
||||
<!ENTITY run.key "r">
|
||||
|
|
|
@ -18,3 +18,13 @@ findCmd.promptTitle=Find…
|
|||
# the user wants to search for a string in the code. You can
|
||||
# access this feature by pressing Ctrl-F on Windows/Linux or Cmd-F on Mac.
|
||||
findCmd.promptMessage=Search for:
|
||||
|
||||
# LOCALIZATION NOTE (gotoLineCmd.promptTitle): This is the dialog title used
|
||||
# when the user wants to jump to a specific line number in the code. You can
|
||||
# access this feature by pressing Ctrl-J on Windows/Linux or Cmd-J on Mac.
|
||||
gotoLineCmd.promptTitle=Go to line…
|
||||
|
||||
# LOCALIZATION NOTE (gotoLineCmd.promptMessage): This is the message shown when
|
||||
# the user wants to jump to a specific line number in the code. You can
|
||||
# access this feature by pressing Ctrl-J on Windows/Linux or Cmd-J on Mac.
|
||||
gotoLineCmd.promptMessage=Jump to line number:
|
||||
|
|
Загрузка…
Ссылка в новой задаче