From b9fce1504276215bd9b280b69ab1214f6d341162 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Wed, 3 Dec 2025 15:18:32 -0500 Subject: [PATCH 1/3] working --- packages/codemirror/codemirror.mjs | 9 +++++++++ packages/codemirror/labelJump.mjs | 31 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 packages/codemirror/labelJump.mjs diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 69fce4b50..6643e400d 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -24,6 +24,7 @@ import { sliderPlugin, updateSliderWidgets } from './slider.mjs'; import { activateTheme, initTheme, theme } from './themes.mjs'; import { isTooltipEnabled } from './tooltip.mjs'; import { updateWidgets, widgetPlugin } from './widget.mjs'; +import { jumpToCharacter } from './labelJump.mjs'; export { toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment } from '@codemirror/commands'; @@ -119,6 +120,14 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo preventDefault: true, run: () => onStop?.(), }, + { + key: 'Alt-]', + run: (view) => jumpToCharacter(view, '$', 1), + }, + { + key: 'Alt-[', + run: (view) => jumpToCharacter(view, '$', -1), + }, /* { key: 'Ctrl-Shift-.', run: () => (onPanic ? onPanic() : onStop?.()), diff --git a/packages/codemirror/labelJump.mjs b/packages/codemirror/labelJump.mjs new file mode 100644 index 000000000..fcdb437f5 --- /dev/null +++ b/packages/codemirror/labelJump.mjs @@ -0,0 +1,31 @@ +import { EditorSelection } from '@codemirror/state'; +import { SearchCursor } from '@codemirror/search'; + +export function jumpToCharacter(view, character, direction = 1) { + const { state, dispatch } = view; + const pos = state.selection.main.head; + const cursor = new SearchCursor(state.doc, character); + + let characterPositions = []; + let jumpPos; + while (!cursor.next().done) { + characterPositions.push(cursor.value.to); + } + if (!characterPositions.length) { + return false; + } + if (direction > 0) { + jumpPos = characterPositions.find((x) => x > pos + 1) ?? characterPositions.at(0); // Loop back around for convenience + } else { + jumpPos = characterPositions.reverse().find((x) => x < pos + 1) ?? characterPositions.at(0); + } + + if (!jumpPos) { + return false; + } + dispatch({ + selection: EditorSelection.cursor(jumpPos - 1), + scrollIntoView: true, + }); + return true; +} From c1a185e852433d4469e25e6b07a2eec64b36d08d Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Wed, 3 Dec 2025 15:25:05 -0500 Subject: [PATCH 2/3] fix null case --- packages/codemirror/labelJump.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/codemirror/labelJump.mjs b/packages/codemirror/labelJump.mjs index fcdb437f5..0aced4eb5 100644 --- a/packages/codemirror/labelJump.mjs +++ b/packages/codemirror/labelJump.mjs @@ -20,7 +20,7 @@ export function jumpToCharacter(view, character, direction = 1) { jumpPos = characterPositions.reverse().find((x) => x < pos + 1) ?? characterPositions.at(0); } - if (!jumpPos) { + if (jumpPos == null) { return false; } dispatch({ From f0aac2098afba2ba10d1f8d88db70c988c6b3496 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Wed, 3 Dec 2025 22:59:20 -0500 Subject: [PATCH 3/3] update_shortcut --- packages/codemirror/codemirror.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 6643e400d..ba481d9ac 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -121,11 +121,11 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo run: () => onStop?.(), }, { - key: 'Alt-]', + key: 'Alt-w', run: (view) => jumpToCharacter(view, '$', 1), }, { - key: 'Alt-[', + key: 'Alt-q', run: (view) => jumpToCharacter(view, '$', -1), }, /* {