mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 960270 - Streamline Editor API. r=msucan
This commit is contained in:
parent
96d6c87b41
commit
c66cff2b44
@ -39,7 +39,7 @@ function test() {
|
||||
|
||||
ok(gContextMenu,
|
||||
"The source editor's context menupopup is available.");
|
||||
ok(gEditor.isReadOnly(),
|
||||
ok(gEditor.getOption("readOnly"),
|
||||
"The source editor is read only.");
|
||||
|
||||
gEditor.focus();
|
||||
|
@ -1490,14 +1490,10 @@ var Scratchpad = {
|
||||
value: initialText,
|
||||
lineNumbers: true,
|
||||
showTrailingSpace: Services.prefs.getBoolPref(SHOW_TRAILING_SPACE),
|
||||
enableCodeFolding: Services.prefs.getBoolPref(ENABLE_CODE_FOLDING),
|
||||
contextMenu: "scratchpad-text-popup"
|
||||
};
|
||||
|
||||
if (Services.prefs.getBoolPref(ENABLE_CODE_FOLDING)) {
|
||||
config.foldGutter = true;
|
||||
config.gutters = ["CodeMirror-linenumbers", "CodeMirror-foldgutter"];
|
||||
}
|
||||
|
||||
this.editor = new Editor(config);
|
||||
this.editor.appendTo(document.querySelector("#scratchpad-editor")).then(() => {
|
||||
var lines = initialText.split("\n");
|
||||
|
@ -148,9 +148,9 @@ function Editor(config) {
|
||||
};
|
||||
|
||||
// Additional shortcuts.
|
||||
this.config.extraKeys[Editor.keyFor("jumpToLine")] = (cm) => this.jumpToLine(cm);
|
||||
this.config.extraKeys[Editor.keyFor("moveLineUp")] = (cm) => this.moveLineUp();
|
||||
this.config.extraKeys[Editor.keyFor("moveLineDown")] = (cm) => this.moveLineDown();
|
||||
this.config.extraKeys[Editor.keyFor("jumpToLine")] = () => this.jumpToLine();
|
||||
this.config.extraKeys[Editor.keyFor("moveLineUp")] = () => this.moveLineUp();
|
||||
this.config.extraKeys[Editor.keyFor("moveLineDown")] = () => this.moveLineDown();
|
||||
this.config.extraKeys[Editor.keyFor("toggleComment")] = "toggleComment";
|
||||
|
||||
// Disable ctrl-[ and ctrl-] because toolbox uses those shortcuts.
|
||||
@ -176,6 +176,16 @@ function Editor(config) {
|
||||
});
|
||||
});
|
||||
|
||||
// Set the code folding gutter, if needed.
|
||||
if (this.config.enableCodeFolding) {
|
||||
this.config.foldGutter = true;
|
||||
|
||||
if (!this.config.gutters) {
|
||||
this.config.gutters = this.config.lineNumbers ? ["CodeMirror-linenumbers"] : [];
|
||||
this.config.gutters.push("CodeMirror-foldgutter");
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite default tab behavior. If something is selected,
|
||||
// indent those lines. If nothing is selected and we're
|
||||
// indenting with tabs, insert one tab. Otherwise insert N
|
||||
@ -257,7 +267,9 @@ Editor.prototype = {
|
||||
cm = win.CodeMirror(win.document.body, this.config);
|
||||
cm.getWrapperElement().addEventListener("contextmenu", (ev) => {
|
||||
ev.preventDefault();
|
||||
this.showContextMenu(el.ownerDocument, ev.screenX, ev.screenY);
|
||||
if (!this.config.contextMenu) return;
|
||||
let popup = el.ownerDocument.getElementById(this.config.contextMenu);
|
||||
popup.openPopupAtScreen(ev.screenX, ev.screenY, true);
|
||||
}, false);
|
||||
|
||||
cm.on("focus", () => this.emit("focus"));
|
||||
@ -659,33 +671,12 @@ Editor.prototype = {
|
||||
return cm.isClean(this.version);
|
||||
},
|
||||
|
||||
/**
|
||||
* True if the editor is in the read-only mode, false otherwise.
|
||||
*/
|
||||
isReadOnly: function () {
|
||||
return this.getOption("readOnly");
|
||||
},
|
||||
|
||||
/**
|
||||
* Displays a context menu at the point x:y. The first
|
||||
* argument, container, should be a DOM node that contains
|
||||
* a context menu element specified by the ID from
|
||||
* config.contextMenu.
|
||||
*/
|
||||
showContextMenu: function (container, x, y) {
|
||||
if (this.config.contextMenu == null)
|
||||
return;
|
||||
|
||||
let popup = container.getElementById(this.config.contextMenu);
|
||||
popup.openPopupAtScreen(x, y, true);
|
||||
},
|
||||
|
||||
/**
|
||||
* This method opens an in-editor dialog asking for a line to
|
||||
* jump to. Once given, it changes cursor to that line.
|
||||
*/
|
||||
jumpToLine: function (cm) {
|
||||
let doc = cm.getWrapperElement().ownerDocument;
|
||||
jumpToLine: function () {
|
||||
let doc = editors.get(this).getWrapperElement().ownerDocument;
|
||||
let div = doc.createElement("div");
|
||||
let inp = doc.createElement("input");
|
||||
let txt = doc.createTextNode(L10N.GetStringFromName("gotoLineCmd.promptTitle"));
|
||||
@ -933,7 +924,7 @@ function controller(ed) {
|
||||
}
|
||||
|
||||
if (cmd == "cmd_gotoLine")
|
||||
ed.jumpToLine(cm);
|
||||
ed.jumpToLine();
|
||||
},
|
||||
|
||||
onEvent: function () {}
|
||||
|
Loading…
Reference in New Issue
Block a user