serdarciplak / BlazorMonaco

Blazor component for Microsoft's Monaco Editor which powers Visual Studio Code.
https://serdarciplak.github.io/BlazorMonaco/
MIT License
441 stars 99 forks source link

how to execute editor actions? #54

Closed MariaCobretti closed 2 years ago

MariaCobretti commented 2 years ago

I am trying to pragramatically execute actions specifically indenting the document, which is Shift+Alt+F looking at the documenation for the key codes i cam up with this method

monacoEditor.ActionCallback("4;6;36");

however, i am getting the exception that this key code does not exist (within an internal dictionary)

leigh-pointer commented 2 years ago

to execute commands on the editor add code to the jsInterop.js: //This example formats the document

formatDocument: function (id) {
    let editor = this.getEditorById(id);
    editor.trigger('anyString', 'editor.action.formatDocument');
},

// In the MonacoEditor.razor add public async Task formatDocument() { await jsRuntime.InvokeVoidAsync("blazorMonaco.editor.formatDocument", Id); }

// List of all commands "actions.find", "actions.findWithSelection", "cursorRedo", "cursorUndo", "deleteAllLeft", "deleteAllRight", "editor.action.addCommentLine", "editor.action.addCursorsToBottom", "editor.action.addCursorsToTop", "editor.action.addSelectionToNextFindMatch", "editor.action.addSelectionToPreviousFindMatch", "editor.action.blockComment", "editor.action.clipboardCopyWithSyntaxHighlightingAction", "editor.action.commentLine", "editor.action.copyLinesDownAction", "editor.action.copyLinesUpAction", "editor.action.deleteLines", "editor.action.detectIndentation", "editor.action.duplicateSelection", "editor.action.fontZoomIn", "editor.action.fontZoomOut", "editor.action.fontZoomReset", "editor.action.formatDocument", "editor.action.formatSelection", "editor.action.gotoLine", "editor.action.goToReferences", "editor.action.indentationToSpaces", "editor.action.indentationToTabs", "editor.action.indentLines", "editor.action.indentUsingSpaces", "editor.action.indentUsingTabs", "editor.action.inPlaceReplace.down", "editor.action.inPlaceReplace.up", "editor.action.insertCursorAbove", "editor.action.insertCursorAtEndOfEachLineSelected", "editor.action.insertCursorBelow", "editor.action.insertLineAfter", "editor.action.insertLineBefore", "editor.action.inspectTokens", "editor.action.joinLines", "editor.action.jumpToBracket", "editor.action.marker.next", "editor.action.marker.nextInFiles", "editor.action.marker.prev", "editor.action.marker.prevInFiles", "editor.action.moveCarretLeftAction", "editor.action.moveCarretRightAction", "editor.action.moveLinesDownAction", "editor.action.moveLinesUpAction", "editor.action.moveSelectionToNextFindMatch", "editor.action.moveSelectionToPreviousFindMatch", "editor.action.nextMatchFindAction", "editor.action.nextSelectionMatchFindAction", "editor.action.onTypeRename", "editor.action.openLink", "editor.action.outdentLines", "editor.action.peekDefinition", "editor.action.previousMatchFindAction", "editor.action.previousSelectionMatchFindAction", "editor.action.quickCommand", "editor.action.quickFix", "editor.action.quickOutline", "editor.action.refactor", "editor.action.referenceSearch.trigger", "editor.action.reindentlines", "editor.action.reindentselectedlines", "editor.action.removeCommentLine", "editor.action.rename", "editor.action.revealDefinition", "editor.action.revealDefinitionAside", "editor.action.selectHighlights", "editor.action.selectToBracket", "editor.action.setSelectionAnchor", "editor.action.showAccessibilityHelp", "editor.action.showContextMenu", "editor.action.showDefinitionPreviewHover", "editor.action.showHover", "editor.action.smartSelect.expand", "editor.action.smartSelect.shrink", "editor.action.sortLinesAscending", "editor.action.sortLinesDescending", "editor.action.sourceAction", "editor.action.startFindReplaceAction", "editor.action.toggleHighContrast", "editor.action.toggleTabFocusMode", "editor.action.transformToLowercase", "editor.action.transformToTitlecase", "editor.action.transformToUppercase", "editor.action.transpose", "editor.action.transposeLetters", "editor.action.triggerParameterHints", "editor.action.triggerSuggest", "editor.action.trimTrailingWhitespace", "editor.action.wordHighlight.trigger", "editor.fold", "editor.foldAll", "editor.foldAllBlockComments", "editor.foldAllMarkerRegions", "editor.foldLevel1", "editor.foldLevel2", "editor.foldLevel3", "editor.foldLevel4", "editor.foldLevel5", "editor.foldLevel6", "editor.foldLevel7", "editor.foldRecursively", "editor.toggleFold", "editor.unfold", "editor.unfoldAll", "editor.unfoldAllMarkerRegions", "editor.unfoldRecursively"