use loc as slider id

This commit is contained in:
Felix Roos 2023-09-30 21:03:28 +02:00
parent 276cf858fc
commit 2731e70fb7
2 changed files with 23 additions and 4 deletions

View File

@ -152,6 +152,6 @@ function updateSliderValue(view, e) {
let change = { from: draggedSlider.from, to: draggedSlider.to, insert };
draggedSlider.to = draggedSlider.from + insert.length;
view.dispatch({ changes: change });
window.postMessage({ type: 'slider-change', value: next });
window.postMessage({ type: 'cm-slider', value: next, loc: draggedSlider.from });
return true;
}

View File

@ -35,6 +35,10 @@ export function transpiler(input, options = {}) {
emitMiniLocations && collectMiniLocations(value, node);
return this.replace(miniWithLocation(value, node));
}
if (isWidgetFunction(node)) {
// collectSliderLocations?
return this.replace(widgetWithLocation(node));
}
// TODO: remove pseudo note variables?
if (node.type === 'Identifier' && isNoteWithOctave(node.name)) {
this.skip();
@ -68,11 +72,10 @@ export function transpiler(input, options = {}) {
}
function isStringWithDoubleQuotes(node, locations, code) {
const { raw, type } = node;
if (type !== 'Literal') {
if (node.type !== 'Literal') {
return false;
}
return raw[0] === '"';
return node.raw[0] === '"';
}
function isBackTickString(node, parent) {
@ -94,3 +97,19 @@ function miniWithLocation(value, node) {
optional: false,
};
}
function isWidgetFunction(node) {
return node.type === 'CallExpression' && node.callee.name === 'slider';
}
function widgetWithLocation(node) {
const loc = node.arguments[0].start;
// add loc as identifier to first argument
// the slider function is assumed to be slider(loc, value, min?, max?)
node.arguments.unshift({
type: 'Literal',
value: loc,
raw: loc + '',
});
return node;
}