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

actions.find not amongst supportedActions anymore

Open momesana opened this issue 5 years ago • 9 comments

Hiding the find widget via editor.trigger('', 'actions.find') or editor.getAction('actions.find).run() stopped working with Monaco editor 0.22.0 and later versions. editor.supportedActions(); also doesn't list it anymore though it does for monaco versions older than 0.22.0 (notably 0.21.3). Has it been removed intentionally or is this just a bug? Also, I see that using the ctrl+f shortcut still triggers the action with 'actions.find' as the id and the entry in findModel.js is also still present and being registered in the findController. It just seems like it is not exposed anymore. What's the alternative if it has been removed intentionally?

Thanks in advance

monaco-editor version: 0.22.0 - 0.22.3 Browser: OS: Playground code that reproduces the issue:

var editor = monaco.editor.create(document.getElementById("container"), {
	value: `console.log("where is da good ol' actions.find");`,
	language: "typescript"
});
editor.trigger('', 'actions.find'); // actions.findWithSelection however works

Edit: https://github.com/microsoft/vscode/commit/979f9f73b3d5cd55356c0117be169fb1edbfd92b introduced a new precondition (editorIsOpen) which is not set in the browser. Therefore the isSupported method of the IEditorAction returns false and the action is never executed.

momesana avatar Feb 17 '21 04:02 momesana

invoking editor.createContextKey('editorIsOpen', true) after constructing the editor fixes it. I do however think that this should be the default for browsers.

momesana avatar Feb 23 '21 20:02 momesana

invoking editor.createContextKey('editorIsOpen', true) after constructing the editor fixes it. I do however think that this should be the default for browsers.

Anas198900 avatar Feb 25 '21 04:02 Anas198900

Looks like it is caused by https://github.com/microsoft/vscode/commit/979f9f73b3d5cd55356c0117be169fb1edbfd92b . It looks like the find action has as precondition a context key (editorIsOpen) that is only defined in the /workbench/ layer. That doesn't make sense to me.

alexdima avatar Feb 26 '21 13:02 alexdima

@alexdima When will this be released?

JounQin avatar Mar 02 '21 15:03 JounQin

Digging into this it looks like the action only triggers now if editorFocus is true in the context. As a workaround, I was able to focus the editor before triggering the action and it works, eg:

      editor.focus();
      editor.trigger('toggleFind', 'actions.find');

mofojed avatar Mar 05 '21 14:03 mofojed

The getActiveCodeEditor implementation in StandaloneCodeServiceImpl always returns null:

getActiveCodeEditor() {
    return null; // not supported in the standalone case
}

Is editor.focus(); really the way to go now or will there be a way to programmatically tell monaco that the editor is always active? I think the current behaviour makes sense for vscode but not in the context of a monaco instance run in a browser.

momesana avatar Mar 05 '21 20:03 momesana

@alexdima

I still have this issue on 0.23.0 even with editor.createContextKey('editorIsOpen', true) while 0.22.3 works with this trick.

JounQin avatar Mar 08 '21 03:03 JounQin

Hey @lramos15 it looks like you might be doing something weird with git and closing issues by accident

alexdima avatar Mar 08 '21 15:03 alexdima

Just my 2 cents.

0.23 equivalent to 0.22

editor.setSelection(selection)
editor.getAction('actions.find').run();

is:

editor.setSelection(selection);
editor.focus();
editor.getAction('actions.find').run();
editor.revealLineInCenter(selection.positionLineNumber);

Don't know if the autofocus removal was intentional.

bworwa avatar Mar 13 '21 05:03 bworwa