Skip to content

Instantly share code, notes, and snippets.

@thykka
Last active June 8, 2022 07:32
Show Gist options
  • Select an option

  • Save thykka/53b1e602131a0c86a28bc62a116b9f18 to your computer and use it in GitHub Desktop.

Select an option

Save thykka/53b1e602131a0c86a28bc62a116b9f18 to your computer and use it in GitHub Desktop.

Revisions

  1. thykka revised this gist Jun 8, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion stage-codemirror-linewrap.user.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,15 @@
    // ==UserScript==
    // @name Stage / CodeMirror Line wrapping
    // @namespace http://tampermonkey.net/
    // @version 0.1.1
    // @version 0.1.2
    // @description Enables line wrapping for CodeMirror, with some responsive tweaks.
    // @author Moses Holmström
    // @match https://*.stage.crasman.fi/admin/*
    // @match https://*.stage.crasman.cloud/admin/*
    // @grant none
    // @updateURL https://gist.github.com/thykka/53b1e602131a0c86a28bc62a116b9f18/raw/stage-codemirror-linewrap.user.js
    // @downloadURL https://gist.github.com/thykka/53b1e602131a0c86a28bc62a116b9f18/raw/stage-codemirror-linewrap.user.js
    // @icon https://crasman.stage.crasman.fi/favicon.ico
    // ==/UserScript==

    (function() {
  2. thykka revised this gist Mar 25, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stage-codemirror-linewrap.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name Stage / CodeMirror Line wrapping
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @version 0.1.1
    // @description Enables line wrapping for CodeMirror, with some responsive tweaks.
    // @author Moses Holmström
    // @match https://*.stage.crasman.fi/admin/*
  3. thykka revised this gist Mar 25, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stage-codemirror-linewrap.user.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // ==UserScript==
    // @name Stage CodeMirror Line wrapping
    // @name Stage / CodeMirror Line wrapping
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @description Enables line wrapping for CodeMirror, with some responsive tweaks.
  4. thykka revised this gist Mar 25, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions stage-codemirror-linewrap.user.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@
    // @match https://*.stage.crasman.fi/admin/*
    // @match https://*.stage.crasman.cloud/admin/*
    // @grant none
    // @updateURL https://gist.github.com/thykka/53b1e602131a0c86a28bc62a116b9f18/raw/stage-codemirror-linewrap.user.js
    // @downloadURL https://gist.github.com/thykka/53b1e602131a0c86a28bc62a116b9f18/raw/stage-codemirror-linewrap.user.js
    // ==/UserScript==

    (function() {
  5. thykka created this gist Mar 25, 2022.
    42 changes: 42 additions & 0 deletions stage-codemirror-linewrap.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    // ==UserScript==
    // @name Stage CodeMirror Line wrapping
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @description Enables line wrapping for CodeMirror, with some responsive tweaks.
    // @author Moses Holmström
    // @match https://*.stage.crasman.fi/admin/*
    // @match https://*.stage.crasman.cloud/admin/*
    // @grant none
    // ==/UserScript==

    (function() {
    'use strict';

    // Constrain editor to screen width
    document.body.style.minWidth = '0';
    document.getElementById('workarea').style.minWidth = '0';

    document.querySelectorAll("#dialog-context,#workarea").forEach(el => {
    el.addEventListener("DOMSubtreeModified", ev => {
    const cmInstance = ev.target.closest('.CodeMirror');
    if(!cmInstance) return; // wrong element

    if(cmInstance.dataset?.lineWrapInitialized) return;


    if(!cmInstance.CodeMirror) return; // not initialized
    if(!cmInstance.CodeMirror.state) return; // ghost editor

    const uiComponent = cmInstance.closest('.ui-component-codemirror');
    if(!uiComponent) return;

    uiComponent.style.maxWidth = '100vw';
    cmInstance.CodeMirror.setOption('lineWrapping', true);
    cmInstance.dataset.lineWrapInitialized = true;
    });
    });

    document.querySelectorAll('.CodeMirror').forEach(cm => {
    cm.CodeMirror.setOption('lineWrapping', true);
    });
    })();