This commit is contained in:
Tim Taubert 2012-03-12 09:41:48 +01:00
Родитель e0cd7fdbe8 7a55e54453
Коммит c409d78680
21 изменённых файлов: 570 добавлений и 219 удалений

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

@ -568,6 +568,7 @@ DebuggerUI.prototype = {
let dbg = this.getDebugger(this.aWindow.gBrowser.selectedTab);
dbg.debuggerWindow.SourceScripts.setEditorMode(aSourceUrl, aContentType);
dbg.editor.setText(aSourceText);
dbg.editor.resetUndo();
let doc = dbg.frame.contentDocument;
let scripts = doc.getElementById("scripts");
let elt = scripts.getElementsByAttribute("value", aSourceUrl)[0];

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

@ -615,6 +615,7 @@ var SourceScripts = {
window.editor.setText(aScript.text);
window.updateEditorBreakpoints();
}
window.editor.resetUndo();
}
};

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

@ -45,10 +45,29 @@
<!ENTITY % debuggerDTD SYSTEM "chrome://browser/locale/devtools/debugger.dtd" >
%debuggerDTD;
]>
<?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
<?xul-overlay href="chrome://browser/content/source-editor-overlay.xul"?>
<xul:window xmlns="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<xul:script type="text/javascript" src="chrome://global/content/globalOverlay.js"/>
<xul:script type="text/javascript" src="debugger.js"/>
<xul:script type="text/javascript" src="debugger-view.js"/>
<xul:popupset id="debugger-popups">
<xul:menupopup id="sourceEditorContextMenu"
onpopupshowing="goUpdateSourceEditorMenuItems()">
<xul:menuitem id="se-cMenu-copy"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-selectAll"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-find"/>
<xul:menuitem id="se-cMenu-findAgain"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-gotoLine"/>
</xul:menupopup>
</xul:popupset>
<xul:commandset id="editMenuCommands"/>
<xul:commandset id="sourceEditorCommands"/>
<xul:keyset id="sourceEditorKeys"/>
<div id="body" class="vbox flex">
<xul:toolbar id="dbg-toolbar">

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

@ -74,6 +74,7 @@ _BROWSER_TEST_FILES = \
browser_dbg_select-line.js \
browser_dbg_clean-exit.js \
browser_dbg_bug723069_editor-breakpoints.js \
browser_dbg_bug731394_editor-contextmenu.js \
head.js \
$(NULL)

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

@ -0,0 +1,102 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Bug 731394: test the debugger source editor default context menu.
*/
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
let gPane = null;
let gTab = null;
let gDebuggee = null;
let gDebugger = null;
function test()
{
let tempScope = {};
Cu.import("resource:///modules/source-editor.jsm", tempScope);
let SourceEditor = tempScope.SourceEditor;
let contextMenu = null;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.debuggerWindow;
gPane.activeThread.addOneTimeListener("scriptsadded", function() {
Services.tm.currentThread.dispatch({ run: onScriptsAdded }, 0);
});
gDebuggee.firstCall();
});
function onScriptsAdded()
{
let scripts = gDebugger.DebuggerView.Scripts._scripts;
is(gDebugger.StackFrames.activeThread.state, "paused",
"Should only be getting stack frames while paused.");
is(scripts.itemCount, 2, "Found the expected number of scripts.");
let editor = gDebugger.editor;
isnot(editor.getText().indexOf("debugger"), -1,
"The correct script was loaded initially.");
contextMenu = gDebugger.document.getElementById("sourceEditorContextMenu");
ok(contextMenu, "source editor context menupopup");
ok(editor.readOnly, "editor is read only");
editor.focus();
editor.setSelection(0, 10);
contextMenu.addEventListener("popupshown", function onPopupShown() {
contextMenu.removeEventListener("popupshown", onPopupShown, false);
executeSoon(testContextMenu);
}, false);
contextMenu.openPopup(editor.editorElement, "overlap", 0, 0, true, false);
}
function testContextMenu()
{
let document = gDebugger.document;
ok(document.getElementById("editMenuCommands"),
"#editMenuCommands found");
ok(!document.getElementById("editMenuKeys"),
"#editMenuKeys not found");
ok(document.getElementById("sourceEditorCommands"),
"#sourceEditorCommands found");
ok(document.getElementById("sourceEditorKeys"),
"#sourceEditorKeys found");
// Map command ids to their expected disabled state.
let commands = {"se-cmd-undo": true, "se-cmd-redo": true,
"se-cmd-cut": true, "se-cmd-paste": true,
"se-cmd-delete": true, "cmd_findAgain": true,
"cmd_findPrevious": true, "cmd_find": false,
"cmd_gotoLine": false, "cmd_copy": false,
"se-cmd-selectAll": false};
for (let id in commands) {
let element = document.getElementById(id);
is(element.hasAttribute("disabled"), commands[id],
id + " hasAttribute('disabled') check");
}
executeSoon(function() {
contextMenu.hidePopup();
gDebugger.StackFrames.activeThread.resume(finish);
});
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
});
}

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

@ -10,7 +10,7 @@ browser.jar:
content/browser/devtools/cssruleview.xul (styleinspector/cssruleview.xul)
content/browser/devtools/styleinspector.css (styleinspector/styleinspector.css)
content/browser/orion.js (sourceeditor/orion/orion.js)
content/browser/source-editor-overlay.xul (sourceeditor/source-editor-overlay.xul)
* content/browser/source-editor-overlay.xul (sourceeditor/source-editor-overlay.xul)
* content/browser/debugger.xul (debugger/debugger.xul)
content/browser/debugger.css (debugger/debugger.css)
content/browser/debugger.js (debugger/debugger.js)

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

@ -111,21 +111,6 @@
modifiers="accel"/>
-->
<key id="key_cut"
key="&cutCmd.key;"
modifiers="accel"/>
<key id="key_copy"
key="&copyCmd.key;"
modifiers="accel"/>
<key id="key_paste"
key="&pasteCmd.key;"
modifiers="accel"/>
<key id="key_selectAll" key="&selectAllCmd.key;" modifiers="accel"/>
<key id="key_undo" key="&undoCmd.key;" modifiers="accel"
command="se-cmd-undo"/>
<key id="key_redo" key="&undoCmd.key;" modifiers="accel,shift"
command="se-cmd-redo"/>
<key id="sp-key-run"
key="&run.key;"
command="sp-cmd-run"
@ -146,28 +131,6 @@
key="&webConsoleCmd.commandkey;"
command="sp-cmd-webConsole"
modifiers="accel,shift"/>
<key id="key_find"
key="&findCmd.key;"
command="cmd_find"
modifiers="accel"/>
#ifdef XP_MACOSX
<key id="key_findAgain"
key="&findAgainCmd.key;"
command="cmd_findAgain"
modifiers="accel"/>
<key id="key_findPrevious"
key="&findPreviousCmd.key;"
command="cmd_findPrevious"
modifiers="accel,shift"/>
#else
<key id="key_findAgain"
keycode="VK_F3"
command="cmd_findAgain"/>
<key id="key_findPrevious"
keycode="VK_F3"
command="cmd_findPrevious"
modifiers="shift"/>
#endif
<key id="key_openHelp"
keycode="VK_F1"
command="sp-cmd-documentationLink"/>
@ -219,56 +182,20 @@
<menu id="sp-edit-menu" label="&editMenu.label;"
accesskey="&editMenu.accesskey;">
<menupopup id="sp-menu_editpopup"
onpopupshowing="goUpdateGlobalEditMenuItems()">
<menuitem id="sp-menu-undo"
label="&undoCmd.label;"
key="key_undo"
accesskey="&undoCmd.accesskey;"
command="se-cmd-undo"/>
<menuitem id="sp-menu-redo"
label="&redoCmd.label;"
key="key_redo"
accesskey="&redoCmd.accesskey;"
command="se-cmd-redo"/>
onpopupshowing="goUpdateSourceEditorMenuItems()">
<menuitem id="se-menu-undo"/>
<menuitem id="se-menu-redo"/>
<menuseparator/>
<menuitem id="sp-menu-cut"
label="&cutCmd.label;"
key="key_cut"
accesskey="&cutCmd.accesskey;"
command="cmd_cut"/>
<menuitem id="sp-menu-copy"
label="&copyCmd.label;"
key="key_copy"
accesskey="&copyCmd.accesskey;"
command="cmd_copy"/>
<menuitem id="sp-menu-paste"
label="&pasteCmd.label;"
key="key_paste"
accesskey="&pasteCmd.accesskey;"
command="cmd_paste"/>
<menuitem id="se-menu-cut"/>
<menuitem id="se-menu-copy"/>
<menuitem id="se-menu-paste"/>
<menuseparator/>
<menuitem id="sp-menu-selectAll"
label="&selectAllCmd.label;"
key="key_selectAll"
accesskey="&selectAllCmd.accesskey;"
command="cmd_selectAll"/>
<menuitem id="se-menu-selectAll"/>
<menuseparator/>
<menuitem id="sp-menu-find"
label="&findCmd.label;"
accesskey="&findCmd.accesskey;"
key="key_find"
command="cmd_find"/>
<menuitem id="sp-menu-findAgain"
label="&findAgainCmd.label;"
accesskey="&findAgainCmd.accesskey;"
key="key_findAgain"
command="cmd_findAgain"/>
<menuitem id="se-menu-find"/>
<menuitem id="se-menu-findAgain"/>
<menuseparator/>
<menuitem id="sp-menu-gotoLine"
label="&gotoLineCmd.label;"
accesskey="&gotoLineCmd.accesskey;"
key="key_gotoLine"
command="cmd_gotoLine"/>
<menuitem id="se-menu-gotoLine"/>
</menupopup>
</menu>
@ -338,13 +265,13 @@
<popupset id="scratchpad-popups">
<menupopup id="scratchpad-text-popup"
onpopupshowing="goUpdateGlobalEditMenuItems()">
<menuitem id="menu_cut"/>
<menuitem id="menu_copy"/>
<menuitem id="menu_paste"/>
<menuitem id="menu_delete"/>
onpopupshowing="goUpdateSourceEditorMenuItems()">
<menuitem id="se-cMenu-cut"/>
<menuitem id="se-cMenu-copy"/>
<menuitem id="se-cMenu-paste"/>
<menuitem id="se-cMenu-delete"/>
<menuseparator/>
<menuitem id="menu_selectAll"/>
<menuitem id="se-cMenu-selectAll"/>
<menuseparator/>
<menuitem id="sp-text-run"
label="&run.label;"
@ -370,7 +297,7 @@
</popupset>
<notificationbox id="scratchpad-notificationbox" flex="1">
<hbox id="scratchpad-editor" flex="1" context="scratchpad-text-popup" />
<hbox id="scratchpad-editor" flex="1"/>
</notificationbox>
</window>

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

@ -27,7 +27,7 @@ function runTests()
let doc = gScratchpadWindow.document;
let winUtils = gScratchpadWindow.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
let OS = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
let OS = Services.appinfo.OS;
info("will test the Edit menu");
@ -51,9 +51,9 @@ function runTests()
let menuPopup = editMenu.menupopup;
ok(menuPopup, "the Edit menupopup");
let cutItem = doc.getElementById("sp-menu-cut");
let cutItem = doc.getElementById("se-menu-cut");
ok(cutItem, "the Cut menuitem");
let pasteItem = doc.getElementById("sp-menu-paste");
let pasteItem = doc.getElementById("se-menu-paste");
ok(pasteItem, "the Paste menuitem");
let anchor = doc.documentElement;
@ -174,9 +174,9 @@ function runTests()
menuPopup = doc.getElementById("scratchpad-text-popup");
ok(menuPopup, "the context menupopup");
cutItem = doc.getElementById("menu_cut");
cutItem = doc.getElementById("se-cMenu-cut");
ok(cutItem, "the Cut menuitem");
pasteItem = doc.getElementById("menu_paste");
pasteItem = doc.getElementById("se-cMenu-paste");
ok(pasteItem, "the Paste menuitem");
sp.setText("bug 699130: hello world! (context menu)");

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

@ -24,6 +24,7 @@
* Kenny Heaton <kennyheaton@gmail.com>
* Spyros Livathinos <livathinos.spyros@gmail.com>
* Allen Eubank <adeubank@gmail.com>
* Girish Sharma <scrapmachines@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -63,6 +64,14 @@ const ORION_IFRAME = "data:text/html;charset=utf8,<!DOCTYPE html>" +
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
/**
* Maximum allowed vertical offset for the line index when you call
* SourceEditor.setCaretPosition().
*
* @type number
*/
const VERTICAL_OFFSET = 3;
/**
* The primary selection update delay. On Linux, the X11 primary selection is
* updated to hold the currently selected text.
@ -109,6 +118,10 @@ const ORION_ANNOTATION_TYPES = {
* Default key bindings in the Orion editor.
*/
const DEFAULT_KEYBINDINGS = [
{
action: "enter",
code: Ci.nsIDOMKeyEvent.DOM_VK_ENTER,
},
{
action: "undo",
code: Ci.nsIDOMKeyEvent.DOM_VK_Z,
@ -465,6 +478,10 @@ SourceEditor.prototype = {
*/
_doTab: function SE__doTab()
{
if (this.readOnly) {
return false;
}
let indent = "\t";
let selection = this.getSelection();
let model = this._model;
@ -515,6 +532,10 @@ SourceEditor.prototype = {
*/
_doUnindentLines: function SE__doUnindentLines()
{
if (this.readOnly) {
return true;
}
let indent = "\t";
let selection = this.getSelection();
@ -569,6 +590,10 @@ SourceEditor.prototype = {
*/
_doEnter: function SE__doEnter()
{
if (this.readOnly) {
return false;
}
let selection = this.getSelection();
if (selection.start != selection.end) {
return false;
@ -1309,10 +1334,56 @@ SourceEditor.prototype = {
* The new caret line location. Line numbers start from 0.
* @param number [aColumn=0]
* Optional. The new caret column location. Columns start from 0.
* @param number [aAlign=0]
* Optional. Position of the line with respect to viewport.
* Allowed values are:
* SourceEditor.VERTICAL_ALIGN.TOP target line at top of view.
* SourceEditor.VERTICAL_ALIGN.CENTER target line at center of view.
* SourceEditor.VERTICAL_ALIGN.BOTTOM target line at bottom of view.
*/
setCaretPosition: function SE_setCaretPosition(aLine, aColumn)
setCaretPosition: function SE_setCaretPosition(aLine, aColumn, aAlign)
{
this.setCaretOffset(this._model.getLineStart(aLine) + (aColumn || 0));
let editorHeight = this._view.getClientArea().height;
let lineHeight = this._view.getLineHeight();
let linesVisible = Math.floor(editorHeight/lineHeight);
let halfVisible = Math.round(linesVisible/2);
let firstVisible = this.getTopIndex();
let lastVisible = this._view.getBottomIndex();
let caretOffset = this._model.getLineStart(aLine) + (aColumn || 0);
this._view.setSelection(caretOffset, caretOffset, false);
// If the target line is in view, skip the vertical alignment part.
if (aLine <= lastVisible && aLine >= firstVisible) {
this._view.showSelection();
return;
}
// Setting the offset so that the line always falls in the upper half
// of visible lines (lower half for BOTTOM aligned).
// VERTICAL_OFFSET is the maximum allowed value.
let offset = Math.min(halfVisible, VERTICAL_OFFSET);
let topIndex;
switch (aAlign) {
case this.VERTICAL_ALIGN.CENTER:
topIndex = Math.max(aLine - halfVisible, 0);
break;
case this.VERTICAL_ALIGN.BOTTOM:
topIndex = Math.max(aLine - linesVisible + offset, 0);
break;
default: // this.VERTICAL_ALIGN.TOP.
topIndex = Math.max(aLine - offset, 0);
break;
}
// Bringing down the topIndex to total lines in the editor if exceeding.
topIndex = Math.min(topIndex, this.getLineCount());
this.setTopIndex(topIndex);
let location = this._view.getLocationAtOffset(caretOffset);
this._view.setHorizontalPixel(location.x);
},
/**

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

@ -35,80 +35,203 @@
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE overlay SYSTEM "chrome://browser/locale/devtools/sourceeditor.dtd">
<!DOCTYPE overlay [
<!ENTITY % editMenuStrings SYSTEM "chrome://global/locale/editMenuOverlay.dtd">
%editMenuStrings;
<!ENTITY % sourceEditorStrings SYSTEM "chrome://browser/locale/devtools/sourceeditor.dtd">
%sourceEditorStrings;
]>
<overlay id="sourceEditorOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- This Source Editor overlay requires the editMenuOverlay.xul to be loaded.
The globalOverlay.js script is also required in the XUL document where
the source-editor-overlay.xul is loaded. -->
the source-editor-overlay.xul is loaded. Do not use #editMenuKeys to
avoid conflicts! -->
<script type="application/javascript">
function goUpdateSourceEditorMenuItems()
{
goUpdateGlobalEditMenuItems();
let commands = ['se-cmd-undo', 'se-cmd-redo', 'se-cmd-cut', 'se-cmd-paste',
'se-cmd-delete'];
commands.forEach(goUpdateCommand);
}
</script>
<commandset id="sourceEditorCommands">
<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')"/>
<command id="se-cmd-selectAll" oncommand="goDoCommand('se-cmd-selectAll')"/>
<command id="se-cmd-cut" oncommand="goDoCommand('se-cmd-cut')" disabled="true"/>
<command id="se-cmd-paste" oncommand="goDoCommand('se-cmd-paste')" disabled="true"/>
<command id="se-cmd-delete" oncommand="goDoCommand('se-cmd-delete')" disabled="true"/>
<command id="se-cmd-undo" oncommand="goDoCommand('se-cmd-undo')" disabled="true"/>
<command id="se-cmd-redo" oncommand="goDoCommand('se-cmd-redo')" disabled="true"/>
</commandset>
<keyset id="sourceEditorKeys">
<!-- Do not use both #sourceEditorKeys and #editMenuKeys in the same
document to avoid conflicts! -->
<key id="key_undo"
key="&undoCmd.key;"
modifiers="accel"
command="se-cmd-undo"/>
#ifdef XP_UNIX
<key id="key_redo"
key="&undoCmd.key;"
modifiers="accel,shift"
command="se-cmd-redo"/>
#else
<key id="key_redo"
key="&redoCmd.key;"
modifiers="accel"
command="se-cmd-redo"/>
#endif
<key id="key_cut"
key="&cutCmd.key;"
modifiers="accel"
command="se-cmd-cut"/>
<key id="key_copy"
key="&copyCmd.key;"
modifiers="accel"
command="cmd_copy"/>
<key id="key_paste"
key="&pasteCmd.key;"
modifiers="accel"
command="se-cmd-paste"/>
<key id="key_gotoLine"
key="&gotoLineCmd.key;"
command="cmd_gotoLine"
modifiers="accel"/>
<key id="key_delete"
keycode="VK_DELETE"
command="se-cmd-delete"/>
<key id="key_selectAll"
key="&selectAllCmd.key;"
modifiers="accel"
command="se-cmd-selectAll"/>
<key id="key_find"
key="&findCmd.key;"
modifiers="accel"
command="cmd_find"/>
<key id="key_findAgain"
key="&findAgainCmd.key;"
modifiers="accel"
command="cmd_findAgain"/>
<key id="key_findPrevious"
key="&findAgainCmd.key;"
modifiers="shift,accel"
command="cmd_findPrevious"/>
<key id="key_findAgain2"
keycode="&findAgainCmd.key2;"
command="cmd_findAgain"/>
<key id="key_findPrevious2"
keycode="&findAgainCmd.key2;"
modifiers="shift"
command="cmd_findPrevious"/>
</keyset>
<menupopup id="sourceEditorContextMenu"
onpopupshowing="goUpdateGlobalEditMenuItems()">
<menuitem id="se-menu-undo"
label="&undoCmd.label;"
key="key_undo"
accesskey="&undoCmd.accesskey;"
command="se-cmd-undo"/>
<menuseparator/>
<menuitem id="se-menu-cut"
label="&cutCmd.label;"
key="key_cut"
accesskey="&cutCmd.accesskey;"
command="cmd_cut"/>
<menuitem id="se-menu-copy"
label="&copyCmd.label;"
key="key_copy"
accesskey="&copyCmd.accesskey;"
command="cmd_copy"/>
<menuitem id="se-menu-paste"
label="&pasteCmd.label;"
key="key_paste"
accesskey="&pasteCmd.accesskey;"
command="cmd_paste"/>
<menuitem id="se-menu-delete"
label="&deleteCmd.label;"
key="key_delete"
accesskey="&deleteCmd.accesskey;"
command="cmd_delete"/>
<menuseparator/>
<menuitem id="se-menu-selectAll"
label="&selectAllCmd.label;"
key="key_selectAll"
accesskey="&selectAllCmd.accesskey;"
command="cmd_selectAll"/>
<menuseparator/>
<menuitem id="se-menu-find"
label="&findCmd.label;"
accesskey="&findCmd.accesskey;"
key="key_find"
command="cmd_find"/>
<menuitem id="se-menu-findAgain"
label="&findAgainCmd.label;"
accesskey="&findAgainCmd.accesskey;"
key="key_findAgain"
command="cmd_findAgain"/>
<menuseparator/>
<menuitem id="se-menu-gotoLine"
label="&gotoLineCmd.label;"
accesskey="&gotoLineCmd.accesskey;"
key="key_gotoLine"
command="cmd_gotoLine"/>
</menupopup>
<!-- Items for the Edit menu -->
<menuitem id="se-menu-undo"
label="&undoCmd.label;"
key="key_undo"
accesskey="&undoCmd.accesskey;"
command="se-cmd-undo"/>
<menuitem id="se-menu-redo"
label="&redoCmd.label;"
key="key_redo"
accesskey="&redoCmd.accesskey;"
command="se-cmd-redo"/>
<menuitem id="se-menu-cut"
label="&cutCmd.label;"
key="key_cut"
accesskey="&cutCmd.accesskey;"
command="se-cmd-cut"/>
<menuitem id="se-menu-copy"
label="&copyCmd.label;"
key="key_copy"
accesskey="&copyCmd.accesskey;"
command="cmd_copy"/>
<menuitem id="se-menu-paste"
label="&pasteCmd.label;"
key="key_paste"
accesskey="&pasteCmd.accesskey;"
command="se-cmd-paste"/>
<menuitem id="se-menu-delete"
label="&deleteCmd.label;"
key="key_delete"
accesskey="&deleteCmd.accesskey;"
command="se-cmd-delete"/>
<menuitem id="se-menu-selectAll"
label="&selectAllCmd.label;"
key="key_selectAll"
accesskey="&selectAllCmd.accesskey;"
command="se-cmd-selectAll"/>
<menuitem id="se-menu-find"
label="&findCmd.label;"
accesskey="&findCmd.accesskey;"
key="key_find"
command="cmd_find"/>
<menuitem id="se-menu-findAgain"
label="&findAgainCmd.label;"
accesskey="&findAgainCmd.accesskey;"
key="key_findAgain"
command="cmd_findAgain"/>
<menuitem id="se-menu-gotoLine"
label="&gotoLineCmd.label;"
accesskey="&gotoLineCmd.accesskey;"
key="key_gotoLine"
command="cmd_gotoLine"/>
<!-- Items for context menus -->
<menuitem id="se-cMenu-undo"
label="&undoCmd.label;"
key="key_undo"
accesskey="&undoCmd.accesskey;"
command="se-cmd-undo"/>
<menuitem id="se-cMenu-cut"
label="&cutCmd.label;"
key="key_cut"
accesskey="&cutCmd.accesskey;"
command="se-cmd-cut"/>
<menuitem id="se-cMenu-copy"
label="&copyCmd.label;"
key="key_copy"
accesskey="&copyCmd.accesskey;"
command="cmd_copy"/>
<menuitem id="se-cMenu-paste"
label="&pasteCmd.label;"
key="key_paste"
accesskey="&pasteCmd.accesskey;"
command="se-cmd-paste"/>
<menuitem id="se-cMenu-delete"
label="&deleteCmd.label;"
key="key_delete"
accesskey="&deleteCmd.accesskey;"
command="se-cmd-delete"/>
<menuitem id="se-cMenu-selectAll"
label="&selectAllCmd.label;"
key="key_selectAll"
accesskey="&selectAllCmd.accesskey;"
command="se-cmd-selectAll"/>
<menuitem id="se-cMenu-find"
label="&findCmd.label;"
accesskey="&findCmd.accesskey;"
key="key_find"
command="cmd_find"/>
<menuitem id="se-cMenu-findAgain"
label="&findAgainCmd.label;"
accesskey="&findAgainCmd.accesskey;"
key="key_findAgain"
command="cmd_findAgain"/>
<menuitem id="se-cMenu-gotoLine"
label="&gotoLineCmd.label;"
accesskey="&gotoLineCmd.accesskey;"
key="key_gotoLine"
command="cmd_gotoLine"/>
</overlay>

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

@ -253,6 +253,10 @@ SourceEditorController.prototype = {
case "cmd_gotoLine":
case "se-cmd-undo":
case "se-cmd-redo":
case "se-cmd-cut":
case "se-cmd-paste":
case "se-cmd-delete":
case "se-cmd-selectAll":
result = true;
break;
default:
@ -278,6 +282,7 @@ SourceEditorController.prototype = {
switch (aCommand) {
case "cmd_find":
case "cmd_gotoLine":
case "se-cmd-selectAll":
result = true;
break;
case "cmd_findAgain":
@ -290,6 +295,19 @@ SourceEditorController.prototype = {
case "se-cmd-redo":
result = this._editor.canRedo();
break;
case "se-cmd-cut":
case "se-cmd-delete": {
let selection = this._editor.getSelection();
result = selection.start != selection.end && !this._editor.readOnly;
break;
}
case "se-cmd-paste": {
let window = this._editor._view._frameWindow;
let controller = window.controllers.getControllerForCommand("cmd_paste");
result = !this._editor.readOnly &&
controller.isCommandEnabled("cmd_paste");
break;
}
default:
result = false;
break;
@ -320,12 +338,26 @@ SourceEditorController.prototype = {
case "cmd_gotoLine":
this._editor.ui.gotoLine();
break;
case "se-cmd-selectAll":
this._editor._view.invokeAction("selectAll");
break;
case "se-cmd-undo":
this._editor.undo();
break;
case "se-cmd-redo":
this._editor.redo();
break;
case "se-cmd-cut":
this._editor.ui._ownerWindow.goDoCommand("cmd_cut");
break;
case "se-cmd-paste":
this._editor.ui._ownerWindow.goDoCommand("cmd_paste");
break;
case "se-cmd-delete": {
let selection = this._editor.getSelection();
this._editor.setText("", selection.start, selection.end);
break;
}
}
},

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

@ -312,6 +312,16 @@ SourceEditor.EVENTS = {
DIRTY_CHANGED: "DirtyChanged",
};
/**
* Allowed vertical alignment options for the line index
* when you call SourceEditor.setCaretPosition().
*/
SourceEditor.VERTICAL_ALIGN = {
TOP: 0,
CENTER: 1,
BOTTOM: 2,
};
/**
* Extend a destination object with properties from a source object.
*
@ -336,6 +346,7 @@ extend(SourceEditor.prototype, {
MODES: SourceEditor.MODES,
THEMES: SourceEditor.THEMES,
DEFAULTS: SourceEditor.DEFAULTS,
VERTICAL_ALIGN: SourceEditor.VERTICAL_ALIGN,
_lastFind: null,

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

@ -60,6 +60,7 @@ _BROWSER_TEST_FILES = \
browser_bug712982_line_ruler_click.js \
browser_bug725618_moveLines_shortcut.js \
browser_bug700893_dirty_state.js \
browser_bug729480_line_vertical_align.js \
head.js \
libs:: $(_BROWSER_TEST_FILES)

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

@ -0,0 +1,99 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let tempScope = {};
Cu.import("resource:///modules/source-editor.jsm", tempScope);
let SourceEditor = tempScope.SourceEditor;
let testWin;
let editor;
const VERTICAL_OFFSET = 3;
function test()
{
waitForExplicitFinish();
const windowUrl = "data:application/vnd.mozilla.xul+xml,<?xml version='1.0'?>" +
"<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'" +
" title='test for bug 729480 - allow setCaretPosition align the target line" +
" vertically in view according to a third argument'" +
" width='300' height='300'><box flex='1'/></window>";
const windowFeatures = "chrome,titlebar,toolbar,centerscreen,dialog=no";
testWin = Services.ww.openWindow(null, windowUrl, "_blank", windowFeatures, null);
testWin.addEventListener("load", function onWindowLoad() {
testWin.removeEventListener("load", onWindowLoad, false);
waitForFocus(initEditor, testWin);
}, false);
}
function initEditor()
{
let box = testWin.document.querySelector("box");
editor = new SourceEditor();
editor.init(box, {showLineNumbers: true}, editorLoaded);
}
function editorLoaded()
{
editor.focus();
// setting 3 pages of lines containing the line number.
let view = editor._view;
let lineHeight = view.getLineHeight();
let editorHeight = view.getClientArea().height;
let linesPerPage = Math.floor(editorHeight / lineHeight);
let totalLines = 3 * linesPerPage;
let text = "";
for (let i = 0; i < totalLines; i++) {
text += "Line " + i + "\n";
}
editor.setText(text);
editor.setCaretOffset(0);
let offset = Math.min(Math.round(linesPerPage/2), VERTICAL_OFFSET);
// Building the iterator array.
// [line, alignment, topIndex_check]
let iterateOn = [
[0, "TOP", 0],
[25, "TOP", 25 - offset],
// Case when the target line is already in view.
[27, "TOP", 25 - offset],
[0, "BOTTOM", 0],
[5, "BOTTOM", 0],
[38, "BOTTOM", 38 - linesPerPage + offset],
[0, "CENTER", 0],
[4, "CENTER", 0],
[34, "CENTER", 34 - Math.round(linesPerPage/2)]
];
function testEnd() {
editor.destroy();
testWin.close();
testWin = editor = null;
waitForFocus(finish, window);
}
function testPosition(pos) {
is(editor.getTopIndex(), iterateOn[pos][2], "scroll is correct for test #" + pos);
iterator(++pos);
}
function iterator(i) {
if (i == iterateOn.length) {
testEnd();
} else {
editor.setCaretPosition(iterateOn[i][0], 0,
editor.VERTICAL_ALIGN[iterateOn[i][1]]);
executeSoon(testPosition.bind(this, i));
}
}
iterator(0);
}

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

@ -201,11 +201,21 @@ function editorLoaded()
editor.setText("foobar");
is(editor.getText(), "foobar", "editor allows programmatic changes (setText)");
EventUtils.synthesizeKey("VK_RETURN", {}, testWin);
is(editor.getText(), "foobar", "Enter key does nothing");
EventUtils.synthesizeKey("VK_TAB", {}, testWin);
is(editor.getText(), "foobar", "Tab does nothing");
editor.setText(" foobar");
EventUtils.synthesizeKey("VK_TAB", {shiftKey: true}, testWin);
is(editor.getText(), " foobar", "Shift+Tab does nothing");
editor.readOnly = false;
editor.setCaretOffset(editor.getCharCount());
EventUtils.synthesizeKey("-", {}, testWin);
is(editor.getText(), "foobar-", "editor is now editable again");
is(editor.getText(), " foobar-", "editor is now editable again");
// Test the Selection event.

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

@ -57,7 +57,22 @@
<xul:script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
<xul:popupset id="style-editor-popups">
<xul:menupopup id="sourceEditorContextMenu"/>
<xul:menupopup id="sourceEditorContextMenu"
onpopupshowing="goUpdateSourceEditorMenuItems()">
<xul:menuitem id="se-cMenu-undo"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-cut"/>
<xul:menuitem id="se-cMenu-copy"/>
<xul:menuitem id="se-cMenu-paste"/>
<xul:menuitem id="se-cMenu-delete"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-selectAll"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-find"/>
<xul:menuitem id="se-cMenu-findAgain"/>
<xul:menuseparator/>
<xul:menuitem id="se-cMenu-gotoLine"/>
</xul:menupopup>
</xul:popupset>
<xul:commandset id="editMenuCommands"/>
@ -66,7 +81,6 @@
<xul:command id="style-editor-cmd-close" oncommand="window.close();"/>
</xul:commandset>
<xul:keyset id="editMenuKeys"/>
<xul:keyset id="sourceEditorKeys"/>
<xul:keyset id="style-editor-keyset">
<xul:key id="style-editor-key-close"

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

@ -43,50 +43,6 @@
<!ENTITY editMenu.label "Edit">
<!ENTITY editMenu.accesskey "E">
<!ENTITY undoCmd.label "Undo">
<!ENTITY undoCmd.key "Z">
<!ENTITY undoCmd.accesskey "U">
<!ENTITY redoCmd.label "Redo">
<!ENTITY redoCmd.key "Y">
<!ENTITY redoCmd.accesskey "R">
<!ENTITY cutCmd.label "Cut">
<!ENTITY cutCmd.key "X">
<!ENTITY cutCmd.accesskey "t">
<!ENTITY copyCmd.label "Copy">
<!ENTITY copyCmd.key "C">
<!ENTITY copyCmd.accesskey "C">
<!ENTITY pasteCmd.label "Paste">
<!ENTITY pasteCmd.key "V">
<!ENTITY pasteCmd.accesskey "P">
<!ENTITY selectAllCmd.label "Select All">
<!ENTITY selectAllCmd.key "A">
<!ENTITY selectAllCmd.accesskey "A">
<!ENTITY findCmd.label "Find…">
<!ENTITY findCmd.key "F">
<!ENTITY findCmd.accesskey "F">
<!ENTITY findAgainCmd.label "Find Again…">
<!-- LOCALIZATION NOTE (findAgainCmd.key): This key is used only on Macs.
- Windows and Linux builds use the F3 key which is not localizable on purpose.
-->
<!ENTITY findAgainCmd.key "G">
<!ENTITY findAgainCmd.accesskey "g">
<!-- LOCALIZATION NOTE (findPreviousCmd.key): This key is used only on Macs.
- Windows and Linux builds use the Shift-F3 key which is not localizable on
- purpose.
-->
<!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">

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

@ -10,23 +10,6 @@
- A good criteria is the language in which you'd find the best
- documentation on web development on the web. -->
<!ENTITY undoCmd.label "Undo">
<!ENTITY undoCmd.accesskey "U">
<!ENTITY cutCmd.label "Cut">
<!ENTITY cutCmd.accesskey "t">
<!ENTITY copyCmd.label "Copy">
<!ENTITY copyCmd.accesskey "C">
<!ENTITY pasteCmd.label "Paste">
<!ENTITY pasteCmd.accesskey "P">
<!ENTITY deleteCmd.label "Delete">
<!ENTITY deleteCmd.accesskey "D">
<!ENTITY selectAllCmd.label "Select All">
<!ENTITY selectAllCmd.accesskey "A">
<!ENTITY findCmd.label "Find…">
<!ENTITY findCmd.accesskey "F">
<!ENTITY findAgainCmd.label "Find Again…">
<!ENTITY findAgainCmd.accesskey "g">
<!ENTITY gotoLineCmd.label "Jump to line…">
<!ENTITY gotoLineCmd.key "J">
<!ENTITY gotoLineCmd.accesskey "J">

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

@ -205,7 +205,7 @@
.ruleview-rule-source {
background-color: -moz-dialog;
color: #0091ff;
color: -moz-dialogText;
padding: 2px 5px;
cursor: pointer;
}

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

@ -207,7 +207,7 @@
.ruleview-rule-source {
background-color: -moz-dialog;
color: #0091ff;
color: -moz-dialogText;
padding: 2px 5px;
cursor: pointer;
}

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

@ -205,7 +205,7 @@
.ruleview-rule-source {
background-color: -moz-dialog;
color: #0091ff;
color: -moz-dialogText;
padding: 2px 5px;
cursor: pointer;
}