UNPKG

@kusto/monaco-kusto

Version:

CSL, KQL plugin for the Monaco Editor

72 lines (71 loc) 2.97 kB
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; /** * Registers a Kusto-specific action to close the IntelliSense suggestions popup. * * Note: * We register the action on the first cursor movement, not on editor creation, * because Monaco fires 'onDidCreateEditor' before the keybinding service is fully initialized. * Waiting for a cursor event guarantees that the editor is fully ready * and allows safe registration of actions with keybindings. */ var CaseInvertor = /** @class */ (function () { function CaseInvertor(editor) { var _this = this; this.editor = editor; this.actionsRegistered = false; this.ctrlKeyMod = this.isMac() ? monaco.KeyMod.WinCtrl : monaco.KeyMod.CtrlCmd; this.editor.onDidChangeCursorSelection(function () { var _a; if (((_a = _this.editor.getModel()) === null || _a === void 0 ? void 0 : _a.getLanguageId()) !== 'kusto') { return; } if (!_this.actionsRegistered) { _this.registerUpperCaseHandler(); _this.registerLowerCaseHandler(); _this.actionsRegistered = true; } }); } CaseInvertor.prototype.registerUpperCaseHandler = function () { this.editor.addAction({ id: 'kusto.toUpperCase', label: 'To Upper Case', keybindings: [this.ctrlKeyMod | monaco.KeyMod.Shift | monaco.KeyCode.KeyU], run: function (editor) { var selectedRange = editor.getSelection(); var selectedText = editor.getModel().getValueInRange(selectedRange); var upperCaseText = selectedText.toUpperCase(); editor.executeEdits('toUpperCase', [ { range: selectedRange, text: upperCaseText, }, ]); }, }); }; CaseInvertor.prototype.registerLowerCaseHandler = function () { this.editor.addAction({ id: 'kusto.toLowerCase', label: 'To Lower Case', keybindings: [this.ctrlKeyMod | monaco.KeyMod.Shift | monaco.KeyCode.KeyL], run: function (editor) { var selectedRange = editor.getSelection(); var selectedText = editor.getModel().getValueInRange(selectedRange); var lowerCaseText = selectedText.toLowerCase(); editor.executeEdits('toLowerCase', [ { range: selectedRange, text: lowerCaseText, }, ]); }, }); }; CaseInvertor.prototype.isMac = function () { var uaData = navigator.userAgentData; return uaData ? uaData.platform === 'macOS' : /Mac|iPod|iPhone|iPad/.test(navigator.platform); }; return CaseInvertor; }()); export default CaseInvertor;