tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

create-editor.js (1703B)


      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/>. */
      4 
      5 import SourceEditor from "devtools/client/shared/sourceeditor/editor";
      6 import { features, prefs } from "../prefs";
      7 
      8 /**
      9 * Create a SourceEditor
     10 *
     11 * @param {object} config: SourceEditor config object
     12 * @returns
     13 */
     14 export function createEditor(config = { cm6: false }) {
     15  const gutters = ["breakpoints", "hit-markers", "CodeMirror-linenumbers"];
     16 
     17  if (features.codeFolding) {
     18    gutters.push("CodeMirror-foldgutter");
     19  }
     20 
     21  return new SourceEditor({
     22    mode: SourceEditor.modes.javascript,
     23    foldGutter: features.codeFolding,
     24    disableSearchAddon: false,
     25    useSearchAddonPanel: false,
     26    enableCodeFolding: features.codeFolding,
     27    readOnly: true,
     28    lineNumbers: true,
     29    theme: "mozilla",
     30    styleActiveLine: false,
     31    lineWrapping: prefs.editorWrapping,
     32    matchBrackets: true,
     33    showAnnotationRuler: true,
     34    gutters,
     35    value: " ",
     36    extraKeys: {
     37      // Override code mirror keymap to avoid conflicts with split console and tabbing to other elements.
     38      Esc: false,
     39      Tab: false,
     40      "Shift-Tab": false,
     41      "Cmd-F": false,
     42      "Ctrl-F": false,
     43      "Cmd-G": false,
     44      "Ctrl-G": false,
     45    },
     46    cursorBlinkRate: prefs.cursorBlinkRate,
     47    ...config,
     48  });
     49 }
     50 
     51 /**
     52 * Create an headless editor (can be used for syntax highlighting for example)
     53 *
     54 * @returns {CodeMirror}
     55 */
     56 export function createHeadlessEditor() {
     57  const editor = createEditor({ cm6: true });
     58  editor.appendToLocalElement(document.createElement("div"));
     59  return editor;
     60 }