Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preserve result height when results are invalidated on edit #254

Merged
merged 25 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e4a62de
feat: preserve result height when results are invalidated on edit
mgreminger Apr 23, 2024
7f2daa6
tests: update tests to check for hidden stale results
mgreminger Apr 28, 2024
541a4ef
feat: preserve result height when moving, deleting, or inserting cells
mgreminger Apr 30, 2024
f6ecc6a
fix: preserve result heights for DeletedCell removal
mgreminger Apr 30, 2024
a6ed1aa
fix: update refesh counter immediately after change
mgreminger May 1, 2024
28e7cd1
fix: check global refresh counter before beginning calculation
mgreminger May 1, 2024
d41f730
feat: preserve result height on current math cell for syntax error
mgreminger May 1, 2024
6d80a20
fix: fix type error
mgreminger May 2, 2024
72e6021
refactor: simplify app level reactive statements
mgreminger May 2, 2024
0a7de73
refactor: remove unneccesary cells array reactivity triggers
mgreminger May 2, 2024
b78fae5
refactor: use fine grained updates for cells array reactivity
mgreminger May 3, 2024
3f8b2be
feat: make deleted cell placeholder match height of deleted cell
mgreminger May 4, 2024
1920277
feat: escape key cancels cell delete
mgreminger May 5, 2024
d165d37
feat: keyboard can be used to navigate button focus in the cell inser…
mgreminger May 5, 2024
d962bdc
fix: increase min width of editable math fields
mgreminger May 5, 2024
ea11a25
tests: update reference screenshots for larger math-field min-width
mgreminger May 6, 2024
e819641
Bump mathlive fork to remove unnecessary scaling
mgreminger May 8, 2024
fab2642
fix: ensure undo delete button is visible
mgreminger May 9, 2024
411a5ae
fix: prevent math-field from handling Control+Minus
mgreminger May 10, 2024
69ba89e
refactor: prevent uneccesary repeated parsing of table cells
mgreminger May 12, 2024
fd11132
refactor: only run parseTableStatements if selected row is changed
mgreminger May 12, 2024
6fc61ab
refactor: only parse piecewise cells when they are edited
mgreminger May 12, 2024
6cf373f
fix: table statements need to be parsed on any edit
mgreminger May 12, 2024
a653a69
refactor: use cache to speed up duplicate calls parseTableStatements
mgreminger May 12, 2024
e766b4a
Bump version and add entry to updates modal
mgreminger May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"idb-keyval": "^6.2.0",
"mathjax": "^3.2.2",
"mathjs": "^11.8.2",
"mathlive": "github:mgreminger/mathlive#29b14918088a7f0ad9f8204f982447a7dbc6c8df",
"mathlive": "github:mgreminger/mathlive#bbe2b44a1f84f4107784a2f92beda30bc62411f1",
"plotly.js-basic-dist": "github:mgreminger/plotly.js#dist-basic-for-ep",
"quick-lru": "^6.1.1",
"quill": "^1.3.7",
Expand Down
71 changes: 41 additions & 30 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -90,7 +90,7 @@

const apiUrl = window.location.origin;

const currentVersion = 20240418;
const currentVersion = 20240513;
const tutorialHash = "fFjTsnFoSQMLwcvteVoNtL";

const termsVersion = 20240110;
Expand Down Expand Up @@ -762,7 +762,7 @@
refreshSheet(); // pushState does not trigger onpopstate event
}

function getResults(statementsAndSystems: string, myRefreshCount: bigint) {
function getResults(statementsAndSystems: string, myRefreshCount: BigInt) {
return new Promise<Results>((resolve, reject) => {
function handleWorkerMessage(e) {
forcePyodidePromiseRejection = null;
Expand Down Expand Up @@ -819,13 +819,14 @@
statements.push(mathField.statement);
}
} else if (cell instanceof TableCell) {
const newStatements = cell.parseTableStatements();
const newStatements = cell.tableStatements;
for (const statement of newStatements) {
endStatements.push(statement);
}
} else if (cell instanceof PiecewiseCell) {
const statement = cell.parsePiecewiseStatement(cellNum);
endStatements.push(statement);
if (cell.piecewiseStatement) {
endStatements.push(cell.piecewiseStatement);
}
} else if (cell instanceof SystemCell) {
const systemDefinition = cell.getSystemDefinition();
if (systemDefinition) {
Expand Down Expand Up @@ -869,15 +870,18 @@
}
}

async function handleCellUpdate() {
const myRefreshCount = ++refreshCounter;
async function handleCellUpdate(localRefreshCounter: BigInt) {
if (localRefreshCounter !== refreshCounter) {
return;
}
const myRefreshCount = localRefreshCounter;
const firstRunAfterSheetLoad = initialSheetLoad;
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 = [];
// invalidate 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;
Expand All @@ -887,17 +891,20 @@
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()) {
if ((cell.type === "math" || cell.type === "plot") ) {
$results[i] = data.results[counter++];
} else {
$results[i] = null;
}
}
}
Expand All @@ -907,6 +914,8 @@
for (const [i, cell] of $cells.entries()) {
if (cell.type === "system") {
$system_results[i] = data.systemResults[counter++]
} else {
$system_results[i] = null;
}
}
if (!firstRunAfterSheetLoad) {
Expand Down Expand Up @@ -1088,6 +1097,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;

Expand All @@ -1112,10 +1122,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 = [];
}

Expand Down Expand Up @@ -1477,6 +1489,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);
Expand Down Expand Up @@ -1910,29 +1923,21 @@ Please include a link to this sheet in the email to assist in debugging the prob
};
}

$:{
if (document.hasFocus() && showKeyboard !== Boolean($activeMathField)) {
$:if (document.hasFocus() && showKeyboard !== Boolean($activeMathField)) {
showKeyboard = Boolean($activeMathField);
}
}

$: {
document.title = `EngineeringPaper.xyz: ${$title}`;
}
$: document.title = `EngineeringPaper.xyz: ${$title}`;

$: if($cells) {
$: if($mathCellChanged) {
refreshCounter++;
$mathCellChanged = false;
noParsingErrors = !checkParsingErrors();
}

$: if ($cells || $mathCellChanged) {
if($mathCellChanged) {
if (initialSheetLoad) {
handleCellUpdate();
} else {
inDebounce = true;
debounceHandleCellUpdate();
}
$mathCellChanged = false;
if (initialSheetLoad) {
handleCellUpdate(refreshCounter);
} else {
inDebounce = true;
debounceHandleCellUpdate(refreshCounter);
}
$unsavedChange = true;
$autosaveNeeded = true;
Expand Down Expand Up @@ -2192,6 +2197,12 @@ Please include a link to this sheet in the email to assist in debugging the prob
}
}

@media (max-width: 450px) {
:global(.hide-when-kinda-narrow) {
display: none;
}
}

@media (max-width: 400px) {
:global(.hide-when-narrow) {
display: none;
Expand Down
31 changes: 15 additions & 16 deletions src/Cell.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import { cells, results, activeCell, mathCellChanged, handleClickInCell, deleteCell } from "./stores";
import { createEventDispatcher, onMount } from "svelte";
import { cells, results, system_results, activeCell,
mathCellChanged, handleClickInCell, deleteCell } from "./stores";
import type { Cell } from './cells/Cells';
import MathCellElement from "./MathCell.svelte";
import DocumentationCellElement from "./DocumentationCell.svelte";
Expand Down Expand Up @@ -46,15 +47,17 @@
}
}

onMount(() => {
if(cell instanceof DeletedCell && cell.height > 0) {
contentDiv.setAttribute("style", `height: ${cell.height}px;`);
}
});

function moveUp(index) {
if (index > 0) {
let newCells = $cells.slice(0,index-1);
newCells.push($cells[index]);
newCells.push($cells[index-1]);
newCells = newCells.concat($cells.slice(index+1, $cells.length+1));
$cells = newCells;

$results = [];
$cells = [...$cells.slice(0,index-1), $cells[index], $cells[index-1], ...$cells.slice(index+1, $cells.length+1)];
$results = [...$results.slice(0,index-1), $results[index], $results[index-1], ...$results.slice(index+1, $cells.length+1)];
$system_results = [...$system_results.slice(0,index-1), $system_results[index], $system_results[index-1], ...$system_results.slice(index+1, $cells.length+1)];

if (index === $activeCell) {
$activeCell--;
Expand All @@ -66,13 +69,9 @@

function moveDown(index) {
if (index < $cells.length-1) {
let newCells = $cells.slice(0, index);
newCells.push($cells[index+1]);
newCells.push($cells[index]);
newCells = newCells.concat($cells.slice(index+2, $cells.length+1));
$cells = newCells;

$results = [];
$cells = [...$cells.slice(0, index), $cells[index+1], $cells[index], ...$cells.slice(index+2, $cells.length+1)];
$results = [...$results.slice(0, index), $results[index+1], $results[index], ...$results.slice(index+2, $cells.length+1)];
$system_results = [...$system_results.slice(0, index), $system_results[index+1], $system_results[index], ...$system_results.slice(index+2, $cells.length+1)];

if (index === $activeCell) {
$activeCell++;
Expand Down
21 changes: 19 additions & 2 deletions src/CellList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { tick } from "svelte";
import { flip } from "svelte/animate";

import { cells, results, activeCell, prefersReducedMotion, mathCellChanged } from "./stores";
import { cells, results, system_results, activeCell, mathCellChanged } from "./stores";
import Cell from "./Cell.svelte";
import ButtonBar from "./ButtonBar.svelte";

Expand Down Expand Up @@ -124,16 +124,33 @@
$cells = [...$cells.slice(0,targetIndex), $cells[draggingSourceIndex],
...$cells.slice(targetIndex, draggingSourceIndex),
...$cells.slice(draggingSourceIndex+1)];

$results = [...$results.slice(0,targetIndex), $results[draggingSourceIndex],
...$results.slice(targetIndex, draggingSourceIndex),
...$results.slice(draggingSourceIndex+1)];

$system_results = [...$system_results.slice(0,targetIndex), $system_results[draggingSourceIndex],
...$system_results.slice(targetIndex, draggingSourceIndex),
...$system_results.slice(draggingSourceIndex+1)];
} else {
$cells = [...$cells.slice(0,draggingSourceIndex),
...$cells.slice(draggingSourceIndex+1, targetIndex+1),
$cells[draggingSourceIndex],
...$cells.slice(targetIndex+1)];

$results = [...$results.slice(0,draggingSourceIndex),
...$results.slice(draggingSourceIndex+1, targetIndex+1),
$results[draggingSourceIndex],
...$results.slice(targetIndex+1)];

$system_results = [...$system_results.slice(0,draggingSourceIndex),
...$system_results.slice(draggingSourceIndex+1, targetIndex+1),
$system_results[draggingSourceIndex],
...$system_results.slice(targetIndex+1)];
}

draggingSourceIndex = targetIndex;

$results = [];
$mathCellChanged = true;
}

Expand Down
Loading
Loading