From be9368e8a2d6be6625b1f55eaf62e8f82a5b587c Mon Sep 17 00:00:00 2001 From: dtricks Date: Fri, 3 Oct 2025 17:57:58 +0200 Subject: [PATCH 1/7] feat(codemirror): add Vim :w evaluate, :q stop, and gc/gcc toggle comment via custom events; docs: add Vim shortcuts page and link from REPL manual --- packages/codemirror/codemirror.mjs | 42 +++++- packages/codemirror/keybindings.mjs | 139 +++++++++++++++++--- website/src/pages/technical-manual/repl.mdx | 4 + website/src/pages/technical-manual/vim.mdx | 36 +++++ 4 files changed, 203 insertions(+), 18 deletions(-) create mode 100644 website/src/pages/technical-manual/vim.mdx diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 4dc23996f..6359609ca 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -1,4 +1,5 @@ import { closeBrackets } from '@codemirror/autocomplete'; +import { toggleLineComment } from '@codemirror/commands'; export { toggleComment, toggleBlockComment, toggleLineComment, toggleBlockCommentByLine } from '@codemirror/commands'; // import { search, highlightSelectionMatches } from '@codemirror/search'; import { indentWithTab } from '@codemirror/commands'; @@ -13,7 +14,7 @@ import { lineNumbers, drawSelection, } from '@codemirror/view'; -import { repl, registerControl } from '@strudel/core'; +import { repl, registerControl, logger } from '@strudel/core'; import { Drawer, cleanupDraw } from '@strudel/draw'; import { isAutoCompletionEnabled } from './autocomplete.mjs'; import { isTooltipEnabled } from './tooltip.mjs'; @@ -245,6 +246,32 @@ export class StrudelMirror { } }; document.addEventListener('start-repl', this.onStartRepl); + + // Handle global evaluation requests (e.g., from Vim :w) + this.onEvaluateRequest = (e) => { + try { + // Evaluate current editor on repl-evaluate + logger('[repl] evaluate via event'); + this.evaluate(); + e?.cancelable && e.preventDefault?.(); + } catch (err) { + console.error('Error handling repl-evaluate event', err); + } + }; + document.addEventListener('repl-evaluate', this.onEvaluateRequest); + document.addEventListener('repl-stop', this.onStopRequest); + + // Toggle comments requested from Vim (gc/gcc) + this.onToggleComment = (e) => { + try { + // Honor selections; toggleLineComment handles both selections and single line + toggleLineComment(this.editor); + e?.cancelable && e.preventDefault?.(); + } catch (err) { + console.error('Error handling repl-toggle-comment event', err); + } + }; + document.addEventListener('repl-toggle-comment', this.onToggleComment); } draw(haps, time, painters) { painters?.forEach((painter) => painter(this.drawContext, time, haps, this.drawTime)); @@ -271,6 +298,16 @@ export class StrudelMirror { async stop() { this.repl.scheduler.stop(); } + + // Listen for global stop requests (e.g., from Vim :q) + onStopRequest = (e) => { + try { + this.stop(); + e?.cancelable && e.preventDefault?.(); + } catch (err) { + console.error('Error handling repl-stop event', err); + } + }; async toggle() { if (this.repl.scheduler.started) { this.repl.stop(); @@ -351,6 +388,9 @@ export class StrudelMirror { } clear() { this.onStartRepl && document.removeEventListener('start-repl', this.onStartRepl); + this.onEvaluateRequest && document.removeEventListener('repl-evaluate', this.onEvaluateRequest); + this.onStopRequest && document.removeEventListener('repl-stop', this.onStopRequest); + this.onToggleComment && document.removeEventListener('repl-toggle-comment', this.onToggleComment); } getCursorLocation() { return this.editor.state.selection.main.head; diff --git a/packages/codemirror/keybindings.mjs b/packages/codemirror/keybindings.mjs index ca5f34f4c..7de2a7238 100644 --- a/packages/codemirror/keybindings.mjs +++ b/packages/codemirror/keybindings.mjs @@ -1,32 +1,137 @@ -import { Prec } from '@codemirror/state'; -import { keymap, ViewPlugin } from '@codemirror/view'; +import {defaultKeymap} from '@codemirror/commands'; +import {Prec} from '@codemirror/state'; +import {keymap, ViewPlugin} from '@codemirror/view'; // import { searchKeymap } from '@codemirror/search'; -import { emacs } from '@replit/codemirror-emacs'; -import { vim } from '@replit/codemirror-vim'; +import {emacs} from '@replit/codemirror-emacs'; +import {vim, Vim} from '@replit/codemirror-vim'; +import { logger } from '@strudel/core'; // import { vim } from './vim_test.mjs'; -import { vscodeKeymap } from '@replit/codemirror-vscode-keymap'; -import { defaultKeymap } from '@codemirror/commands'; +import {vscodeKeymap} from '@replit/codemirror-vscode-keymap'; const vscodePlugin = ViewPlugin.fromClass( - class { - constructor() {} - }, - { - provide: () => { - return Prec.highest(keymap.of([...vscodeKeymap])); + class { + constructor() {} + }, + { + provide : () => { return Prec.highest(keymap.of([...vscodeKeymap ])); }, }, - }, ); const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []); +// Map Vim :w to trigger the same action as evaluation. We dispatch a custom +// event 'repl-evaluate' that the editor listens for, and also simulate +// Ctrl+Enter/Alt+Enter as a fallback. We log to the Strudel logger so it +// appears in the Console panel. +try { + if (Vim && typeof Vim.defineEx === 'function') { + // Map gc/gcc to toggle line comments by dispatching a custom event that our + // CodeMirror integration listens to. This avoids depending on Vim's internal + // actions and works with current selections/visual mode. + try { + Vim.defineAction('strudelToggleComment', (cm) => { + const view = cm?.view || cm; + try { + const ev = new CustomEvent('repl-toggle-comment', { detail: { source: 'vim', view }, cancelable: true }); + document.dispatchEvent(ev); + } catch (e) { + console.error('strudelToggleComment dispatch failed', e); + } + }); + Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'normal' }); + Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'visual' }); + Vim.mapCommand('gcc', 'action', 'strudelToggleComment', {}, { context: 'normal' }); + } catch (e) { + console.error('Vim gc/gcc mapping failed', e); + } + + // :q to pause/stop + // :q to pause/stop + Vim.defineEx('quit', 'q', (cm) => { + try { + const view = cm?.view || cm; + // First try dispatching our custom stop event, then fallback to Alt+. + let handled = false; + try { + const ev = new CustomEvent('repl-stop', { detail: { source: 'vim', view }, cancelable: true }); + handled = document.dispatchEvent(ev) === false; + } catch {} + if (!handled) { + const altDot = new KeyboardEvent('keydown', { + key: '.', + code: 'Period', + altKey: true, + bubbles: true, + cancelable: true, + }); + view?.dom?.dispatchEvent?.(altDot); + } + } catch (e) { + console.error('Error dispatching :q stop event', e); + } + }); + + // :w to evaluate + // :w to evaluate + Vim.defineEx('write', 'w', (cm) => { + const view = + cm?.view || + cm; // CM6 Vim passes either an object with view or the view itself + try { + view?.focus?.(); + // Let the app know this came from Vim :w + try { + logger('[vim] :w — evaluating code'); + } catch {} + // Dispatch a dedicated evaluate event first + let handled = false; + try { + const ev = new CustomEvent('repl-evaluate', { detail: { source: 'vim', view }, cancelable: true }); + handled = document.dispatchEvent(ev) === false; // false means preventDefault was called + } catch {} + if (handled) { + return; + } + // Try Ctrl+Enter first if not handled by custom event + const ctrlEnter = new KeyboardEvent('keydown', { + key : 'Enter', + code : 'Enter', + ctrlKey : true, + bubbles : true, + cancelable : true, + }); + view?.dom?.dispatchEvent?.(ctrlEnter); + // If not handled (no handler called preventDefault), try Alt+Enter as + // fallback + if (!ctrlEnter.defaultPrevented) { + const altEnter = new KeyboardEvent('keydown', { + key : 'Enter', + code : 'Enter', + altKey : true, + bubbles : true, + cancelable : true, + }); + view?.dom?.dispatchEvent?.(altEnter); + } + } catch (e) { + console.error('Error dispatching :w evaluation event', e); + } + }); + } +} catch (e) { + console.error('Vim ex command setup failed (defineEx missing or Vim unavailable)', e); +} + const keymaps = { - vim, + vim, + // Add extra Vim keymap for gc to toggle line comment + // We will include a Vim-specific keymap that calls the CM command + // respecting the current selection. emacs, - codemirror: () => keymap.of(defaultKeymap), - vscode: vscodeExtension, + codemirror : () => keymap.of(defaultKeymap), + vscode : vscodeExtension, }; export function keybindings(name) { const active = keymaps[name]; - return [active ? Prec.high(active()) : []]; + return [ active ? Prec.high(active()) : [] ]; } diff --git a/website/src/pages/technical-manual/repl.mdx b/website/src/pages/technical-manual/repl.mdx index 8c4287af5..f74a4fb8b 100644 --- a/website/src/pages/technical-manual/repl.mdx +++ b/website/src/pages/technical-manual/repl.mdx @@ -117,6 +117,10 @@ Here's an example AST for `c3 [e3 g3]` which translates to `seq(c3, seq(e3, g3))` +## Vim Keybindings + +See the separate page on Vim shortcuts for a quick reference: [/technical-manual/vim](/technical-manual/vim) + ## Scheduling Events After an instance of `Pattern` is obtained from the user code, diff --git a/website/src/pages/technical-manual/vim.mdx b/website/src/pages/technical-manual/vim.mdx new file mode 100644 index 000000000..ec284d0bf --- /dev/null +++ b/website/src/pages/technical-manual/vim.mdx @@ -0,0 +1,36 @@ +--- +title: Vim Shortcuts +layout: ../../layouts/MainLayout.astro +--- + +# Vim Shortcuts in the REPL + +When the REPL editor (CodeMirror) is configured to use Vim keybindings, the following commands are available: + +- :w — Evaluate the current code + - Triggers the same evaluation as Ctrl+Enter / Alt+Enter + - You’ll see messages in the Console panel such as: + - [vim] :w — evaluating code + - [repl] evaluate via event + - [eval] code updated + +- :q — Stop/pause playback + - Triggers the same stop action as Alt+. + - Useful to quickly stop scheduling without leaving Vim mode + +- gc — Toggle line comments for the current selection(s) + - Works in normal and visual mode + - If there’s a selection, all selected lines are toggled + +- gcc — Toggle comment for the current line (normal mode) + +Notes + +- Behavior respects the current language mode in the editor for comment syntax. +- If multiple REPL editors are open, commands target the active editor. The implementation dispatches custom events handled by the editor. +- If you don’t see the Console panel, open the right panel in the REPL UI. + +Troubleshooting + +- If :w logs but evaluation doesn’t apply, ensure Vim keybindings are active and try again. You can also use Ctrl+Enter as a fallback. +- For :q / gc / gcc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again. From 73a98349596c68031b33b1fe44b830498faea920 Mon Sep 17 00:00:00 2001 From: dtricks Date: Fri, 3 Oct 2025 18:12:47 +0200 Subject: [PATCH 2/7] codeformat --- packages/codemirror/codemirror.mjs | 2 +- packages/codemirror/keybindings.mjs | 56 +++++++++++----------- packages/osc/server.js | 0 website/src/pages/technical-manual/vim.mdx | 3 ++ 4 files changed, 32 insertions(+), 29 deletions(-) mode change 100644 => 100755 packages/osc/server.js diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 6359609ca..f3ab3890e 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -298,7 +298,7 @@ export class StrudelMirror { async stop() { this.repl.scheduler.stop(); } - + // Listen for global stop requests (e.g., from Vim :q) onStopRequest = (e) => { try { diff --git a/packages/codemirror/keybindings.mjs b/packages/codemirror/keybindings.mjs index 7de2a7238..06aaad523 100644 --- a/packages/codemirror/keybindings.mjs +++ b/packages/codemirror/keybindings.mjs @@ -1,20 +1,22 @@ -import {defaultKeymap} from '@codemirror/commands'; -import {Prec} from '@codemirror/state'; -import {keymap, ViewPlugin} from '@codemirror/view'; +import { defaultKeymap } from '@codemirror/commands'; +import { Prec } from '@codemirror/state'; +import { keymap, ViewPlugin } from '@codemirror/view'; // import { searchKeymap } from '@codemirror/search'; -import {emacs} from '@replit/codemirror-emacs'; -import {vim, Vim} from '@replit/codemirror-vim'; +import { emacs } from '@replit/codemirror-emacs'; +import { vim, Vim } from '@replit/codemirror-vim'; import { logger } from '@strudel/core'; // import { vim } from './vim_test.mjs'; -import {vscodeKeymap} from '@replit/codemirror-vscode-keymap'; +import { vscodeKeymap } from '@replit/codemirror-vscode-keymap'; const vscodePlugin = ViewPlugin.fromClass( - class { - constructor() {} - }, - { - provide : () => { return Prec.highest(keymap.of([...vscodeKeymap ])); }, + class { + constructor() {} + }, + { + provide: () => { + return Prec.highest(keymap.of([...vscodeKeymap])); }, + }, ); const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []); @@ -73,9 +75,7 @@ try { // :w to evaluate // :w to evaluate Vim.defineEx('write', 'w', (cm) => { - const view = - cm?.view || - cm; // CM6 Vim passes either an object with view or the view itself + const view = cm?.view || cm; // CM6 Vim passes either an object with view or the view itself try { view?.focus?.(); // Let the app know this came from Vim :w @@ -93,22 +93,22 @@ try { } // Try Ctrl+Enter first if not handled by custom event const ctrlEnter = new KeyboardEvent('keydown', { - key : 'Enter', - code : 'Enter', - ctrlKey : true, - bubbles : true, - cancelable : true, + key: 'Enter', + code: 'Enter', + ctrlKey: true, + bubbles: true, + cancelable: true, }); view?.dom?.dispatchEvent?.(ctrlEnter); // If not handled (no handler called preventDefault), try Alt+Enter as // fallback if (!ctrlEnter.defaultPrevented) { const altEnter = new KeyboardEvent('keydown', { - key : 'Enter', - code : 'Enter', - altKey : true, - bubbles : true, - cancelable : true, + key: 'Enter', + code: 'Enter', + altKey: true, + bubbles: true, + cancelable: true, }); view?.dom?.dispatchEvent?.(altEnter); } @@ -122,16 +122,16 @@ try { } const keymaps = { - vim, + vim, // Add extra Vim keymap for gc to toggle line comment // We will include a Vim-specific keymap that calls the CM command // respecting the current selection. emacs, - codemirror : () => keymap.of(defaultKeymap), - vscode : vscodeExtension, + codemirror: () => keymap.of(defaultKeymap), + vscode: vscodeExtension, }; export function keybindings(name) { const active = keymaps[name]; - return [ active ? Prec.high(active()) : [] ]; + return [active ? Prec.high(active()) : []]; } diff --git a/packages/osc/server.js b/packages/osc/server.js old mode 100644 new mode 100755 diff --git a/website/src/pages/technical-manual/vim.mdx b/website/src/pages/technical-manual/vim.mdx index ec284d0bf..b18a259ec 100644 --- a/website/src/pages/technical-manual/vim.mdx +++ b/website/src/pages/technical-manual/vim.mdx @@ -8,6 +8,7 @@ layout: ../../layouts/MainLayout.astro When the REPL editor (CodeMirror) is configured to use Vim keybindings, the following commands are available: - :w — Evaluate the current code + - Triggers the same evaluation as Ctrl+Enter / Alt+Enter - You’ll see messages in the Console panel such as: - [vim] :w — evaluating code @@ -15,10 +16,12 @@ When the REPL editor (CodeMirror) is configured to use Vim keybindings, the foll - [eval] code updated - :q — Stop/pause playback + - Triggers the same stop action as Alt+. - Useful to quickly stop scheduling without leaving Vim mode - gc — Toggle line comments for the current selection(s) + - Works in normal and visual mode - If there’s a selection, all selected lines are toggled From 46ba165c7eb7375056625e837fee12ff9cef1aee Mon Sep 17 00:00:00 2001 From: dtricks Date: Fri, 3 Oct 2025 18:16:18 +0200 Subject: [PATCH 3/7] remove gcc --- packages/codemirror/codemirror.mjs | 60 ++++++++++++---------- packages/codemirror/keybindings.mjs | 11 ++-- website/src/pages/technical-manual/vim.mdx | 4 +- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index f3ab3890e..69fce4b50 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -1,31 +1,31 @@ import { closeBrackets } from '@codemirror/autocomplete'; -import { toggleLineComment } from '@codemirror/commands'; -export { toggleComment, toggleBlockComment, toggleLineComment, toggleBlockCommentByLine } from '@codemirror/commands'; -// import { search, highlightSelectionMatches } from '@codemirror/search'; -import { indentWithTab } from '@codemirror/commands'; +import { indentWithTab, toggleLineComment } from '@codemirror/commands'; import { javascript, javascriptLanguage } from '@codemirror/lang-javascript'; -import { defaultHighlightStyle, syntaxHighlighting, bracketMatching } from '@codemirror/language'; +import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language'; import { Compartment, EditorState, Prec } from '@codemirror/state'; import { + drawSelection, EditorView, - highlightActiveLineGutter, highlightActiveLine, + highlightActiveLineGutter, keymap, lineNumbers, - drawSelection, } from '@codemirror/view'; -import { repl, registerControl, logger } from '@strudel/core'; -import { Drawer, cleanupDraw } from '@strudel/draw'; +import { persistentAtom } from '@nanostores/persistent'; +import { logger, registerControl, repl } from '@strudel/core'; +import { cleanupDraw, Drawer } from '@strudel/draw'; + import { isAutoCompletionEnabled } from './autocomplete.mjs'; -import { isTooltipEnabled } from './tooltip.mjs'; +import { basicSetup } from './basicSetup.mjs'; import { flash, isFlashEnabled } from './flash.mjs'; import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs'; import { keybindings } from './keybindings.mjs'; -import { initTheme, activateTheme, theme } from './themes.mjs'; import { sliderPlugin, updateSliderWidgets } from './slider.mjs'; -import { widgetPlugin, updateWidgets } from './widget.mjs'; -import { persistentAtom } from '@nanostores/persistent'; -import { basicSetup } from './basicSetup.mjs'; +import { activateTheme, initTheme, theme } from './themes.mjs'; +import { isTooltipEnabled } from './tooltip.mjs'; +import { updateWidgets, widgetPlugin } from './widget.mjs'; + +export { toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment } from '@codemirror/commands'; const extensions = { isLineWrappingEnabled: (on) => (on ? EditorView.lineWrapping : []), @@ -95,8 +95,8 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo }), sliderPlugin, widgetPlugin, - // indentOnInput(), // works without. already brought with javascript extension? - // bracketMatching(), // does not do anything + // indentOnInput(), // works without. already brought with javascript + // extension? bracketMatching(), // does not do anything syntaxHighlighting(defaultHighlightStyle), EditorView.updateListener.of((v) => onChange(v)), drawSelection({ cursorBlinkRate: 0 }), @@ -120,13 +120,13 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo run: () => onStop?.(), }, /* { - key: 'Ctrl-Shift-.', - run: () => (onPanic ? onPanic() : onStop?.()), - }, - { - key: 'Ctrl-Shift-Enter', - run: () => (onReEvaluate ? onReEvaluate() : onEvaluate?.()), - }, */ + key: 'Ctrl-Shift-.', + run: () => (onPanic ? onPanic() : onStop?.()), + }, + { + key: 'Ctrl-Shift-Enter', + run: () => (onReEvaluate ? onReEvaluate() : onEvaluate?.()), + }, */ ]), ), ], @@ -207,7 +207,8 @@ export class StrudelMirror { updateWidgets(this.editor, widgets); updateMiniLocations(this.editor, this.miniLocations); replOptions?.afterEval?.(options); - // if no painters are set (.onPaint was not called), then we only need the present moment (for highlighting) + // if no painters are set (.onPaint was not called), then we only need + // the present moment (for highlighting) const drawTime = options.pattern.getPainters().length ? this.drawTime : [0, 0]; this.drawer.setDrawTime(drawTime); // invalidate drawer after we've set the appropriate drawTime @@ -261,10 +262,11 @@ export class StrudelMirror { document.addEventListener('repl-evaluate', this.onEvaluateRequest); document.addEventListener('repl-stop', this.onStopRequest); - // Toggle comments requested from Vim (gc/gcc) + // Toggle comments requested from Vim (gc) this.onToggleComment = (e) => { try { - // Honor selections; toggleLineComment handles both selections and single line + // Honor selections; toggleLineComment handles both selections and + // single line toggleLineComment(this.editor); e?.cancelable && e.preventDefault?.(); } catch (err) { @@ -383,7 +385,11 @@ export class StrudelMirror { } } setCode(code) { - const changes = { from: 0, to: this.editor.state.doc.length, insert: code }; + const changes = { + from: 0, + to: this.editor.state.doc.length, + insert: code, + }; this.editor.dispatch({ changes }); } clear() { diff --git a/packages/codemirror/keybindings.mjs b/packages/codemirror/keybindings.mjs index 06aaad523..545c9797d 100644 --- a/packages/codemirror/keybindings.mjs +++ b/packages/codemirror/keybindings.mjs @@ -4,9 +4,9 @@ import { keymap, ViewPlugin } from '@codemirror/view'; // import { searchKeymap } from '@codemirror/search'; import { emacs } from '@replit/codemirror-emacs'; import { vim, Vim } from '@replit/codemirror-vim'; -import { logger } from '@strudel/core'; // import { vim } from './vim_test.mjs'; import { vscodeKeymap } from '@replit/codemirror-vscode-keymap'; +import { logger } from '@strudel/core'; const vscodePlugin = ViewPlugin.fromClass( class { @@ -26,9 +26,9 @@ const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []); // appears in the Console panel. try { if (Vim && typeof Vim.defineEx === 'function') { - // Map gc/gcc to toggle line comments by dispatching a custom event that our - // CodeMirror integration listens to. This avoids depending on Vim's internal - // actions and works with current selections/visual mode. + // Map gc to toggle line comments by dispatching a custom event that our + // CodeMirror integration listens to. This avoids depending on Vim's + // internal actions and works with current selections/visual mode. try { Vim.defineAction('strudelToggleComment', (cm) => { const view = cm?.view || cm; @@ -41,9 +41,8 @@ try { }); Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'normal' }); Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'visual' }); - Vim.mapCommand('gcc', 'action', 'strudelToggleComment', {}, { context: 'normal' }); } catch (e) { - console.error('Vim gc/gcc mapping failed', e); + console.error('Vim gc mapping failed', e); } // :q to pause/stop diff --git a/website/src/pages/technical-manual/vim.mdx b/website/src/pages/technical-manual/vim.mdx index b18a259ec..73f5e1a11 100644 --- a/website/src/pages/technical-manual/vim.mdx +++ b/website/src/pages/technical-manual/vim.mdx @@ -25,8 +25,6 @@ When the REPL editor (CodeMirror) is configured to use Vim keybindings, the foll - Works in normal and visual mode - If there’s a selection, all selected lines are toggled -- gcc — Toggle comment for the current line (normal mode) - Notes - Behavior respects the current language mode in the editor for comment syntax. @@ -36,4 +34,4 @@ Notes Troubleshooting - If :w logs but evaluation doesn’t apply, ensure Vim keybindings are active and try again. You can also use Ctrl+Enter as a fallback. -- For :q / gc / gcc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again. +- For :q / gc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again. From cfe17fcba56a8d3767deecd08ef86f054c339d7f Mon Sep 17 00:00:00 2001 From: dtricks Date: Fri, 3 Oct 2025 18:19:18 +0200 Subject: [PATCH 4/7] wrong unicode char --- website/src/pages/technical-manual/vim.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/src/pages/technical-manual/vim.mdx b/website/src/pages/technical-manual/vim.mdx index 73f5e1a11..fa53aa550 100644 --- a/website/src/pages/technical-manual/vim.mdx +++ b/website/src/pages/technical-manual/vim.mdx @@ -10,7 +10,7 @@ When the REPL editor (CodeMirror) is configured to use Vim keybindings, the foll - :w — Evaluate the current code - Triggers the same evaluation as Ctrl+Enter / Alt+Enter - - You’ll see messages in the Console panel such as: + - You'll see messages in the Console panel such as: - [vim] :w — evaluating code - [repl] evaluate via event - [eval] code updated @@ -23,15 +23,15 @@ When the REPL editor (CodeMirror) is configured to use Vim keybindings, the foll - gc — Toggle line comments for the current selection(s) - Works in normal and visual mode - - If there’s a selection, all selected lines are toggled + - If there's a selection, all selected lines are toggled Notes - Behavior respects the current language mode in the editor for comment syntax. - If multiple REPL editors are open, commands target the active editor. The implementation dispatches custom events handled by the editor. -- If you don’t see the Console panel, open the right panel in the REPL UI. +- If you don't see the Console panel, open the right panel in the REPL UI. Troubleshooting -- If :w logs but evaluation doesn’t apply, ensure Vim keybindings are active and try again. You can also use Ctrl+Enter as a fallback. +- If :w logs but evaluation doesn't apply, ensure Vim keybindings are active and try again. You can also use Ctrl+Enter as a fallback. - For :q / gc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again. From 30a2e149592659ec9e9262c7d05fc7134ef29729 Mon Sep 17 00:00:00 2001 From: dtricks Date: Fri, 3 Oct 2025 18:29:32 +0200 Subject: [PATCH 5/7] weird permission change --- packages/osc/server.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 packages/osc/server.js diff --git a/packages/osc/server.js b/packages/osc/server.js old mode 100755 new mode 100644 From a79fc3db5b78a31d6944ca5501206c41cbb9b1bd Mon Sep 17 00:00:00 2001 From: dtricks Date: Sat, 4 Oct 2025 14:49:56 +0200 Subject: [PATCH 6/7] remove unnecessary comments --- packages/codemirror/keybindings.mjs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/codemirror/keybindings.mjs b/packages/codemirror/keybindings.mjs index 545c9797d..5cd6a50e4 100644 --- a/packages/codemirror/keybindings.mjs +++ b/packages/codemirror/keybindings.mjs @@ -45,7 +45,6 @@ try { console.error('Vim gc mapping failed', e); } - // :q to pause/stop // :q to pause/stop Vim.defineEx('quit', 'q', (cm) => { try { @@ -71,7 +70,6 @@ try { } }); - // :w to evaluate // :w to evaluate Vim.defineEx('write', 'w', (cm) => { const view = cm?.view || cm; // CM6 Vim passes either an object with view or the view itself @@ -122,9 +120,6 @@ try { const keymaps = { vim, - // Add extra Vim keymap for gc to toggle line comment - // We will include a Vim-specific keymap that calls the CM command - // respecting the current selection. emacs, codemirror: () => keymap.of(defaultKeymap), vscode: vscodeExtension, From f48f8e46e51c1010bb3dc9e0599b5de8dbb2a00d Mon Sep 17 00:00:00 2001 From: dtricks Date: Mon, 6 Oct 2025 11:09:21 +0200 Subject: [PATCH 7/7] fix empty catches --- packages/codemirror/keybindings.mjs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/codemirror/keybindings.mjs b/packages/codemirror/keybindings.mjs index 5cd6a50e4..81dc87a52 100644 --- a/packages/codemirror/keybindings.mjs +++ b/packages/codemirror/keybindings.mjs @@ -54,7 +54,9 @@ try { try { const ev = new CustomEvent('repl-stop', { detail: { source: 'vim', view }, cancelable: true }); handled = document.dispatchEvent(ev) === false; - } catch {} + } catch (e) { + console.error('Error dispatching repl-stop event', e); + } if (!handled) { const altDot = new KeyboardEvent('keydown', { key: '.', @@ -78,13 +80,17 @@ try { // Let the app know this came from Vim :w try { logger('[vim] :w — evaluating code'); - } catch {} + } catch (e) { + console.error('Error logging Vim :w evaluation', e); + } // Dispatch a dedicated evaluate event first let handled = false; try { const ev = new CustomEvent('repl-evaluate', { detail: { source: 'vim', view }, cancelable: true }); handled = document.dispatchEvent(ev) === false; // false means preventDefault was called - } catch {} + } catch (e) { + console.error('Error dispatching repl-evaluate event', e); + } if (handled) { return; }