How to use the monaco-editor.editor 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 / editor.js View on Github external
var widgets = _.compact(_.map(output, function (obj) {
        if (!obj.tag) return;
        var severity = 3; // error
        if (obj.tag.text.match(/^warning/)) severity = 2;
        if (obj.tag.text.match(/^note/)) severity = 1;
        return {
            severity: severity,
            message: obj.tag.text,
            source: compiler.name + ' #' + compilerId,
            startLineNumber: obj.tag.line,
            startColumn: obj.tag.column || 0,
            endLineNumber: obj.tag.line,
            endColumn: obj.tag.column ? -1 : Infinity
        };
    }, this));
    monaco.editor.setModelMarkers(this.editor.getModel(), compilerId, widgets);
    this.decorations.tags = _.map(widgets, function (tag) {
        return {
            range: new monaco.Range(tag.startLineNumber, tag.startColumn, tag.startLineNumber + 1, 1),
            options: {
                isWholeLine: false,
                inlineClassName: "error-code"
            }
        };
    }, this);
    this.updateDecorations();
    this.asmByCompiler[compilerId] = result.asm;
    this.numberUsedLines();
};
github ggoodman / velcro / packages / playground / src / lib / hooks.ts View on Github external
export function useDirectory(uri: Monaco.Uri) {
  // Make sure the URI always ends with a trailing slash
  const prefix = uri.toString(true).replace(/\/?$/, '/');
  const sortEntries = (models: (DirectoryEntry)[]) => {
    return [...models].sort((a, b) => (a.uri.fsPath > b.uri.fsPath ? 1 : -1));
  };

  const initialEntries = sortEntries(
    Monaco.editor.getModels().reduce(
      (entries, model) => {
        const modelUri = model.uri.toString(true);

        if (modelUri.startsWith(prefix)) {
          const nestedPath = modelUri.slice(prefix.length);
          const nextDirIdx = nestedPath.indexOf('/');

          if (nextDirIdx === 0) {
            throw new Error('Invariant error: WAT?');
          }

          if (nextDirIdx > 0) {
            // This is an intermediate directory
            const uri = Monaco.Uri.parse(`${prefix}${nestedPath.slice(0, nextDirIdx + 1)}`);

            entries.push({
github heremaps / harp-map-editor / src / text-editor-frame / TextEditor.ts View on Github external
type Commands = WindowCommands["command"];

/**
 * This class controls the monaco editor and communicate thru messages with the Theme editor.
 */
export class TextEditor extends EventEmitter {
    /**
     * The macro editor instance
     */
    private m_decorations: string[] = [];
    private m_editor: monaco.editor.IStandaloneCodeEditor | null = null;
    private m_monacoNotifications: Notification[] = [];
    private m_editorElem: HTMLElement | null = null;

    private m_modelUri = monaco.Uri.parse("a:/harp.gl/default.theme.json");
    private m_model = monaco.editor.createModel("", "json", this.m_modelUri);

    init() {
        this.m_editorElem = document.createElement("div");

        monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
            validate: true,
            schemas: [
                {
                    uri: "https://github.com/heremaps/harp.gl/theme.scheme.json",
                    fileMatch: [".theme.json"],
                    schema
                }
            ]
        });

        this.m_editor = monaco.editor.create(this.m_editorElem, {
github Coding / WebIDE-Frontend / app / components / MonacoEditor / state.js View on Github external
createMonacoEditorInstance (props) {
    this.monacoElement = document.createElement('div')
    this.monacoElement.style.width = '100%'
    this.monacoElement.style.height = '100%'

    if (this.filePath) {
      this.languageMode = findLanguageByextensions(this.filePath.split('.').pop()).id
    }

    const model = monaco.editor.getModel(
      monaco.Uri.parse(this.uri).toString())
      || monaco.editor.createModel(this.content || '', this.languageMode, monaco.Uri.parse(this.uri)
    )
    this.uri = model.uri._formatted
    const monacoEditor = monaco.editor.create(this.monacoElement, {
      ...initialOptions,
      ...props,
      model,
    }, {
      editorService: {
        openEditor: toDefinition
      }
    })

    this.disposers.push(observe(this, 'content', (change) => {
      const content = change.newValue || ''
      if (content !== monacoEditor.getValue()) {
        monacoEditor.setValue(content)
github mattgodbolt / compiler-explorer / static / panes / tool.js View on Github external
this.toolName = "Tool";
    this.compilerService = hub.compilerService;
    this.eventHub = hub.createEventHub();
    this.domRoot = container.getElement();
    this.domRoot.html($('#tool-output').html());
    this.editorContentRoot = this.domRoot.find('.monaco-placeholder');
    this.plainContentRoot = this.domRoot.find('pre.content');
    this.optionsToolbar = this.domRoot.find('.options-toolbar');
    this.compilerName = "";
    this.normalAnsiToHtml = makeAnsiToHtml();
    this.errorAnsiToHtml = makeAnsiToHtml('red');

    this.optionsField = this.domRoot.find('input.options');
    this.stdinField = this.domRoot.find('textarea.tool-stdin');

    this.outputEditor = monaco.editor.create(this.editorContentRoot[0], {
        scrollBeyondLastLine: false,
        readOnly: true,
        language: 'text',
        fontFamily: "courier new",
        glyphMargin: true,
        fixedOverflowWidgets: true,
        minimap: {
            maxColumn: 80
        },
        lineNumbersMinChars: 5,
        renderIndentGuides: false
    });

    this.fontScale = new FontScale(this.domRoot, state, ".content,.monaco-editor");
    this.fontScale.on('change', _.bind(function () {
        this.saveState();
github mattgodbolt / compiler-explorer / static / panes / compiler.js View on Github external
this.wantOptInfo = state.wantOptInfo;
    this.decorations = {};
    this.prevDecorations = [];
    this.labelDefinitions = {};
    this.alertSystem = new Alert();
    this.alertSystem.prefixMessage = "Compiler #" + this.id + ": ";

    this.awaitingInitialResults = false;
    this.selection = state.selection;

    this.linkedFadeTimeoutId = -1;
    this.toolsMenu = null;

    this.initButtons(state);

    this.outputEditor = monaco.editor.create(this.monacoPlaceholder[0], {
        scrollBeyondLastLine: false,
        readOnly: true,
        language: languages[this.currentLangId].monacoDisassembly || 'asm',
        fontFamily: this.settings.editorsFFont,
        glyphMargin: !options.embedded,
        fixedOverflowWidgets: true,
        minimap: {
            maxColumn: 80
        },
        lineNumbersMinChars: 1,
        renderIndentGuides: false,
        fontLigatures: this.settings.editorsFLigatures
    });

    this.codeLensProvider = null;
    this.fontScale = new FontScale(this.domRoot, state, this.outputEditor);
github mattgodbolt / compiler-explorer / static / panes / editor.js View on Github external
this.fadeTimeoutId = -1;

    this.editorSourceByLang = {};
    this.alertSystem = new Alert();
    this.alertSystem.prefixMessage = "Editor #" + this.id + ": ";

    this.awaitingInitialResults = false;
    this.selection = state.selection;

    this.langKeys = _.keys(languages);
    this.initLanguage(state);

    var root = this.domRoot.find(".monaco-placeholder");
    var legacyReadOnly = state.options && !!state.options.readOnly;
    this.editor = monaco.editor.create(root[0], {
        scrollBeyondLastLine: false,
        language: this.currentLanguage.monaco,
        fontFamily: this.settings.editorsFFont,
        readOnly: !!options.readOnly || legacyReadOnly,
        glyphMargin: !options.embedded,
        quickSuggestions: false,
        fixedOverflowWidgets: true,
        minimap: {
            maxColumn: 80
        },
        folding: true,
        lineNumbersMinChars: 1,
        emptySelectionClipboard: true,
        autoIndent: true,
        vimInUse: this.settings.useVim,
        fontLigatures: this.settings.editorsFLigatures
github mayuki / Rin / src / Rin.Frontend / src / components / inspector / InspectorDetail.RequestResponseView.tsx View on Github external
const body = props.isBase64Encoded ? convertBase64StringToUint8Array(props.body) : props.body;
  const hexed = hexy(body, { format: 'twos', caps: 'upper' }).trimEnd();

  return (
    
  );
}

monacoEditor.editor.defineTheme('rin-hex-dump', {
  base: 'vs',
  colors: {},
  rules: [{ token: 'address-token', foreground: 'aaaaaa' }],
  inherit: true,
});
monacoEditor.languages.register({ id: 'text/x-rin-hex-dump' });
monacoEditor.languages.setMonarchTokensProvider('text/x-rin-hex-dump', {
  tokenizer: {
    root: [[/^[0-9a-fA-F]+:/, 'address-token']],
  },
});

function EditorPreview(props: {
  contentType: string;
  body: string;
  paneResizeToken: number;
github nxtedition / create-caspar-graphics / packages / caspar-graphics / lib / preview / editor.js View on Github external
{ token: 'type', foreground: '008080' },

    { token: 'delimiter', foreground: '111111' },
    { token: 'string.key.json', foreground: '717070' },
    { token: 'string.value.json', foreground: '111111' },
    { token: 'string', foreground: '525252' },
    { token: 'keyword', foreground: '0000FF' },
    { token: 'keyword.json', foreground: '000000', fontStyle: 'bold' }
  ],
  colors: {
    'editor.background': '#ffffff',
    'editor.foreground': '#000000'
  }
}

monaco.editor.defineTheme('custom', theme)

export default class Editor extends Component {
  containerElement = React.createRef()
  editor = null

  componentDidMount = () => {
    this.editor = monaco.editor.create(this.containerElement.current, {
      value: JSON.stringify(this.props.value || {}, null, 2),
      language: 'json',
      theme: 'custom',
      lineNumbers: 'off',
      lineDecorationsWidth: 0,
      folding: false,
      glyphMargin: false,
      hideCursorInOverviewRuler: true,
      highlightActiveIndentGuide: false,
github Coding / WebIDE-Frontend / app / components / MonacoEditor / state.js View on Github external
getPosition: () => ({
          position: {
            lineNumber: startLineNumber - 1,
            column: 1,
          },
          preference: [monaco.editor.ContentWidgetPositionPreference.BELOW]
        })
      }