Difference between revisions of "Code-editor-firefox-default-context-for-mediawiki"

From Wiki4Intranet
Jump to: navigation, search
 
Line 11: Line 11:
 
         minimap: {
 
         minimap: {
 
             enabled: false,
 
             enabled: false,
        },
 
        wordwrap: {
 
            enabled: true,
 
 
         },
 
         },
 
         unicodeHighlight: {
 
         unicodeHighlight: {
 
             ambiguousCharacters: false,
 
             ambiguousCharacters: false,
 +
            invisibleCharacters: false,
 
         },         
 
         },         
         theme: "vs",
+
        lineNumbers: "off",
         language: "plaintext",
+
         theme: "wiki-theme",
         wordWrap: "off",
+
         language: "wikitext",
 +
         wordWrap: "on",
 
         accessibilitySupport: "on",
 
         accessibilitySupport: "on",
 
         accessibilityPageSize: 20,
 
         accessibilityPageSize: 20,
Line 62: Line 61:
 
         {
 
         {
 
             func() {
 
             func() {
                 // console.log("ext-code-editor.init");
+
                 monaco.languages.register({ id: 'wikitext' });
 +
                monaco.languages.setMonarchTokensProvider("wikitext", {
 +
                    tokenizer: {
 +
                        root: [
 +
                            [/'''[^']+'''/, "bold-quote"],
 +
                        ],
 +
                        whitespace: [
 +
                            [/[ \t\r\n]+/, 'white'],
 +
                            [/<!--/, 'comment', '@comment']
 +
                        ],
 +
                        comment: [
 +
                            [/[^<\-]+/, 'comment.content'],
 +
                            [/-->/, 'comment', '@pop'],
 +
                            [/<!--/, 'comment.content.invalid'],
 +
                            [/[<\-]/, 'comment.content']
 +
                        ],
 +
 
 +
                    },
 +
                });
 +
                // Define a new theme that contains only rules that match this language
 +
                monaco.editor.defineTheme("wiki-theme", {
 +
                    base: "vs",
 +
                    inherit: true,
 +
                    rules: [
 +
                        { token: "bold-quote", foreground: "008800", fontStyle: "bold"  },
 +
                    ],
 +
                    colors: {
 +
                        "editor.foreground": "#000000",
 +
                    },
 +
                });
 +
 
 
             },
 
             },
            args: [],
+
             injectImmediately: true,
             injectImmediately: false,
+
         },          
         },
+
 
         {
 
         {
 
             injectImmediately: true,
 
             injectImmediately: true,

Latest revision as of 09:49, 17 April 2024

/**
 * @type {Context}
 */
({
    /**
     * {@link https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IStandaloneEditorConstructionOptions.html}
     * {@link https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IStandaloneDiffEditorConstructionOptions.html}
     */
    options: {
        minimap: {
            enabled: false,
        },
        unicodeHighlight: {
            ambiguousCharacters: false,
            invisibleCharacters: false,
        },        
        lineNumbers: "off",
        theme: "wiki-theme",
        language: "wikitext",
        wordWrap: "on",
        accessibilitySupport: "on",
        accessibilityPageSize: 20,
        scrollBeyondLastLine: true,
        ignoreTrimWhitespace: true,
        useInlineViewWhenSpaceIsLimited: true,
    },
    /**
     * {@link https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IActionDescriptor.html}
     */
    actions: {
        "user.toggleWordWarp": {
            label: "Toggle Word Wrap",
            keybindings: [
                "Alt+KeyZ",
            ],
            contextMenuGroupId: "view",
            contextMenuOrder: 4.5,
            run(editor) {
                let wrappingInfo = editor.getOption(monaco.editor.EditorOption.wrappingInfo);
                editor.updateOptions({
                    wordWrapOverride2: wrappingInfo.wrappingColumn == -1 ? 'on' : 'off',
                });
            },
        },
        "user.toggleIgnoreTrimWhitespace": {
            label: "Toggle Show Trim Whitespace Diff",
            precondition: "isInDiffEditor",
            contextMenuGroupId: "view",
            contextMenuOrder: 4.6,
            run() {
                let editor = editorUtil.editor;
                let value = editor._options?.ignoreTrimWhitespace?.value;
                editor.updateOptions({
                    ignoreTrimWhitespace: !value,
                });
            },
        },
    },
    init: [
        {
            func() {
                monaco.languages.register({ id: 'wikitext' });
                monaco.languages.setMonarchTokensProvider("wikitext", {
                    tokenizer: {
                        root: [
                            [/'''[^']+'''/, "bold-quote"],
                        ],
                        whitespace: [
                            [/[ \t\r\n]+/, 'white'],
                            [/<!--/, 'comment', '@comment']
                        ],
                        comment: [
                            [/[^<\-]+/, 'comment.content'],
                            [/-->/, 'comment', '@pop'],
                            [/<!--/, 'comment.content.invalid'],
                            [/[<\-]/, 'comment.content']
                        ],
 
                    },
                });
                // Define a new theme that contains only rules that match this language
                monaco.editor.defineTheme("wiki-theme", {
                    base: "vs",
                    inherit: true,
                    rules: [
                        { token: "bold-quote", foreground: "008800", fontStyle: "bold"  },
                    ],
                    colors: {
                        "editor.foreground": "#000000",
                    },
                });
 
            },
            injectImmediately: true,
        },            
        {
            injectImmediately: true,
            func() {
                let addTouchTools = () => {
                    self.removeEventListener('touchstart', addTouchTools, true);
                    console.debug('addTouchTools');
                    editorUtil.addActions({
                        "user.undo": {
                            label: "Undo",
                            precondition: "textInputFocus && !editorReadonly",
                            contextMenuGroupId: " 1_modification",
                            contextMenuOrder: 11,
                            run(editor) {
                                editor.trigger("", "undo");
                            },
                        },
                        "user.redo": {
                            label: "Redo",
                            precondition: "textInputFocus && !editorReadonly",
                            contextMenuGroupId: " 1_modification",
                            contextMenuOrder: 12,
                            run(editor) {
                                editor.trigger("", "redo");
                            },
                        },
                        "user.paste": {
                            label: "Paste Clipboard Text",
                            precondition: "textInputFocus && !editorReadonly",
                            contextMenuGroupId: "9_cutcopypaste",
                            contextMenuOrder: 4,
                            async run(editor) {
                                // Requires ACCESS_LEVEL >=30
                                if (self.browser) {
                                    try {
                                        await browser.permissions.request({ permissions: ['clipboardRead'] });
                                    } catch (e) {
                                        console.warn(e);
                                    }
                                }
                                try {
                                    let text = await navigator.clipboard.readText();
                                    if (!text) return;
                                    editor.executeEdits("", [{
                                        forceMoveMarkers: true,
                                        range: editor.getSelection(),
                                        text,
                                    }]);
                                } catch (e) {
                                    console.warn(e);
                                } finally {
                                    // await browser.permissions.remove({ permissions: ['clipboardRead'] });
                                }
                            },
                        },
                        "user.delete": {
                            label: "Delete",
                            precondition: "!editorReadonly && editorHasSelection",
                            contextMenuGroupId: "9_cutcopypaste",
                            contextMenuOrder: 5,
                            run(editor) {
                                editor.executeEdits("", [{
                                    forceMoveMarkers: true,
                                    range: editor.getSelection(),
                                    text: "",
                                }]);
                            },
                        },
                        "user.selectAll": {
                            label: "Select All",
                            precondition: "textInputFocus",
                            contextMenuGroupId: "9_cutcopypaste",
                            contextMenuOrder: 6,
                            run(editor) {
                                editor.setSelection(editor.getModel().getFullModelRange());
                            },
                        },
                        "user.find": {
                            label: "Find...",
                            precondition: "textInputFocus && !findWidgetVisible",
                            contextMenuGroupId: "view",
                            contextMenuOrder: 4.9,
                            run() {
                                editor.trigger("", "actions.find");
                            },
                        },
                    });
                };
                self.addEventListener('touchstart', addTouchTools, true);
            },
        },
    ],
})