Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
105 changes: 101 additions & 4 deletions CSharpMath.Editor.Tests/KeyPressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,116 @@ public void Return(params K[] inputs) =>
[
Theory,
T(@"", K.Backspace, K.Backspace, K.Backspace, K.Backspace, K.Backspace),
T(@"2", K.Backspace, K.Backspace, K.D1, K.Backspace, K.D2),
T(@"1", K.D1, K.D2, K.Backspace),
T(@"x^2", K.SmallX, K.Power, K.D2, K.D1, K.Backspace),
T(@"y_{3_4}", K.SmallY, K.Subscript, K.D3, K.Subscript, K.Backspace, K.Backspace, K.D4, K.D5, K.Backspace),
T(@"5^■", K.D5, K.Power, K.Iota, K.Kappa, K.SmallEta, K.Backspace, K.Backspace, K.Backspace, K.Backspace),
T(@"\frac{■}{\square }", K.Fraction, K.Backspace),
T(@"5", K.D5, K.Power, K.Iota, K.Kappa, K.SmallEta, K.Backspace, K.Backspace, K.Backspace, K.Backspace),
T(@"", K.Fraction, K.Backspace),
T(@"", K.Power, K.Backspace),
T(@"", K.Subscript, K.Backspace),
T(@"", K.SquareRoot, K.Backspace),
T(@"3", K.CubeRoot, K.Backspace),
T(@"", K.NthRoot, K.Backspace),
T(@"a", K.SmallA, K.Fraction, K.Backspace),
T(@"a", K.SmallA, K.SquareRoot, K.Backspace),
T(@"a3", K.SmallA, K.CubeRoot, K.Backspace),
T(@"a", K.SmallA, K.NthRoot, K.Backspace),
T(@"a", K.SmallA, K.Power, K.Backspace),
T(@"a", K.SmallA, K.Subscript, K.Backspace),
T(@"\square ^■", K.Power, K.Subscript, K.Backspace),
T(@"\square ^■", K.Power, K.Power, K.Backspace),
T(@"\square _■", K.Subscript, K.Power, K.Backspace),
T(@"\square _■", K.Subscript, K.Subscript, K.Backspace),
T(@"y_4", K.SmallY, K.Subscript, K.D3, K.Subscript, K.Backspace, K.Backspace, K.D4, K.D5, K.Backspace),
T(@"", K.VerticalBar, K.VerticalBar, K.Backspace, K.Backspace, K.Backspace)
]
public void Backspace(string latex, params K[] inputs) => Test(latex, inputs);

[
Theory,
T(@"", K.Left, K.Left, K.Backspace, K.Backspace, K.Right, K.Right, K.Backspace, K.Backspace, K.Left),
T(@"", K.Power, K.Left, K.Backspace),
T(@"", K.Subscript, K.Left, K.Backspace),
T(@".\frac{\square }{\square }", K.Fraction, K.Left, K.Backspace, K.Decimal),
T(@".\sqrt{\square }", K.SquareRoot, K.Left, K.Backspace, K.Decimal),
T(@".\sqrt[\square ]{\square }", K.NthRoot, K.Left, K.Backspace, K.Decimal),
T(@".\left( \square \right) ", K.BothRoundBrackets, K.Left, K.Backspace, K.Decimal),
T(@".", K.Power, K.Left, K.Backspace, K.Decimal),
T(@".", K.Subscript, K.Left, K.Backspace, K.Decimal),
T(@".\frac{\square }{\square }", K.SmallA, K.Fraction, K.Left, K.Backspace, K.Decimal),
T(@".\sqrt{\square }", K.SmallA, K.SquareRoot, K.Left, K.Backspace, K.Decimal),
T(@".\sqrt[\square ]{\square }", K.SmallA, K.NthRoot, K.Left, K.Backspace, K.Decimal),
T(@".\left( \square \right) ", K.SmallA, K.BothRoundBrackets, K.Left, K.Backspace, K.Decimal),
T(@".^{\square }", K.SmallA, K.Power, K.Left, K.Backspace, K.Decimal),
T(@"._{\square }", K.SmallA, K.Subscript, K.Left, K.Backspace, K.Decimal),
T(@".", K.Fraction, K.Right, K.Backspace, K.Decimal),
T(@".", K.SquareRoot, K.Right, K.Backspace, K.Decimal),
T(@".", K.NthRoot, K.Right, K.Backspace, K.Decimal),
T(@".", K.BothRoundBrackets, K.Right, K.Backspace, K.Decimal),
T(@".", K.Power, K.Right, K.Backspace, K.Decimal),
T(@".", K.Subscript, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.Fraction, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.SquareRoot, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.NthRoot, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.BothRoundBrackets, K.Right, K.Backspace, K.Decimal),
T(@".", K.SmallA, K.Power, K.Right, K.Backspace, K.Decimal),
T(@".", K.SmallA, K.Subscript, K.Right, K.Backspace, K.Decimal),
T(@".", K.Fraction, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.SquareRoot, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.NthRoot, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.BothRoundBrackets, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.Power, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.Subscript, K.Right, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.Fraction, K.Right, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.SquareRoot, K.Right, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.NthRoot, K.Right, K.Right, K.Backspace, K.Decimal),
T(@"a.", K.SmallA, K.BothRoundBrackets, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.SmallA, K.Power, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".", K.SmallA, K.Subscript, K.Right, K.Right, K.Backspace, K.Decimal),
T(@".bcd", K.Fraction, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".bcd", K.SquareRoot, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".bcd", K.NthRoot, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".bcd", K.BothRoundBrackets, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".bcd", K.Power, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".bcd", K.Subscript, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"a.bcd", K.SmallA, K.Fraction, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"a.bcd", K.SmallA, K.SquareRoot, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"a.bcd", K.SmallA, K.NthRoot, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"a.bcd", K.SmallA, K.BothRoundBrackets, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"a.bcd", K.SmallA, K.Power, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"a.bcd", K.SmallA, K.Subscript, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"bcd.", K.Fraction, K.SmallB, K.SmallC, K.SmallD, K.Right, K.Backspace, K.Decimal),
T(@"bcd.", K.NthRoot, K.SmallB, K.SmallC, K.SmallD, K.Right, K.Backspace, K.Decimal),
T(@"abcd.", K.SmallA, K.Fraction, K.SmallB, K.SmallC, K.SmallD, K.Right, K.Backspace, K.Decimal),
T(@"abcd.", K.SmallA, K.NthRoot, K.SmallB, K.SmallC, K.SmallD, K.Right, K.Backspace, K.Decimal),
T(@"bcd.", K.Fraction, K.Right, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"bcd.", K.NthRoot, K.Right, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"abcd.", K.SmallA, K.Fraction, K.Right, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"abcd.", K.SmallA, K.NthRoot, K.Right, K.SmallB, K.SmallC, K.SmallD, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"bcd.efg", K.Fraction, K.SmallB, K.SmallC, K.SmallD, K.Right, K.SmallE, K.SmallF, K.SmallG, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"bcd.efg", K.NthRoot, K.SmallB, K.SmallC, K.SmallD, K.Right, K.SmallE, K.SmallF, K.SmallG, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"abcd.efg", K.SmallA, K.Fraction, K.SmallB, K.SmallC, K.SmallD, K.Right, K.SmallE, K.SmallF, K.SmallG, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"abcd.efg", K.SmallA, K.NthRoot, K.SmallB, K.SmallC, K.SmallD, K.Right, K.SmallE, K.SmallF, K.SmallG, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".456", K.Subscript, K.D4, K.D5, K.D6, K.Left, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".789", K.Power, K.D7, K.D8, K.D9, K.Left, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".456789", K.Subscript, K.D4, K.D5, K.D6, K.Right, K.Power, K.D7, K.D8, K.D9, K.Left, K.Left, K.Left, K.Left, K.Left, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@".456789", K.Power, K.D7, K.D8, K.D9, K.Right, K.Subscript, K.D4, K.D5, K.D6, K.Left, K.Left, K.Left, K.Left, K.Backspace, K.Decimal),
T(@"\square ^{\square }", K.Power, K.Right, K.Subscript, K.Backspace),
T(@"\square _{\square }", K.Subscript, K.Right, K.Power, K.Backspace),
T(@"X^{\square }", K.X, K.Power, K.Right, K.Subscript, K.Backspace),
T(@"X_{\square }", K.X, K.Subscript, K.Right, K.Power, K.Backspace),
T(@"\square ^Z", K.Power, K.Z, K.Right, K.Subscript, K.Backspace),
T(@"\square _{\square }Z", K.Subscript, K.Right, K.Power, K.Z, K.Left, K.Backspace),
T(@"X^Z", K.X, K.Power, K.Z, K.Right, K.Subscript, K.Backspace),
T(@"X_{\square }Z", K.X, K.Subscript, K.Right, K.Power, K.Z, K.Left, K.Backspace),
T(@"\square ^{\square }Y", K.Power, K.Right, K.Subscript, K.Y, K.Left, K.Backspace),
T(@"\square _Y", K.Subscript, K.Y, K.Right, K.Power, K.Backspace),
T(@"X^{\square }Y", K.X, K.Power, K.Right, K.Subscript, K.Y, K.Left, K.Backspace),
T(@"X_Y", K.X, K.Subscript, K.Y, K.Right, K.Power, K.Backspace),
T(@"\square ^ZY", K.Power, K.Z, K.Right, K.Subscript, K.Y, K.Left, K.Backspace),
T(@"\square _YZ", K.Subscript, K.Y, K.Right, K.Power, K.Z, K.Left, K.Backspace),
T(@"X^ZY", K.X, K.Power, K.Z, K.Right, K.Subscript, K.Y, K.Left, K.Backspace),
T(@"X_YZ", K.X, K.Subscript, K.Y, K.Right, K.Power, K.Z, K.Left, K.Backspace),
T(@"\frac{\square }{3}", K.Slash, K.D3, K.Left, K.Left, K.Backspace, K.Left),
T(@"1_3", K.D1, K.D2, K.Subscript, K.D3, K.Left, K.Left, K.Backspace),
T(@"1_3^2", K.D1, K.D4, K.Subscript, K.D3, K.Left, K.Left, K.Power, K.D2, K.Left, K.Left, K.Left, K.Left, K.Backspace),
Expand All @@ -247,7 +345,6 @@ public void Return(params K[] inputs) =>
T(@"\sqrt[■]{\square }", K.NthRoot, K.SmallA, K.Backspace),
T(@"\sqrt{■}", K.SquareRoot, K.SmallA, K.Backspace),
T(@"\frac{1}{■}", K.Slash, K.D6, K.Backspace),
T(@"■_5", K.Subscript, K.D5, K.Left, K.Left, K.Backspace, K.X, K.Left, K.Left, K.Left, K.Backspace),
T(@"7+1^X", K.D7, K.Plus, K.D1, K.D2, K.Power, K.X, K.Left, K.Left, K.Backspace),
T(@"7.^X", K.D7, K.Decimal, K.D1, K.Power, K.X, K.Left, K.Left, K.Backspace),
T(@"7+■^X", K.D7, K.Plus, K.D1, K.Power, K.X, K.Left, K.Left, K.Backspace),
Expand Down
78 changes: 68 additions & 10 deletions CSharpMath.Editor/Extensions/MathList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace CSharpMath.Editor {
using Atom;
using Atoms = Atom.Atoms;
using Structures;
using System.Linq;

partial class Extensions {
static void InsertAtAtomIndexAndAdvance(this MathList self, int atomIndex, MathAtom atom, ref MathListIndex advance, MathListSubIndexType advanceType) {
if (atomIndex < 0 || atomIndex > self.Count)
Expand Down Expand Up @@ -81,12 +83,66 @@ public static void InsertAndAdvance(this MathList self, ref MathListIndex index,
}

public static void RemoveAt(this MathList self, ref MathListIndex index) {
index ??= MathListIndex.Level0Index(0);
void RemoveAtInnerList<TAtom>(ref MathListIndex index, TAtom atom, int innerListIndex) where TAtom : MathAtom, IMathListContainer {

@charlesroddie charlesroddie May 26, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document this a bit? It's not clear from the name of the function and inputs:

  • Is atom an Atom that resides at index?
  • Is atom the thing to be removed, or is instead a subatom of atom residing at innerListIndex within atom?

@Happypig375 Happypig375 May 26, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atom is a MathAtom directly contained in self that contains(index.SubIndex.AtomIndex > -1)/is(index.SubIndex.AtomIndex = -1) the atom to remove.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that takes us closer. What would be the right type for AtomIndex to have? Nullable<int>?

@Happypig375 Happypig375 May 27, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An AtomIndex of -1 indicates deletion at the beginning of line (not pointing to any atom). It is not a valid value for other methods accepting MathListIndex, which is why PreviousOrBeforeWholeList is internal.

if (index.SubIndex is null) throw new InvalidCodePathException($"{nameof(index.SubIndex)} should exist");
if (index.IsBeforeSubList) {
index = index.LevelDown()
?? throw new InvalidCodePathException($"{nameof(index.SubIndex)} is not null but {nameof(index.LevelDown)} is null");
self.RemoveAt(ref index);
MathListIndex tempIndex = index;
int i = 0;
foreach (var innerList in atom.InnerLists)
if (!(innerList.Count == 1 && innerList[0] is Atoms.Placeholder))
if (i++ < innerListIndex) {
foreach (var inner in innerList)
self.InsertAndAdvance(ref index, inner, MathListSubIndexType.None);
tempIndex = index;
}
else
foreach (var inner in innerList)
self.InsertAndAdvance(ref tempIndex, inner, MathListSubIndexType.None);
if(index.SubIndexType != MathListSubIndexType.None && tempIndex.AtomIndex == 0 // We deleted an atom only consisting of placeholders
|| atom.Superscript.Count > 0 || atom.Subscript.Count > 0)
self.InsertAndAdvance(ref tempIndex, LaTeXSettings.Placeholder, MathListSubIndexType.None);
if(atom.Superscript.Count > 0) self[tempIndex.AtomIndex - 1].Superscript.Append(atom.Superscript);
if(atom.Subscript.Count > 0) self[tempIndex.AtomIndex - 1].Subscript.Append(atom.Subscript);
} else atom.InnerLists.ElementAt(innerListIndex).RemoveAt(ref index.SubIndex);
}
void RemoveAtInnerScript(ref MathListIndex index, MathAtom atom, bool superscript) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this function

if (index.SubIndex is null) throw new InvalidCodePathException($"{nameof(index.SubIndex)} should exist");
var script = superscript ? atom.Superscript : atom.Subscript;
if (index.IsBeforeSubList) {
index = index.LevelDown()
?? throw new InvalidCodePathException($"{nameof(index.SubIndex)} is not null but {nameof(index.LevelDown)} is null");
if (atom is Atoms.Placeholder && (superscript ? atom.Subscript : atom.Superscript).Count == 0)
self.RemoveAt(index.AtomIndex);
else index = index.Next;
var tempIndex = index;
if (!(script.Count == 1 && script[0] is Atoms.Placeholder))
foreach (var inner in script)
self.InsertAndAdvance(ref tempIndex, inner, MathListSubIndexType.None);
script.Clear();
} else script.RemoveAt(ref index.SubIndex);
}

if (index.AtomIndex > self.Atoms.Count)
throw new IndexOutOfRangeException($"Index {index.AtomIndex} is out of bounds for list of size {self.Atoms.Count}");
switch (index.SubIndexType) {
case MathListSubIndexType.None:
self.RemoveAt(index.AtomIndex);
if (index.AtomIndex == -1) {
index = index.Next;
if (self.Atoms[index.AtomIndex] is Atoms.Placeholder { Superscript: var super, Subscript: var sub }) {
self.RemoveAt(index.AtomIndex);
var tempIndex = index;
if (!(sub.Count == 1 && sub[0] is Atoms.Placeholder))
foreach (var s in sub)
self.InsertAndAdvance(ref tempIndex, s, MathListSubIndexType.None);
if (!(super.Count == 1 && super[0] is Atoms.Placeholder))
foreach (var s in super)
self.InsertAndAdvance(ref tempIndex, s, MathListSubIndexType.None);
}
} else
self.RemoveAt(index.AtomIndex);
break;
case var _ when index.SubIndex is null:
throw new InvalidCodePathException("index.SubIndex is null despite non-None subindex type");
Expand Down Expand Up @@ -132,33 +188,35 @@ public static void RemoveAt(this MathList self, ref MathListIndex index) {
if (!(self.Atoms[index.AtomIndex] is Atoms.Radical radical))
throw new SubIndexTypeMismatchException(typeof(Atoms.Radical), index);
if (index.SubIndexType == MathListSubIndexType.Degree)
radical.Degree.RemoveAt(ref index.SubIndex);
else radical.Radicand.RemoveAt(ref index.SubIndex);
RemoveAtInnerList(ref index, radical, 0);
else
RemoveAtInnerList(ref index, radical, 1);
break;
case MathListSubIndexType.Numerator:
case MathListSubIndexType.Denominator:
if (!(self.Atoms[index.AtomIndex] is Atoms.Fraction frac))
throw new SubIndexTypeMismatchException(typeof(Atoms.Fraction), index);
if (index.SubIndexType == MathListSubIndexType.Numerator)
frac.Numerator.RemoveAt(ref index.SubIndex);
else frac.Denominator.RemoveAt(ref index.SubIndex);
RemoveAtInnerList(ref index, frac, 0);
else
RemoveAtInnerList(ref index, frac, 1);
break;
case MathListSubIndexType.Subscript:
var current = self.Atoms[index.AtomIndex];
if (current.Subscript.IsEmpty())
throw new SubIndexTypeMismatchException(index);
current.Subscript.RemoveAt(ref index.SubIndex);
RemoveAtInnerScript(ref index, current, false);
break;
case MathListSubIndexType.Superscript:
current = self.Atoms[index.AtomIndex];
if (current.Superscript.IsEmpty())
throw new SubIndexTypeMismatchException(index);
current.Superscript.RemoveAt(ref index.SubIndex);
RemoveAtInnerScript(ref index, current, true);
break;
case MathListSubIndexType.Inner:
if (!(self.Atoms[index.AtomIndex] is Atoms.Inner inner))
throw new SubIndexTypeMismatchException(typeof(Atoms.Inner), index);
inner.InnerList.RemoveAt(ref index.SubIndex);
RemoveAtInnerList(ref index, inner, 0);
break;
default:
throw new SubIndexTypeMismatchException(index);
Expand All @@ -167,7 +225,7 @@ public static void RemoveAt(this MathList self, ref MathListIndex index) {
// We have deleted to the beginning of the line and it is not the outermost line
if (self.AtomAt(index) is null) {
self.InsertAndAdvance(ref index, LaTeXSettings.Placeholder, MathListSubIndexType.None);
index = index.Previous ?? throw new InvalidCodePathException("Cannot go back after insertion?"); ;
index = index.Previous ?? throw new InvalidCodePathException("Cannot go back after insertion?");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions CSharpMath.Editor/MathKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public MathListIndex InsertionIndex {
public LineStyle LineStyle { get; set; }
public Structures.Color SelectColor { get; set; }
public virtual RectangleF Measure => Display?.DisplayBounds() ?? RectangleF.Empty;
public bool HasText => MathList?.Atoms?.Count > 0;
public bool HasText => MathList.Atoms.Count > 0;
public void RecreateDisplayFromMathList() {
var position = Display?.Position ?? default;
Display = Typesetter.CreateLine(MathList, Font, Context, LineStyle);
Expand Down Expand Up @@ -389,7 +389,7 @@ void MoveCursorRight() {

void DeleteBackwards() {
// delete the last atom from the list
if (HasText && _insertionIndex.Previous is MathListIndex previous) {
if (HasText && _insertionIndex.PreviousOrBeforeWholeList is MathListIndex previous) {
_insertionIndex = previous;
MathList.RemoveAt(ref _insertionIndex);
}
Expand Down Expand Up @@ -491,7 +491,7 @@ void InsertSymbolName(string name, bool subscript = false, bool superscript = fa
break;
case MathKeyboardInput.BaseEPower:
InsertAtom(LaTeXSettings.ForAscii((sbyte)'e')
?? throw new InvalidCodePathException("LaTeXDefaults.ForAscii((byte)'e') is null"));
?? throw new InvalidCodePathException($"{nameof(LaTeXSettings.ForAscii)}((sbyte)'e') is null"));
HandleScriptButton(true);
break;
case MathKeyboardInput.Logarithm:
Expand Down
8 changes: 8 additions & 0 deletions CSharpMath.Editor/MathListIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public MathListIndex LevelUpWithSubIndex(MathListSubIndexType type, MathListInde
MathListSubIndexType.None => AtomIndex > 0 ? Level0Index(AtomIndex - 1) : null,
_ => SubIndex?.Previous is MathListIndex prevSubIndex ? IndexAtLocation(AtomIndex, SubIndexType, prevSubIndex) : null,
};
/// <summary>Should be used inside <see cref="Extensions.RemoveAt(Atom.MathList, ref MathListIndex)"/> only!</summary>
internal bool IsBeforeSubList => SubIndex is { AtomIndex: -1, SubIndexType: MathListSubIndexType.None };
/// <summary>Valid for <see cref="Extensions.RemoveAt(Atom.MathList, ref MathListIndex)"/> only!</summary>
internal MathListIndex? PreviousOrBeforeWholeList => SubIndexType switch
{
MathListSubIndexType.None => AtomIndex > -1 ? Level0Index(AtomIndex - 1) : null,
_ => SubIndex?.PreviousOrBeforeWholeList is MathListIndex prevSubIndex ? IndexAtLocation(AtomIndex, SubIndexType, prevSubIndex) : null,
};

///<summary>Returns the next index.</summary>
public MathListIndex Next => SubIndexType switch
Expand Down
Loading