monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

Trigger the Command Palette and seed its string programmatically

Open nmanumr opened this issue 9 years ago • 7 comments

i want to trigger action bar dynamically through javascript.

how can i do that??

nmanumr avatar Sep 18 '16 02:09 nmanumr

@naumanumer What do you mean by action bar? The context menu? The F1 list? Or something else?

alexdima avatar Sep 19 '16 12:09 alexdima

The F1 list (Command Palette).

nmanumr avatar Sep 19 '16 15:09 nmanumr

editor.trigger('anyString', 'editor.action.quickCommand') should do it.

alexdima avatar Sep 20 '16 07:09 alexdima

Is there a way to auto-populate the quick command search bar when opening it? Something like:

editor.trigger('anyString', 'editor.action.quickCommand', {
  initialSearch: 'Initial search term',
});

bradenhs avatar Jan 19 '17 07:01 bradenhs

@bradenhs No API of that sort at this time. PR welcome.

alexdima avatar Jan 21 '17 00:01 alexdima

@nmanumr A bit hacky solution, but it one that work, is to simply change the value of the <input /> and trigger an input event on it.

editor.focus(); // Editor needs focus to be able to trigger command
editor.trigger("", "editor.action.quickCommand", ""); // Opens the quickcommand
const input = document.querySelector(".quick-input-box .input"); // Gets the quickcommand input
input.value = "> Your search string"; // Change the input value
input.dispatchEvent(new Event("input", { bubbles: true })); // Trigger an input event, for the search to register the new input value

Bjornnyborg avatar Apr 21 '22 14:04 Bjornnyborg

Hi to all, I am writing this comment here since it was the place or thread I found I thought it was appropriate to what I am looking for. I would like to append some text to the editor after a suggestion has been selected. i.e. if a open element tag is inserted from the suggestion list, I would create the respective closing tag and insert it. pseudo code: insert "</" + tagname + ">". I am trying to learn how to use this tool. I am very new at it.

I really appreciate your help.

bobajc avatar Jun 04 '22 14:06 bobajc

We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding, and happy coding!

hediet avatar Feb 24 '23 10:02 hediet