remove gcc
This commit is contained in:
parent
73a9834959
commit
46ba165c7e
3 changed files with 39 additions and 36 deletions
|
|
@ -1,31 +1,31 @@
|
||||||
import { closeBrackets } from '@codemirror/autocomplete';
|
import { closeBrackets } from '@codemirror/autocomplete';
|
||||||
import { toggleLineComment } from '@codemirror/commands';
|
import { indentWithTab, toggleLineComment } from '@codemirror/commands';
|
||||||
export { toggleComment, toggleBlockComment, toggleLineComment, toggleBlockCommentByLine } from '@codemirror/commands';
|
|
||||||
// import { search, highlightSelectionMatches } from '@codemirror/search';
|
|
||||||
import { indentWithTab } from '@codemirror/commands';
|
|
||||||
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
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 { Compartment, EditorState, Prec } from '@codemirror/state';
|
||||||
import {
|
import {
|
||||||
|
drawSelection,
|
||||||
EditorView,
|
EditorView,
|
||||||
highlightActiveLineGutter,
|
|
||||||
highlightActiveLine,
|
highlightActiveLine,
|
||||||
|
highlightActiveLineGutter,
|
||||||
keymap,
|
keymap,
|
||||||
lineNumbers,
|
lineNumbers,
|
||||||
drawSelection,
|
|
||||||
} from '@codemirror/view';
|
} from '@codemirror/view';
|
||||||
import { repl, registerControl, logger } from '@strudel/core';
|
import { persistentAtom } from '@nanostores/persistent';
|
||||||
import { Drawer, cleanupDraw } from '@strudel/draw';
|
import { logger, registerControl, repl } from '@strudel/core';
|
||||||
|
import { cleanupDraw, Drawer } from '@strudel/draw';
|
||||||
|
|
||||||
import { isAutoCompletionEnabled } from './autocomplete.mjs';
|
import { isAutoCompletionEnabled } from './autocomplete.mjs';
|
||||||
import { isTooltipEnabled } from './tooltip.mjs';
|
import { basicSetup } from './basicSetup.mjs';
|
||||||
import { flash, isFlashEnabled } from './flash.mjs';
|
import { flash, isFlashEnabled } from './flash.mjs';
|
||||||
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
|
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
|
||||||
import { keybindings } from './keybindings.mjs';
|
import { keybindings } from './keybindings.mjs';
|
||||||
import { initTheme, activateTheme, theme } from './themes.mjs';
|
|
||||||
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
|
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
|
||||||
import { widgetPlugin, updateWidgets } from './widget.mjs';
|
import { activateTheme, initTheme, theme } from './themes.mjs';
|
||||||
import { persistentAtom } from '@nanostores/persistent';
|
import { isTooltipEnabled } from './tooltip.mjs';
|
||||||
import { basicSetup } from './basicSetup.mjs';
|
import { updateWidgets, widgetPlugin } from './widget.mjs';
|
||||||
|
|
||||||
|
export { toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment } from '@codemirror/commands';
|
||||||
|
|
||||||
const extensions = {
|
const extensions = {
|
||||||
isLineWrappingEnabled: (on) => (on ? EditorView.lineWrapping : []),
|
isLineWrappingEnabled: (on) => (on ? EditorView.lineWrapping : []),
|
||||||
|
|
@ -95,8 +95,8 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
|
||||||
}),
|
}),
|
||||||
sliderPlugin,
|
sliderPlugin,
|
||||||
widgetPlugin,
|
widgetPlugin,
|
||||||
// indentOnInput(), // works without. already brought with javascript extension?
|
// indentOnInput(), // works without. already brought with javascript
|
||||||
// bracketMatching(), // does not do anything
|
// extension? bracketMatching(), // does not do anything
|
||||||
syntaxHighlighting(defaultHighlightStyle),
|
syntaxHighlighting(defaultHighlightStyle),
|
||||||
EditorView.updateListener.of((v) => onChange(v)),
|
EditorView.updateListener.of((v) => onChange(v)),
|
||||||
drawSelection({ cursorBlinkRate: 0 }),
|
drawSelection({ cursorBlinkRate: 0 }),
|
||||||
|
|
@ -120,13 +120,13 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
|
||||||
run: () => onStop?.(),
|
run: () => onStop?.(),
|
||||||
},
|
},
|
||||||
/* {
|
/* {
|
||||||
key: 'Ctrl-Shift-.',
|
key: 'Ctrl-Shift-.',
|
||||||
run: () => (onPanic ? onPanic() : onStop?.()),
|
run: () => (onPanic ? onPanic() : onStop?.()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'Ctrl-Shift-Enter',
|
key: 'Ctrl-Shift-Enter',
|
||||||
run: () => (onReEvaluate ? onReEvaluate() : onEvaluate?.()),
|
run: () => (onReEvaluate ? onReEvaluate() : onEvaluate?.()),
|
||||||
}, */
|
}, */
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -207,7 +207,8 @@ export class StrudelMirror {
|
||||||
updateWidgets(this.editor, widgets);
|
updateWidgets(this.editor, widgets);
|
||||||
updateMiniLocations(this.editor, this.miniLocations);
|
updateMiniLocations(this.editor, this.miniLocations);
|
||||||
replOptions?.afterEval?.(options);
|
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];
|
const drawTime = options.pattern.getPainters().length ? this.drawTime : [0, 0];
|
||||||
this.drawer.setDrawTime(drawTime);
|
this.drawer.setDrawTime(drawTime);
|
||||||
// invalidate drawer after we've set the appropriate 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-evaluate', this.onEvaluateRequest);
|
||||||
document.addEventListener('repl-stop', this.onStopRequest);
|
document.addEventListener('repl-stop', this.onStopRequest);
|
||||||
|
|
||||||
// Toggle comments requested from Vim (gc/gcc)
|
// Toggle comments requested from Vim (gc)
|
||||||
this.onToggleComment = (e) => {
|
this.onToggleComment = (e) => {
|
||||||
try {
|
try {
|
||||||
// Honor selections; toggleLineComment handles both selections and single line
|
// Honor selections; toggleLineComment handles both selections and
|
||||||
|
// single line
|
||||||
toggleLineComment(this.editor);
|
toggleLineComment(this.editor);
|
||||||
e?.cancelable && e.preventDefault?.();
|
e?.cancelable && e.preventDefault?.();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -383,7 +385,11 @@ export class StrudelMirror {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCode(code) {
|
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 });
|
this.editor.dispatch({ changes });
|
||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ 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 { 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';
|
||||||
|
import { logger } from '@strudel/core';
|
||||||
|
|
||||||
const vscodePlugin = ViewPlugin.fromClass(
|
const vscodePlugin = ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
|
|
@ -26,9 +26,9 @@ const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []);
|
||||||
// appears in the Console panel.
|
// appears in the Console panel.
|
||||||
try {
|
try {
|
||||||
if (Vim && typeof Vim.defineEx === 'function') {
|
if (Vim && typeof Vim.defineEx === 'function') {
|
||||||
// Map gc/gcc to toggle line comments by dispatching a custom event that our
|
// Map gc to toggle line comments by dispatching a custom event that our
|
||||||
// CodeMirror integration listens to. This avoids depending on Vim's internal
|
// CodeMirror integration listens to. This avoids depending on Vim's
|
||||||
// actions and works with current selections/visual mode.
|
// internal actions and works with current selections/visual mode.
|
||||||
try {
|
try {
|
||||||
Vim.defineAction('strudelToggleComment', (cm) => {
|
Vim.defineAction('strudelToggleComment', (cm) => {
|
||||||
const view = cm?.view || cm;
|
const view = cm?.view || cm;
|
||||||
|
|
@ -41,9 +41,8 @@ try {
|
||||||
});
|
});
|
||||||
Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'normal' });
|
Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'normal' });
|
||||||
Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'visual' });
|
Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'visual' });
|
||||||
Vim.mapCommand('gcc', 'action', 'strudelToggleComment', {}, { context: 'normal' });
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Vim gc/gcc mapping failed', e);
|
console.error('Vim gc mapping failed', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// :q to pause/stop
|
// :q to pause/stop
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ When the REPL editor (CodeMirror) is configured to use Vim keybindings, the foll
|
||||||
- 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
|
||||||
|
|
||||||
- gcc — Toggle comment for the current line (normal mode)
|
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
|
|
||||||
- Behavior respects the current language mode in the editor for comment syntax.
|
- Behavior respects the current language mode in the editor for comment syntax.
|
||||||
|
|
@ -36,4 +34,4 @@ Notes
|
||||||
Troubleshooting
|
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 / 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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue