codeformat

This commit is contained in:
dtricks
2025-10-03 18:12:47 +02:00
committed by dtricks
parent be9368e8a2
commit 73a9834959
4 changed files with 32 additions and 29 deletions
+1 -1
View File
@@ -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 {
+28 -28
View File
@@ -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()) : []];
}
Regular → Executable
View File
@@ -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
- Youll 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 theres a selection, all selected lines are toggled