Skip to content

Commit 66f7eea

Browse files
remove uncleanedLatex from opaqueSnapshot
1 parent df2216c commit 66f7eea

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/mathquill.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ declare namespace MathQuill {
2424
startIndex: number;
2525
endIndex: number;
2626
opaqueSnapshot: {
27-
uncleanedLatex: string;
2827
cursorInsertPath: string;
2928
signedSelectionSize: number;
3029
};

src/publicapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function getInterface(v: number): MathQuill.v3.API | MathQuill.v1.API {
346346
return this;
347347
}
348348

349-
return this.__controller.exportLatexSelection();
349+
return this.__controller.exportLatexSelection().selection;
350350
}
351351
html() {
352352
return this.__controller.root

src/services/latex.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type ExportedLatexSelection = {
99
startIndex: number;
1010
endIndex: number;
1111
opaqueSnapshot: {
12-
uncleanedLatex: string;
1312
cursorInsertPath: string;
1413
signedSelectionSize: number;
1514
};
@@ -192,14 +191,20 @@ class Controller_latex extends Controller_keystroke {
192191
}
193192

194193
restoreLatexSelection(data: ExportedLatexSelection) {
195-
const currentUncleanedLatex =
196-
this.exportLatexSelection().opaqueSnapshot.uncleanedLatex;
197-
const { cursorInsertPath, signedSelectionSize, uncleanedLatex } =
198-
data.opaqueSnapshot;
199-
200-
// verify the uncleanedLatex are identical. We need the trees to be identical so that the
201-
// path instructions are relative to an identical tree structure
202-
if (currentUncleanedLatex !== uncleanedLatex) return;
194+
const currentSelectionInfo = this.exportLatexSelection();
195+
const currentLatex = currentSelectionInfo.selection.latex;
196+
const newLatex = data.latex;
197+
const { cursorInsertPath, signedSelectionSize } = data.opaqueSnapshot;
198+
199+
// latex's must match for the indicies in the selection to match up
200+
if (currentLatex !== newLatex) return;
201+
202+
// TODO - track things better so that we can actually make this work
203+
if (currentLatex !== currentSelectionInfo.ctx.latex) {
204+
throw new Error(
205+
'TODO - restoring selection requires uncleanedLatex to match latex'
206+
);
207+
}
203208

204209
if (!this.insertCursorAtPath(cursorInsertPath)) return;
205210

@@ -238,7 +243,10 @@ class Controller_latex extends Controller_keystroke {
238243
return count;
239244
}
240245

241-
exportLatexSelection(): ExportedLatexSelection {
246+
exportLatexSelection(): {
247+
selection: ExportedLatexSelection;
248+
ctx: LatexContext;
249+
} {
242250
var ctx: LatexContext = {
243251
latex: '',
244252
startIndex: -1,
@@ -305,14 +313,16 @@ class Controller_latex extends Controller_keystroke {
305313
}
306314

307315
return {
308-
latex: cleanLatex,
309-
startIndex: startIndex,
310-
endIndex: endIndex,
311-
opaqueSnapshot: {
312-
uncleanedLatex,
313-
cursorInsertPath,
314-
signedSelectionSize
315-
}
316+
selection: {
317+
latex: cleanLatex,
318+
startIndex: startIndex,
319+
endIndex: endIndex,
320+
opaqueSnapshot: {
321+
cursorInsertPath,
322+
signedSelectionSize
323+
}
324+
},
325+
ctx
316326
};
317327
}
318328

test/unit/latex.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ suite('latex', function () {
677677
// we tried setting
678678
const originalSnapShot = mq.selection();
679679
mq2.latex('');
680-
mq2.latex(originalSnapShot.opaqueSnapshot.uncleanedLatex);
680+
mq2.latex(originalSnapShot.latex);
681681
mq2.selection(originalSnapShot);
682682
const restoredSnapShot = mq2.selection();
683683
assert.equal(

0 commit comments

Comments
 (0)