From e4a62de11f75eebda5fc87d24ab28bd328328ba6 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Mon, 22 Apr 2024 21:03:44 -0500 Subject: [PATCH] feat: preserve result height when results are invalidated on edit This is done instead of deleting the results to reduce vertical jumping on updates. --- src/App.svelte | 15 ++++++++++----- src/Cell.svelte | 4 +++- src/CellList.svelte | 3 ++- src/DeletedCell.svelte | 4 +++- src/InsertCell.svelte | 3 ++- src/MathCell.svelte | 3 ++- src/MathField.svelte | 12 +++++++++--- src/stores.ts | 7 ++++++- 8 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 7a3baac1..dd142d99 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -7,7 +7,7 @@ import PlotCell from "./cells/PlotCell"; import PiecewiseCell from "./cells/PiecewiseCell"; import SystemCell from "./cells/SystemCell"; - import { cells, title, results, system_results, history, insertedSheets, activeCell, + import { cells, title, results, resultsInvalid, system_results, history, insertedSheets, activeCell, getSheetJson, getSheetObject, resetSheet, sheetId, mathCellChanged, nonMathCellChanged, addCell, prefersReducedMotion, modifierKey, inCellInsertMode, config, unsavedChange, incrementActiveCell, decrementActiveCell, deleteCell, activeMathField, @@ -875,9 +875,9 @@ initialSheetLoad = false; inDebounce = false; if(noParsingErrors && !firstRunAfterSheetLoad) { - // remove existing results if all math fields are valid (while editing current cell) - // also, don't clear results if sheet was just loaded without modification (initialSheetLoad === true) - $results = []; + // inalidated results if all math fields are valid (while editing current cell) + // also, don't invalidate results if sheet was just loaded without modification (initialSheetLoad === true) + $resultsInvalid = true; error = ""; } await pyodidePromise; @@ -887,12 +887,13 @@ clearTimeout(pyodideTimeoutRef); pyodideTimeoutRef = window.setTimeout(() => pyodideTimeout=true, pyodideTimeoutLength); if (!firstRunAfterSheetLoad) { - $results = []; + $resultsInvalid = true; error = ""; } pyodidePromise = getResults(statementsAndSystems, myRefreshCount) .then((data: Results) => { $results = []; + $resultsInvalid = false; if (!data.error && data.results.length > 0) { let counter = 0; for (const [i, cell] of $cells.entries()) { @@ -1088,6 +1089,7 @@ Please include a link to this sheet in the email to assist in debugging the prob $cells = []; $results = []; + $resultsInvalid = true; $system_results = []; $activeCell = -1; @@ -1112,10 +1114,12 @@ Please include a link to this sheet in the email to assist in debugging the prob if (noParsingErrors) { $results = sheet.results; + $resultsInvalid = false; // old documents in the database won't have the system_results property $system_results = sheet.system_results ? sheet.system_results : []; } else { $results = []; + $resultsInvalid = true; $system_results = []; } @@ -1477,6 +1481,7 @@ Please include a link to this sheet in the email to assist in debugging the prob try{ $results = []; + $resultsInvalid = true; $system_results = []; const newCells = sheet.cells.map(cellFactory); diff --git a/src/Cell.svelte b/src/Cell.svelte index 84b47b19..c534527b 100644 --- a/src/Cell.svelte +++ b/src/Cell.svelte @@ -1,6 +1,6 @@