mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-05 06:57:35 -04:00
normalize shortcuts
This commit is contained in:
@@ -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);
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user