MCPcopy
hub / github.com/josdejong/mathjs / updateSelection

Function updateSelection

examples/code_editor/main.js:165–192  ·  view source on GitHub ↗

* Updates the visual highlighting of results based on the current line selection in the editor. * * @function updateSelection * @requires editor, processedExpressions * * @description * 1. Determines the current line number in the editor's selection. * 2. Finds the corresponding result (processed ex

()

Source from the content-addressed store, hash-verified

163* - Scrolls the newly selected result into view.
164*/
165function updateSelection() {
166 const selectedLine = editor.state.doc.lineAt(
167 editor.state.selection.ranges[editor.state.selection.mainIndex].from
168 ).number - 1;
169
170 let selectedExpressionIndex;
171
172 processedExpressions.forEach((result, index) => {
173 if ((selectedLine >= result.from) && (selectedLine <= result.to)) {
174 selectedExpressionIndex = index;
175 }
176 });
177
178 if (selectedExpressionIndex !== previousSelectedExpressionIndex) {
179 const previouslyHighlightedResult = document.querySelector('#result').children[previousSelectedExpressionIndex];
180 if (previouslyHighlightedResult !== undefined) {
181 previouslyHighlightedResult.className = null;
182 }
183
184 const currentlySelectedResult = document.querySelector('#result').children[selectedExpressionIndex];
185 if (currentlySelectedResult !== undefined) {
186 currentlySelectedResult.className = 'highlighted';
187 currentlySelectedResult.scrollIntoView({ block: 'nearest', inline: 'start' });
188 }
189
190 previousSelectedExpressionIndex = selectedExpressionIndex;
191 }
192}
193
194/**
195* Converts an array of processed results into HTML elements for display.

Callers 1

main.jsFile · 0.85

Calls 1

forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…