How to use the monaco-editor.Selection function in monaco-editor

To help you get started, we’ve selected a few monaco-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mattgodbolt / compiler-explorer / static / panes / compiler.js View on Github external
var label = this.getLabelAtPosition(position);

    if (!label) {
        return;
    }

    var labelDefLineNum = this.labelDefinitions[label.name];
    if (!labelDefLineNum) {
        return;
    }

    // Highlight the new range.
    var endLineContent =
        this.outputEditor.getModel().getLineContent(labelDefLineNum);

    this.outputEditor.setSelection(new monaco.Selection(
        labelDefLineNum, 0,
        labelDefLineNum, endLineContent.length + 1));

    // Jump to the given line.
    this.outputEditor.revealLineInCenter(labelDefLineNum);
};
github gitlabhq / gitlabhq / spec / frontend / ide / lib / editor_spec.js View on Github external
it('sets cursor to end of the replaced string', () => {
      const selection = editor.getSelection();
      expect(selection).toEqual(new Selection(1, 10, 1, 10));
    });
  });
github open-rpc / playground / src / MonacoJSONEditor.js View on Github external
const options = {
      language: 'json',
      theme: 'vs-dark',
      options: {
        formatOnType: true,
        formatOnPaste: true,
        autoIndent: true
      }
    }

    this.editorInstance = monaco.editor.create(this.monaco.current, {
      ...options
    });

    this.editorInstance.setModel(model);
    this.editorInstance.setSelection(new monaco.Selection(3,13,3,13));

    this.editorInstance.focus();
    window.onresize = () => this.editorInstance.layout();
    setTimeout(() => this.editorInstance.layout(), 1000);
    this.editorInstance.onDidChangeModelContent(() => {
      const changedSchema = this.editorInstance.getValue();
      window.localStorage.setItem('schema', changedSchema);
      this.props.onChange(changedSchema);
    });
    this.addCommands(this.editorInstance);
  }
  addCommands(editor) {
github Coding / WebIDE-Frontend / app / components / MonacoEditor / state.js View on Github external
range: content,
              text: '',
              forceMoveMarkers: false,
            }])
            break
          }
          case 'accept-both':
          default:
            break
        }
      }
    })

    if (props.selection) {
      const { startLineNumber, startColumn } = props.selection
      const selection = new monaco.Selection(startLineNumber, startColumn, startLineNumber, startColumn)
      this.selection = selection
      monacoEditor.setSelection(selection)
      monacoEditor.revealLineInCenter(startLineNumber, 1)
    }

    monacoEditor._editorInfo = this
    this.monacoEditor = monacoEditor

    if (props.debug) {
      this.setDebugDeltaDecorations()
    }

    if (containsConflict(this.content)) {
      this.containsConflict = true
      if (hasCache(this.filePath)) {
        this.conflicts = cacheConflicts.get(this.filePath)
github open-rpc / playground / src / MonacoJSONEditor.tsx View on Github external
const options = {
      language: "json",
      options: {
        autoIndent: true,
        formatOnPaste: true,
        formatOnType: true,
      },
      theme: this.props.uiSchema.appBar["ui:darkMode"] ? "vs-dark" : "vs",
    };

    if (this.monaco && this.monaco.current) {
      this.editorInstance = monaco.editor.create(this.monaco.current, {
        ...options,
      });
      this.editorInstance.setModel(model);
      this.editorInstance.setSelection(new monaco.Selection(4, 13, 4, 13));

      this.editorInstance.focus();
      window.onresize = () => this.editorInstance && this.editorInstance.layout();
      setTimeout(() => this.editorInstance && this.editorInstance.layout(), 1000);

      this.editorInstance.onDidChangeModelContent(() => {
        const changedSchema = this.editorInstance && this.editorInstance.getValue();
        if (changedSchema) {
          window.localStorage.setItem("schema", changedSchema);
          this.props.onChange(changedSchema);
        }
      });
      this.props.onCreate(this.editorInstance);
    }

    this.addCommands(this.editorInstance);
github mattgodbolt / compiler-explorer / static / panes / editor.js View on Github external
setTimeout(_.bind(function () {
            this.editor.setSelection(new monaco.Selection(1, 1, 1, 1));
            this.editor.focus();
            this.editor.getAction("editor.fold").run();
            this.editor.clearSelection();
        }, this), 500);
    }
github open-rpc / playground / src / hooks / useMonacoModel.tsx View on Github external
enableSchemaRequest: true,
        schemas: [
          {
            fileMatch: ["*"],
            schema,
            uri: modelUri.toString(),
          },
        ],
        validate: true,
      });
      m.updateOptions({ tabSize: 2 });
      setModel(m);
      editor.setModel(m);
      const [selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn] = position;
      editor.setSelection(
        new monaco.Selection(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn),
      );
      editor.focus();
    }

    return () => {
      if (model) {
        model.dispose();
      }
    };
  }, [editor, schema]);
  return [model, setPosition];