1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * The source editor exposes XUL commands that can be used when embedded in a XUL
9 * document. This controller drives the availability and behavior of the commands. When
10 * the editor input field is focused, this controller will update the matching menu item
11 * entries found in application menus or context menus.
15 * Returns a controller object that can be used for editor-specific commands:
24 function createController(ed) {
26 supportsCommand(cmd) {
41 isCommandEnabled(cmd) {
42 const cm = ed.codeMirror;
50 return cm.state.search != null && cm.state.search.query != null;
56 return ed.somethingSelected();
63 const cm = ed.codeMirror;
66 cmd_selectAll: "selectAll",
70 cmd_delete: "delCharAfter",
71 cmd_findAgain: "findNext",
75 cm.execCommand(map[cmd]);
79 if (cmd == "cmd_gotoLine") {
89 * Create and insert a commands controller for the provided SourceEditor instance.
91 function insertCommandsController(sourceEditor) {
92 const input = sourceEditor.codeMirror.getInputField();
93 const controller = createController(sourceEditor);
94 input.controllers.insertControllerAt(0, controller);
97 module.exports = { insertCommandsController };