Skip to content

Commit 57ddb6d

Browse files
more work
1 parent 57bb574 commit 57ddb6d

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/publicapi.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,43 @@ function getInterface(v: number): MathQuill.v3.API | MathQuill.v1.API {
364364
} else {
365365
console.log('REAL CURSOR[PARENT]', cursor.parent);
366366
console.log('REAL CURSOR[L]', cursor[L]);
367-
console.log('REAL CURSOR[R]', cursor[R]);
368367
}
369368
console.log('---- simulate applying selection ---');
370369
const results = this.__controller.exportLatexSelection(uncleanedIndicies);
371370
console.log('=== done simulate applying selection ===');
372371

373372
if (cursor.selection) {
373+
console.log(
374+
'[FOUND] selectionL: ',
375+
results.ctx.restoreInfo?.selectionL
376+
);
377+
console.log(
378+
'[FOUND] selectionR: ',
379+
results.ctx.restoreInfo?.selectionR
380+
);
381+
374382
if (
375383
cursor.selection.getEnd(L) !== results.ctx.restoreInfo?.selectionL ||
376384
cursor.selection.getEnd(R) !== results.ctx.restoreInfo?.selectionR
377385
) {
378-
// TODO -- I think maybe this is now never being hit. SelectionL and SelectionR might be solid.
386+
// TODO - I think maybe this is correct and never hit now
379387
console.log('computed wrong selection');
380388
debugger;
381389
}
382390
} else {
383-
if (cursor.parent !== results.ctx.restoreInfo?.cursorParent) {
391+
console.log(
392+
'[FOUND] cursorParent: ',
393+
results.ctx.restoreInfo?.cursorParent
394+
);
395+
console.log('[FOUND] cursorL: ', results.ctx.restoreInfo?.cursorL);
396+
397+
if (
398+
cursor.parent !== results.ctx.restoreInfo?.cursorParent ||
399+
cursor[L] !== results.ctx.restoreInfo?.cursorL
400+
) {
384401
// TODO -- computing the wrong parent when you put cursor inside of an empty () or empty sqrt(). I think
385402
// there's something about MathBlocks that are special.
386-
// TODO -- not even trying to get cursorL and cursorR correct yet.
387-
console.log('wrong cursor parent');
403+
console.log('wrong cursor');
388404
debugger;
389405
}
390406
}

src/tree.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,11 @@ class NodeBase {
367367
if (restoreInfo.endIndex === restoreInfo.startIndex) {
368368
// caret
369369
if (latexLength === restoreInfo.startIndex) {
370-
//if (!restoreInfo.cursorParent) {
371370
restoreInfo.cursorParent = this.parent;
372371
console.log('Cursor parent =', this.parent);
373-
//}
374372

375-
console.log('Cursor start = ', this);
373+
console.log('set Cursor[L] = ', 0);
374+
restoreInfo.cursorL = 0 as any;
376375
}
377376
} else {
378377
// selection
@@ -404,14 +403,27 @@ class NodeBase {
404403
if (latexLength === restoreInfo.endIndex) {
405404
if (restoreInfo.startIndex === restoreInfo.endIndex) {
406405
// caret
407-
console.log('Cursor end = ', this);
406+
if (!restoreInfo.cursorL) {
407+
console.log('set Cursor[L] = ', this);
408+
restoreInfo.cursorL = this;
409+
}
410+
408411
if (!restoreInfo.cursorParent) {
409412
console.log('Cursor parent =', this.parent);
410413
restoreInfo.cursorParent = this.parent;
414+
} else if (restoreInfo.cursorParent === this.parent) {
415+
// this seems important for when we enter an empty MathBlock. For instance cursor in between "()" or
416+
// in an empty square root.
417+
console.log('RESETTING Cursor parent =', this.parent);
418+
restoreInfo.cursorParent = this;
411419
}
412420
} else {
413421
// selection
414-
restoreInfo.selectionR = this;
422+
// it seems like when closing the selection we want the very first node that matches
423+
// the index, not any later ones.
424+
if (!restoreInfo.selectionR) {
425+
restoreInfo.selectionR = this;
426+
}
415427
}
416428
}
417429
}

0 commit comments

Comments
 (0)