From 7e0eed87cb68f2ae128874904e4c76a035df2b8e Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Tue, 27 Jan 2026 17:21:36 -0500 Subject: [PATCH] normalize shortcuts --- packages/codemirror/codemirror.mjs | 22 +++++++++++++++++++-- packages/codemirror/labelJump.mjs | 31 ++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 9acd77c1c..1939ed759 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -26,6 +26,7 @@ import { isTooltipEnabled } from './tooltip.mjs'; import { updateWidgets, widgetPlugin } from './widget.mjs'; import { deleteAllInlineBeforeCharacter, + InsertCharBeforeChar, jumpToCharacter, jumpToNextCharacter, ToggleCharBeforeChar, @@ -153,6 +154,13 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo return deleteAllInlineBeforeCharacter(view, SOLO_LABEL + ANON_LABEL); }, }, + // clear all solo and mute + { + key: `Ctrl-Shift-0`, + run: (view) => { + return deleteAllInlineBeforeCharacter(view, SOLO_LABEL); + }, + }, ...Array.from({ length: 9 }).map((_, i) => { let num = i + 1; return { @@ -168,7 +176,7 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo return { key: `Alt-Shift-${num}`, run: (view) => { - return ToggleCharBeforeChar(view, ANON_LABEL, SOLO_LABEL, i); + return InsertCharBeforeChar(view, ANON_LABEL, SOLO_LABEL, i); }, }; }), @@ -178,7 +186,17 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo return { key: `Alt-Ctrl-${num}`, run: (view) => { - return ToggleCharBeforeChar(view, ANON_LABEL, MUTE_LABEL, i); + return InsertCharBeforeChar(view, ANON_LABEL, MUTE_LABEL, i); + }, + }; + }), + // Handle clearing mutes and solos 1-9 + ...Array.from({ length: 9 }).map((_, i) => { + let num = i + 1; + return { + key: `Ctrl-Shift-${num}`, + run: (view) => { + return InsertCharBeforeChar(view, ANON_LABEL,'', i); }, }; }), diff --git a/packages/codemirror/labelJump.mjs b/packages/codemirror/labelJump.mjs index 385ca5b20..b58f10098 100644 --- a/packages/codemirror/labelJump.mjs +++ b/packages/codemirror/labelJump.mjs @@ -57,6 +57,7 @@ export function jumpToCharacter(view, character, num) { }); return true; } + export function deleteAllInlineBeforeCharacter(view, character) { const { state, dispatch } = view; const characterPositions = getCharacterPositions(state, character); @@ -64,7 +65,7 @@ export function deleteAllInlineBeforeCharacter(view, character) { const changes = []; characterPositions.forEach((pos) => { const line = state.doc.lineAt(pos); - if (state.doc.sliceString(line.from, line.from + 1) === COMMENT_STRING) { + if (state.doc.sliceString(line.from, line.from + 2) === COMMENT_STRING) { return; } changes.push({ @@ -84,7 +85,7 @@ export function ToggleCharBeforeChar(view, character, character2, num) { const labelpos = characterPositions.at(num) ?? characterPositions.at(-1); const line = state.doc.lineAt(labelpos); - if (state.doc.sliceString(line.from, line.from + 1) === COMMENT_STRING) { + if (state.doc.sliceString(line.from, line.from + 2) === COMMENT_STRING) { return false; } //delete preceeding characters @@ -105,3 +106,29 @@ export function ToggleCharBeforeChar(view, character, character2, num) { dispatch({ changes }); return true; } +export function InsertCharBeforeChar(view, character, character2, num) { + const { state, dispatch } = view; + + const changes = []; + const characterPositions = getCharacterPositions(state, character); + const labelpos = characterPositions.at(num) ?? characterPositions.at(-1); + const line = state.doc.lineAt(labelpos); + + if (state.doc.sliceString(line.from, line.from + 2) === COMMENT_STRING) { + return false; + } + //delete preceeding characters + changes.push({ + from: line.from, + to: labelpos - 1, + insert: '', + }); + + changes.push({ + insert: character2, + from: line.from, + }); + + dispatch({ changes }); + return true; +}