Skip to content

Commit 1b30e5d

Browse files
rename some properties to uncleanedLatex, uncleanedStartIndex, uncleanedEndIndex
1 parent 4f936cb commit 1b30e5d

File tree

7 files changed

+75
-75
lines changed

7 files changed

+75
-75
lines changed

src/commands/math.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,19 @@ class MathCommand extends MathElement {
282282
latexRecursive(ctx: LatexContext) {
283283
this.checkCursorContextOpen(ctx);
284284

285-
ctx.latex += this.ctrlSeq || '';
285+
ctx.uncleanedLatex += this.ctrlSeq || '';
286286
this.eachChild((child) => {
287-
ctx.latex += '{';
287+
ctx.uncleanedLatex += '{';
288288

289-
let beforeLength = ctx.latex.length;
289+
let beforeLength = ctx.uncleanedLatex.length;
290290
child.latexRecursive(ctx);
291-
let afterLength = ctx.latex.length;
291+
let afterLength = ctx.uncleanedLatex.length;
292292
if (beforeLength === afterLength) {
293293
// nothing was written so we write a space
294-
ctx.latex += ' ';
294+
ctx.uncleanedLatex += ' ';
295295
}
296296

297-
ctx.latex += '}';
297+
ctx.uncleanedLatex += '}';
298298
});
299299

300300
this.checkCursorContextClose(ctx);
@@ -405,7 +405,7 @@ class MQSymbol extends MathCommand {
405405

406406
latexRecursive(ctx: LatexContext) {
407407
this.checkCursorContextOpen(ctx);
408-
ctx.latex += this.ctrlSeq || '';
408+
ctx.uncleanedLatex += this.ctrlSeq || '';
409409
this.checkCursorContextClose(ctx);
410410
}
411411
text() {

src/commands/math/LatexCommandInput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ CharCmds['\\'] = class LatexCommandInput extends MathCommand {
9595
latexRecursive(ctx: LatexContext) {
9696
this.checkCursorContextOpen(ctx);
9797

98-
ctx.latex += '\\';
98+
ctx.uncleanedLatex += '\\';
9999
this.getEnd(L).latexRecursive(ctx);
100-
ctx.latex += ' ';
100+
ctx.uncleanedLatex += ' ';
101101

102102
this.checkCursorContextClose(ctx);
103103
}

src/commands/math/commands.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ LatexCmds.textcolor = class extends MathCommand {
259259
latexRecursive(ctx: LatexContext) {
260260
this.checkCursorContextOpen(ctx);
261261
var blocks0 = this.blocks![0];
262-
ctx.latex += '\\textcolor{' + this.color + '}{';
262+
ctx.uncleanedLatex += '\\textcolor{' + this.color + '}{';
263263
blocks0.latexRecursive(ctx);
264-
ctx.latex += '}';
264+
ctx.uncleanedLatex += '}';
265265
this.checkCursorContextClose(ctx);
266266
}
267267
parser() {
@@ -314,9 +314,9 @@ var Class = (LatexCmds['class'] = class extends MathCommand {
314314
this.checkCursorContextOpen(ctx);
315315

316316
var blocks0 = this.blocks![0];
317-
ctx.latex += '\\class{' + this.cls + '}{';
317+
ctx.uncleanedLatex += '\\class{' + this.cls + '}{';
318318
blocks0.latexRecursive(ctx);
319-
ctx.latex += '}';
319+
ctx.uncleanedLatex += '}';
320320

321321
this.checkCursorContextClose(ctx);
322322
}
@@ -488,29 +488,29 @@ class SupSub extends MathCommand {
488488
this.checkCursorContextOpen(ctx);
489489

490490
if (this.sub) {
491-
ctx.latex += '_{';
492-
const beforeLength = ctx.latex.length;
491+
ctx.uncleanedLatex += '_{';
492+
const beforeLength = ctx.uncleanedLatex.length;
493493
this.sub.latexRecursive(ctx);
494-
const afterLength = ctx.latex.length;
494+
const afterLength = ctx.uncleanedLatex.length;
495495
if (beforeLength === afterLength) {
496496
// nothing was written. so we write a space
497-
ctx.latex += ' ';
497+
ctx.uncleanedLatex += ' ';
498498
}
499499

500-
ctx.latex += '}';
500+
ctx.uncleanedLatex += '}';
501501
}
502502

503503
if (this.sup) {
504-
ctx.latex += '^{';
505-
const beforeLength = ctx.latex.length;
504+
ctx.uncleanedLatex += '^{';
505+
const beforeLength = ctx.uncleanedLatex.length;
506506
this.sup.latexRecursive(ctx);
507-
const afterLength = ctx.latex.length;
507+
const afterLength = ctx.uncleanedLatex.length;
508508
if (beforeLength === afterLength) {
509509
// nothing was written. so we write a space
510-
ctx.latex += ' ';
510+
ctx.uncleanedLatex += ' ';
511511
}
512512

513-
ctx.latex += '}';
513+
ctx.uncleanedLatex += '}';
514514
}
515515

516516
this.checkCursorContextClose(ctx);
@@ -727,25 +727,25 @@ class SummationNotation extends MathCommand {
727727
latexRecursive(ctx: LatexContext) {
728728
this.checkCursorContextOpen(ctx);
729729

730-
ctx.latex += this.ctrlSeq + '_{';
731-
let beforeLength = ctx.latex.length;
730+
ctx.uncleanedLatex += this.ctrlSeq + '_{';
731+
let beforeLength = ctx.uncleanedLatex.length;
732732
this.getEnd(L).latexRecursive(ctx);
733-
let afterLength = ctx.latex.length;
733+
let afterLength = ctx.uncleanedLatex.length;
734734
if (afterLength === beforeLength) {
735735
// nothing was written so we write a space
736-
ctx.latex += ' ';
736+
ctx.uncleanedLatex += ' ';
737737
}
738738

739-
ctx.latex += '}^{';
740-
beforeLength = ctx.latex.length;
739+
ctx.uncleanedLatex += '}^{';
740+
beforeLength = ctx.uncleanedLatex.length;
741741
this.getEnd(R).latexRecursive(ctx);
742-
afterLength = ctx.latex.length;
742+
afterLength = ctx.uncleanedLatex.length;
743743
if (beforeLength === afterLength) {
744744
// nothing was written so we write a space
745-
ctx.latex += ' ';
745+
ctx.uncleanedLatex += ' ';
746746
}
747747

748-
ctx.latex += '}';
748+
ctx.uncleanedLatex += '}';
749749
this.checkCursorContextClose(ctx);
750750
}
751751
mathspeak() {
@@ -1069,7 +1069,7 @@ class Token extends MQSymbol {
10691069
latexRecursive(ctx: LatexContext): void {
10701070
this.checkCursorContextOpen(ctx);
10711071

1072-
ctx.latex += '\\token{' + this.tokenId + '}';
1072+
ctx.uncleanedLatex += '\\token{' + this.tokenId + '}';
10731073

10741074
this.checkCursorContextClose(ctx);
10751075
}
@@ -1175,11 +1175,11 @@ class NthRoot extends SquareRoot {
11751175
latexRecursive(ctx: LatexContext) {
11761176
this.checkCursorContextOpen(ctx);
11771177

1178-
ctx.latex += '\\sqrt[';
1178+
ctx.uncleanedLatex += '\\sqrt[';
11791179
this.getEnd(L).latexRecursive(ctx);
1180-
ctx.latex += ']{';
1180+
ctx.uncleanedLatex += ']{';
11811181
this.getEnd(R).latexRecursive(ctx);
1182-
ctx.latex += '}';
1182+
ctx.uncleanedLatex += '}';
11831183

11841184
this.checkCursorContextClose(ctx);
11851185
}
@@ -1328,9 +1328,9 @@ class Bracket extends DelimsNode {
13281328
latexRecursive(ctx: LatexContext) {
13291329
this.checkCursorContextOpen(ctx);
13301330

1331-
ctx.latex += '\\left' + this.sides[L].ctrlSeq;
1331+
ctx.uncleanedLatex += '\\left' + this.sides[L].ctrlSeq;
13321332
this.getEnd(L).latexRecursive(ctx);
1333-
ctx.latex += '\\right' + this.sides[R].ctrlSeq;
1333+
ctx.uncleanedLatex += '\\right' + this.sides[R].ctrlSeq;
13341334

13351335
this.checkCursorContextClose(ctx);
13361336
}
@@ -1869,7 +1869,7 @@ class EmbedNode extends MQSymbol {
18691869
latexRecursive(ctx: LatexContext): void {
18701870
this.checkCursorContextOpen(ctx);
18711871

1872-
ctx.latex += this.latex();
1872+
ctx.uncleanedLatex += this.latex();
18731873

18741874
this.checkCursorContextClose(ctx);
18751875
}

src/commands/text.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ class TextBlock extends MQNode {
8585

8686
var contents = this.textContents();
8787
if (contents.length > 0) {
88-
ctx.latex += this.ctrlSeq + '{';
89-
ctx.latex += contents
88+
ctx.uncleanedLatex += this.ctrlSeq + '{';
89+
ctx.uncleanedLatex += contents
9090
.replace(/\\/g, '\\backslash ')
9191
.replace(/[{}]/g, '\\$&');
92-
ctx.latex += '}';
92+
ctx.uncleanedLatex += '}';
9393
}
9494

9595
this.checkCursorContextClose(ctx);
@@ -361,7 +361,7 @@ class TextPiece extends MQNode {
361361
}
362362
latexRecursive(ctx: LatexContext) {
363363
this.checkCursorContextOpen(ctx);
364-
ctx.latex += this.textStr;
364+
ctx.uncleanedLatex += this.textStr;
365365
this.checkCursorContextClose(ctx);
366366
}
367367

@@ -509,9 +509,9 @@ class RootMathCommand extends MathCommand {
509509
}
510510
latexRecursive(ctx: LatexContext) {
511511
this.checkCursorContextOpen(ctx);
512-
ctx.latex += '$';
512+
ctx.uncleanedLatex += '$';
513513
this.getEnd(L).latexRecursive(ctx);
514-
ctx.latex += '$';
514+
ctx.uncleanedLatex += '$';
515515
this.checkCursorContextClose(ctx);
516516
}
517517
}

src/services/latex.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class Controller_latex extends Controller_keystroke {
156156
// pass through the tree looking for the nodes at the startIndex and endIndex
157157
const mappedIndices = mapFromCleanedToUncleanedIndices(
158158
oldLatex,
159-
oldSelectionInfo.ctx.latex,
159+
oldSelectionInfo.ctx.uncleanedLatex,
160160
newSelection
161161
);
162162

@@ -217,15 +217,15 @@ class Controller_latex extends Controller_keystroke {
217217
ctx: LatexContext;
218218
} {
219219
var ctx: LatexContext = {
220-
latex: '',
221-
startIndex: -1,
222-
endIndex: -1
220+
uncleanedLatex: '',
221+
uncleanedStartIndex: -1,
222+
uncleanedEndIndex: -1
223223
};
224224

225225
if (restoreInfo) {
226226
ctx.restoreInfo = {
227-
startIndex: restoreInfo.uncleanStartIndex,
228-
endIndex: restoreInfo.uncleanEndIndex
227+
uncleanedStartIndex: restoreInfo.uncleanStartIndex,
228+
uncleanedEndIndex: restoreInfo.uncleanEndIndex
229229
};
230230
}
231231

@@ -252,7 +252,7 @@ class Controller_latex extends Controller_keystroke {
252252
this.root.latexRecursive(ctx);
253253

254254
// need to clean the latex
255-
var uncleanedLatex = ctx.latex;
255+
var uncleanedLatex = ctx.uncleanedLatex;
256256
var cleanLatex = this.cleanLatex(uncleanedLatex);
257257
const { startIndex, endIndex } = mapFromUncleanedToCleanedIndices(
258258
uncleanedLatex,
@@ -544,10 +544,10 @@ class Controller_latex extends Controller_keystroke {
544544
function mapFromUncleanedToCleanedIndices(
545545
uncleanedLatex: string,
546546
cleanedLatex: string,
547-
indices: { startIndex: number; endIndex: number }
547+
indices: { uncleanedStartIndex: number; uncleanedEndIndex: number }
548548
) {
549-
var startIndex = indices.startIndex;
550-
var endIndex = indices.endIndex;
549+
var startIndex = indices.uncleanedStartIndex;
550+
var endIndex = indices.uncleanedEndIndex;
551551

552552
// assumes that the cleaning process will only remove space characters. We
553553
// run through the uncleanedLatex and cleanLatex to find differences.
@@ -556,11 +556,11 @@ function mapFromUncleanedToCleanedIndices(
556556
// startIndex and endIndex if appropriate.
557557
for (
558558
var uncleanIdx = 0, cleanIdx = 0;
559-
uncleanIdx < indices.endIndex;
559+
uncleanIdx < indices.uncleanedEndIndex;
560560
uncleanIdx++
561561
) {
562562
if (uncleanedLatex[uncleanIdx] !== cleanedLatex[cleanIdx]) {
563-
if (uncleanIdx < indices.startIndex) {
563+
if (uncleanIdx < indices.uncleanedStartIndex) {
564564
startIndex -= 1;
565565
}
566566
endIndex -= 1;

src/shared_types.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ type InequalityData = {
3838
};
3939

4040
type LatexContext = {
41-
latex: string;
42-
startIndex: number;
43-
endIndex: number;
41+
uncleanedLatex: string;
42+
uncleanedStartIndex: number;
43+
uncleanedEndIndex: number;
4444
startSelectionBefore?: NodeBase;
4545
startSelectionAfter?: NodeBase;
4646
endSelectionBefore?: NodeBase;
4747
endSelectionAfter?: NodeBase;
4848
restoreInfo?: {
49-
startIndex: number;
50-
endIndex: number;
49+
uncleanedStartIndex: number;
50+
uncleanedEndIndex: number;
5151
selectionL?: NodeBase;
5252
selectionR?: NodeBase;
5353

src/tree.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,26 +339,26 @@ class NodeBase {
339339
return '';
340340
}
341341
latex() {
342-
let ctx: LatexContext = { latex: '', startIndex: -1, endIndex: -1 };
342+
let ctx: LatexContext = { uncleanedLatex: '', uncleanedStartIndex: -1, uncleanedEndIndex: -1 };
343343
this.latexRecursive(ctx);
344-
return ctx.latex;
344+
return ctx.uncleanedLatex;
345345
}
346346
latexRecursive(_ctx: LatexContext): void {}
347347
checkCursorContextOpen(ctx: LatexContext) {
348-
const latexLength = ctx.latex.length;
348+
const latexLength = ctx.uncleanedLatex.length;
349349
if (ctx.startSelectionBefore === this) {
350-
ctx.startIndex = latexLength;
350+
ctx.uncleanedStartIndex = latexLength;
351351
}
352352
if (ctx.endSelectionBefore === this) {
353-
ctx.endIndex = latexLength;
353+
ctx.uncleanedEndIndex = latexLength;
354354
}
355355

356356
const restoreInfo = ctx.restoreInfo;
357357
if (restoreInfo) {
358-
if (latexLength === restoreInfo.startIndex) {
359-
if (restoreInfo.endIndex === restoreInfo.startIndex) {
358+
if (latexLength === restoreInfo.uncleanedStartIndex) {
359+
if (restoreInfo.uncleanedEndIndex === restoreInfo.uncleanedStartIndex) {
360360
// caret
361-
if (latexLength === restoreInfo.startIndex) {
361+
if (latexLength === restoreInfo.uncleanedStartIndex) {
362362
restoreInfo.cursorParent = this.parent;
363363
}
364364
} else {
@@ -369,19 +369,19 @@ class NodeBase {
369369
}
370370
}
371371
checkCursorContextClose(ctx: LatexContext) {
372-
const latexLength = ctx.latex.length;
372+
const latexLength = ctx.uncleanedLatex.length;
373373

374374
if (ctx.startSelectionAfter === this) {
375-
ctx.startIndex = latexLength;
375+
ctx.uncleanedStartIndex = latexLength;
376376
}
377377
if (ctx.endSelectionAfter === this) {
378-
ctx.endIndex = latexLength;
378+
ctx.uncleanedEndIndex = latexLength;
379379
}
380380

381381
const restoreInfo = ctx.restoreInfo;
382382
if (restoreInfo) {
383-
if (latexLength === restoreInfo.endIndex) {
384-
if (restoreInfo.startIndex === restoreInfo.endIndex) {
383+
if (latexLength === restoreInfo.uncleanedEndIndex) {
384+
if (restoreInfo.uncleanedStartIndex === restoreInfo.uncleanedEndIndex) {
385385
// caret
386386
if (!restoreInfo.cursorL) {
387387
restoreInfo.cursorL = this;

0 commit comments

Comments
 (0)