microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
39.78k stars 3.55k forks source link

Provide configuration for deleting trigger characters after providing pop-up lists #4329

Open git102347501 opened 8 months ago

git102347501 commented 8 months ago

Context

Description

I hope that after entering @, a dropdown list will pop up for selection. After selection, the @ symbol needs to be removed, similar to: selecting test from the @ dropdown, and ultimately staying in the editor is test instead of @ test

Monaco Editor Playground Link

demo

Monaco Editor Playground Code

const value = /* set from `myEditor.getModel()`: */ `@`;

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
    value: "",
    language: "sql"
});

monaco.languages.registerCompletionItemProvider('sql', {
      triggerCharacters: ['@'],
      provideCompletionItems: (model, position) => {
        let suggestions = [{label: "test", kind: "test", insertText: "test"}];
        return { suggestions };
      }
    }
);
git102347501 commented 8 months ago
monaco.languages.registerCompletionItemProvider('sql', {
      triggerCharacters: ['@'],
      replaceTriggerChar: true, // For example, if this configuration is enabled, @ will be replaced
      provideCompletionItems: (model, position) => {
        let suggestions = [{label: "test", kind: "test", insertText: "test"}];
        return { suggestions };
      }
    }
);