diff --git a/packages/codemirror/slider.mjs b/packages/codemirror/slider.mjs index 63015051..2e75959b 100644 --- a/packages/codemirror/slider.mjs +++ b/packages/codemirror/slider.mjs @@ -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; } diff --git a/packages/transpiler/transpiler.mjs b/packages/transpiler/transpiler.mjs index 78aae9f7..9ff558cb 100644 --- a/packages/transpiler/transpiler.mjs +++ b/packages/transpiler/transpiler.mjs @@ -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; +}