surmon-china / vue-codemirror

@codemirror code editor component for @vuejs

Home Page:https://github.surmon.me/vue-codemirror

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

nkreiger opened this issue · comments

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:

export const createEditorState = ({ onUpdate, onChange, onFocus, onBlur, ...config }: CreateStateOptions) => {

based on props

Alternative

Multiple combined editors.

Additional context

No response

Validations

  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.