surmon-china / vue-codemirror

@codemirror code editor component for @vuejs
https://github.surmon.me/vue-codemirror
MIT License
3.28k stars 382 forks source link

Disable A Section of the Editor, Instead of the Full Editor #182

Open nkreiger opened 1 year ago

nkreiger commented 1 year ago

Clear and concise description of the problem

In client facing editors, sometimes you want to ensure certain values are always there, and cannot be removed by the user. You could hide them, however, sometimes if its code related the user might accidentally add them back.

Suggested solution

I have written a workaround, around this

const ne = (start, stop) => EditorView.updateListener.of((viewUpdate) => {
        if (viewUpdate.docChanged) {
          if (viewUpdate.changes.touchesRange(start, stop)) {
            // rollback deletes, ignore create
            // rollback state
            nextTick(() => {
              input.value = props.rollback;
            });
          }
        }
      });

      // extensions
      const rego_extensions = [rego_lang(), ne(props.disableStart, props.disableStop)];

moving something along these lines to:

https://github.com/surmon-china/vue-codemirror/blob/609ef5b0425ffccd23bdf6598594cc6283d3e2bc/src/codemirror.ts#L14

based on props

Alternative

Multiple combined editors.

Additional context

No response

Validations