From 10896146cf2152ceaa57dab2989d2ac4dc3fc396 Mon Sep 17 00:00:00 2001 From: Oleh Omelchenko Date: Sat, 25 Jan 2025 21:22:37 +0200 Subject: [PATCH] feat: integrate Monaco editor for enhanced comment editing in modal --- index.html | 4 ++-- src/UIManager.js | 12 +++++++----- src/main.js | 11 +++++++++++ src/styles.css | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 4c58ba4..7598fce 100644 --- a/index.html +++ b/index.html @@ -65,8 +65,8 @@
-

Comment Content Editor

- +

Comment Content Editor

+
diff --git a/src/UIManager.js b/src/UIManager.js index 7831d9d..d4b1a1e 100644 --- a/src/UIManager.js +++ b/src/UIManager.js @@ -14,7 +14,8 @@ export class UIManager { this.setupEventListener('export-snippets', 'onclick', () => this.snippetManager.storageManager.exportSnippets()); this.setupEventListener('import-snippets', 'onclick', () => document.getElementById('import-file').click()); this.setupEventListener('import-file', 'onchange', (e) => this.handleImport(e)); - this.setupEventListener('comment-modal-background', 'onclick', () => this.closeCommentModal()); + this.setupEventListener('comment-modal-background', 'onclick', () => this.saveComment()); + this.setupEventListener('save-comment', 'onclick', () => this.saveComment()); } setupEventListener(elementId, event, handler) { @@ -105,18 +106,19 @@ export class UIManager { const snippet = this.snippetManager.snippets.find(s => s.id === snippetId); if (!snippet) return; - const commentTextarea = document.getElementById('comment-textarea'); - commentTextarea.value = snippet.comment || ''; + const commentEditor = window.commentEditor; + commentEditor.setValue(snippet.comment || ''); document.getElementById('comment-modal').style.display = 'block'; document.getElementById('comment-modal-background').style.display = 'block'; + document.getElementById('comment-modal-title').textContent = `Edit comment for snippet: ${snippet.name}`; this.currentCommentSnippetId = snippetId; } saveComment() { - const commentTextarea = document.getElementById('comment-textarea'); + const commentEditor = window.commentEditor; const snippet = this.snippetManager.snippets.find(s => s.id === this.currentCommentSnippetId); if (snippet) { - snippet.comment = commentTextarea.value; + snippet.comment = commentEditor.getValue(); this.snippetManager.saveSnippetsAndUpdateUI(); } document.getElementById('comment-modal').style.display = 'none'; diff --git a/src/main.js b/src/main.js index 4292f37..f629d60 100644 --- a/src/main.js +++ b/src/main.js @@ -17,6 +17,17 @@ require(['vs/editor/editor.main'], async function () { formatOnType: true }); + // Initialize Monaco editor for comment modal + window.commentEditor = monaco.editor.create(document.getElementById('comment-editor'), { + language: 'markdown', + theme: 'vs-light', + wordWrap: 'on', + minimap: { enabled: false }, + automaticLayout: true, + formatOnPaste: true, + formatOnType: true + }); + // Fetch JSON schemas const vegaSchema = await fetch('https://vega.github.io/schema/vega/v5.json').then(response => response.json()); const vegaLiteSchema = await fetch('https://vega.github.io/schema/vega-lite/v5.json').then(response => response.json()); diff --git a/src/styles.css b/src/styles.css index bb83499..94b5cdc 100644 --- a/src/styles.css +++ b/src/styles.css @@ -269,17 +269,30 @@ border-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); z-index: 1001; + font-family: var(--ui-font); +} + +.comment-modal h2 { + font-size: 1.25rem; + font-weight: 600; + margin-bottom: 1rem; } .comment-modal textarea { width: 100%; height: calc(100% - 2rem); margin-bottom: 1rem; + font-family: var(--ui-font); + font-size: 1rem; + padding: 0.5rem; + border: 1px solid #e0e0e0; + border-radius: 4px; } .comment-modal .button { display: block; margin: 0 auto; + font-family: var(--ui-font); } .comment-modal-background { @@ -333,4 +346,10 @@ border: 1px solid #e0e0e0; border-radius: 4px; font-size: 1rem; +} + +#comment-editor { + width: 100%; + height: calc(100% - 2rem); + margin-bottom: 1rem; } \ No newline at end of file