codeformat
This commit is contained in:
parent
be9368e8a2
commit
73a9834959
4 changed files with 32 additions and 29 deletions
|
|
@ -298,7 +298,7 @@ export class StrudelMirror {
|
||||||
async stop() {
|
async stop() {
|
||||||
this.repl.scheduler.stop();
|
this.repl.scheduler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for global stop requests (e.g., from Vim :q)
|
// Listen for global stop requests (e.g., from Vim :q)
|
||||||
onStopRequest = (e) => {
|
onStopRequest = (e) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
import {defaultKeymap} from '@codemirror/commands';
|
import { defaultKeymap } from '@codemirror/commands';
|
||||||
import {Prec} from '@codemirror/state';
|
import { Prec } from '@codemirror/state';
|
||||||
import {keymap, ViewPlugin} from '@codemirror/view';
|
import { keymap, ViewPlugin } from '@codemirror/view';
|
||||||
// import { searchKeymap } from '@codemirror/search';
|
// import { searchKeymap } from '@codemirror/search';
|
||||||
import {emacs} from '@replit/codemirror-emacs';
|
import { emacs } from '@replit/codemirror-emacs';
|
||||||
import {vim, Vim} from '@replit/codemirror-vim';
|
import { vim, Vim } from '@replit/codemirror-vim';
|
||||||
import { logger } from '@strudel/core';
|
import { logger } from '@strudel/core';
|
||||||
// import { vim } from './vim_test.mjs';
|
// import { vim } from './vim_test.mjs';
|
||||||
import {vscodeKeymap} from '@replit/codemirror-vscode-keymap';
|
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
|
||||||
|
|
||||||
const vscodePlugin = ViewPlugin.fromClass(
|
const vscodePlugin = ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide : () => { return Prec.highest(keymap.of([...vscodeKeymap ])); },
|
provide: () => {
|
||||||
|
return Prec.highest(keymap.of([...vscodeKeymap]));
|
||||||
},
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []);
|
const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []);
|
||||||
|
|
||||||
|
|
@ -73,9 +75,7 @@ try {
|
||||||
// :w to evaluate
|
// :w to evaluate
|
||||||
// :w to evaluate
|
// :w to evaluate
|
||||||
Vim.defineEx('write', 'w', (cm) => {
|
Vim.defineEx('write', 'w', (cm) => {
|
||||||
const view =
|
const view = cm?.view || cm; // CM6 Vim passes either an object with view or the view itself
|
||||||
cm?.view ||
|
|
||||||
cm; // CM6 Vim passes either an object with view or the view itself
|
|
||||||
try {
|
try {
|
||||||
view?.focus?.();
|
view?.focus?.();
|
||||||
// Let the app know this came from Vim :w
|
// Let the app know this came from Vim :w
|
||||||
|
|
@ -93,22 +93,22 @@ try {
|
||||||
}
|
}
|
||||||
// Try Ctrl+Enter first if not handled by custom event
|
// Try Ctrl+Enter first if not handled by custom event
|
||||||
const ctrlEnter = new KeyboardEvent('keydown', {
|
const ctrlEnter = new KeyboardEvent('keydown', {
|
||||||
key : 'Enter',
|
key: 'Enter',
|
||||||
code : 'Enter',
|
code: 'Enter',
|
||||||
ctrlKey : true,
|
ctrlKey: true,
|
||||||
bubbles : true,
|
bubbles: true,
|
||||||
cancelable : true,
|
cancelable: true,
|
||||||
});
|
});
|
||||||
view?.dom?.dispatchEvent?.(ctrlEnter);
|
view?.dom?.dispatchEvent?.(ctrlEnter);
|
||||||
// If not handled (no handler called preventDefault), try Alt+Enter as
|
// If not handled (no handler called preventDefault), try Alt+Enter as
|
||||||
// fallback
|
// fallback
|
||||||
if (!ctrlEnter.defaultPrevented) {
|
if (!ctrlEnter.defaultPrevented) {
|
||||||
const altEnter = new KeyboardEvent('keydown', {
|
const altEnter = new KeyboardEvent('keydown', {
|
||||||
key : 'Enter',
|
key: 'Enter',
|
||||||
code : 'Enter',
|
code: 'Enter',
|
||||||
altKey : true,
|
altKey: true,
|
||||||
bubbles : true,
|
bubbles: true,
|
||||||
cancelable : true,
|
cancelable: true,
|
||||||
});
|
});
|
||||||
view?.dom?.dispatchEvent?.(altEnter);
|
view?.dom?.dispatchEvent?.(altEnter);
|
||||||
}
|
}
|
||||||
|
|
@ -122,16 +122,16 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
const keymaps = {
|
const keymaps = {
|
||||||
vim,
|
vim,
|
||||||
// Add extra Vim keymap for gc to toggle line comment
|
// Add extra Vim keymap for gc to toggle line comment
|
||||||
// We will include a Vim-specific keymap that calls the CM command
|
// We will include a Vim-specific keymap that calls the CM command
|
||||||
// respecting the current selection.
|
// respecting the current selection.
|
||||||
emacs,
|
emacs,
|
||||||
codemirror : () => keymap.of(defaultKeymap),
|
codemirror: () => keymap.of(defaultKeymap),
|
||||||
vscode : vscodeExtension,
|
vscode: vscodeExtension,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function keybindings(name) {
|
export function keybindings(name) {
|
||||||
const active = keymaps[name];
|
const active = keymaps[name];
|
||||||
return [ active ? Prec.high(active()) : [] ];
|
return [active ? Prec.high(active()) : []];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
0
packages/osc/server.js
Normal file → Executable file
0
packages/osc/server.js
Normal file → Executable 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:
|
When the REPL editor (CodeMirror) is configured to use Vim keybindings, the following commands are available:
|
||||||
|
|
||||||
- :w — Evaluate the current code
|
- :w — Evaluate the current code
|
||||||
|
|
||||||
- Triggers the same evaluation as Ctrl+Enter / Alt+Enter
|
- 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
|
- [vim] :w — evaluating code
|
||||||
|
|
@ -15,10 +16,12 @@ When the REPL editor (CodeMirror) is configured to use Vim keybindings, the foll
|
||||||
- [eval] code updated
|
- [eval] code updated
|
||||||
|
|
||||||
- :q — Stop/pause playback
|
- :q — Stop/pause playback
|
||||||
|
|
||||||
- Triggers the same stop action as Alt+.
|
- Triggers the same stop action as Alt+.
|
||||||
- Useful to quickly stop scheduling without leaving Vim mode
|
- Useful to quickly stop scheduling without leaving Vim mode
|
||||||
|
|
||||||
- gc — Toggle line comments for the current selection(s)
|
- gc — Toggle line comments for the current selection(s)
|
||||||
|
|
||||||
- Works in normal and visual mode
|
- 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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue