From 43dbba9ffe2477df5c14fb5f9b94b8fbbd9d1881 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Tue, 24 Jun 2025 00:07:56 -0300 Subject: [PATCH] fix(SNOTES-473): code editor fixes --- packages/org.standardnotes.code-editor/index.html | 11 ++++------- packages/org.standardnotes.code-editor/src/main.js | 14 +++++++++++--- .../org.standardnotes.code-editor/src/main.scss | 4 ++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/org.standardnotes.code-editor/index.html b/packages/org.standardnotes.code-editor/index.html index b043623f..356e3f7a 100644 --- a/packages/org.standardnotes.code-editor/index.html +++ b/packages/org.standardnotes.code-editor/index.html @@ -28,32 +28,29 @@ -
-
+
Language:
- +
- Set as Default + Set as Default
- Enable Vim mode + Enable Vim mode
diff --git a/packages/org.standardnotes.code-editor/src/main.js b/packages/org.standardnotes.code-editor/src/main.js index 7d6d9468..8e379f1e 100644 --- a/packages/org.standardnotes.code-editor/src/main.js +++ b/packages/org.standardnotes.code-editor/src/main.js @@ -1,3 +1,5 @@ +CodeMirror.modeURL = "dist/codemirror/mode/%N/%N.js"; + document.addEventListener('DOMContentLoaded', function () { const modeByModeMode = CodeMirror.modeInfo.reduce(function (acc, m) { if (acc[m.mode]) { @@ -163,13 +165,15 @@ document.addEventListener('DOMContentLoaded', function () { updateVimStatus(keymap) } - window.onLanguageSelect = function () { + function onLanguageSelect() { const language = modes[select.selectedIndex] changeMode(language) saveNote() } - window.setDefaultLanguage = function () { + document.getElementById('language-select').addEventListener('change', onLanguageSelect) + + function setDefaultLanguage() { const language = modes[select.selectedIndex] // assign default language for this editor when entering notes @@ -187,6 +191,8 @@ document.addEventListener('DOMContentLoaded', function () { }, 750) } + document.getElementById('default-label').addEventListener('click', setDefaultLanguage) + function inputModeToMode(inputMode) { const convertCodeMirrorMode = function (codeMirrorMode) { if (codeMirrorMode) { @@ -260,7 +266,7 @@ document.addEventListener('DOMContentLoaded', function () { toggleButton.classList.add(buttonClass) } - window.toggleVimMode = function () { + function toggleVimMode() { let newKeyMap const currentKeyMap = componentRelay.getComponentDataValueForKey('keyMap') ?? 'default' @@ -274,6 +280,8 @@ document.addEventListener('DOMContentLoaded', function () { componentRelay.setComponentDataValueForKey('keyMap', newKeyMap) } + document.getElementById('toggle-vim-mode-button').addEventListener('click', toggleVimMode) + function getInputStyleForEnvironment() { const environment = componentRelay.environment ?? 'web' return environment === 'mobile' ? 'textarea' : 'contenteditable' diff --git a/packages/org.standardnotes.code-editor/src/main.scss b/packages/org.standardnotes.code-editor/src/main.scss index a08d241e..5998b16b 100644 --- a/packages/org.standardnotes.code-editor/src/main.scss +++ b/packages/org.standardnotes.code-editor/src/main.scss @@ -103,3 +103,7 @@ body, html { .cm-fat-cursor .CodeMirror-line > span[role="presentation"] { caret-color: transparent; } + +#bar { + width: inherit; +}