Skip to content
Merged
Changes from all commits
Commits
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
25 changes: 7 additions & 18 deletions CSharpMath.Editor/Keyboards/MathKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,14 @@ void HandleScriptButton(bool isSuperScript) {
SetScript(emptyAtom, MathAtoms.PlaceholderList);
MathList.InsertAndAdvance(ref _insertionIndex, emptyAtom, subIndexType);
} else {
var prevAtom = MathList.AtomAt(_insertionIndex.Previous);
#warning Simplify to tuple patterns when C# 8 is out
switch ((GetScript(prevAtom) is null, _insertionIndex.FinalSubIndexType is MathListSubIndexType.BetweenBaseAndScripts)) {
case var t when t == (true, true):
SetScript(MathList.AtomAt(_insertionIndex.LevelDown()), MathAtoms.PlaceholderList);
_insertionIndex = _insertionIndex.LevelDown().LevelUpWithSubIndex(subIndexType, MathListIndex.Level0Index(0));
break;
case var t when t == (true, false):
SetScript(prevAtom, MathAtoms.PlaceholderList);
_insertionIndex = _insertionIndex.Previous.LevelUpWithSubIndex(subIndexType, MathListIndex.Level0Index(0));
break;
case var t when t == (false, true):
// If we are already inside the nucleus, then we come out and go up to the script
_insertionIndex = _insertionIndex.LevelDown().LevelUpWithSubIndex(subIndexType, MathListIndex.Level0Index(GetScript(prevAtom).Atoms.Count));
break;
case var t when t == (false, false):
_insertionIndex = _insertionIndex.Previous.LevelUpWithSubIndex(subIndexType, MathListIndex.Level0Index(GetScript(prevAtom).Atoms.Count));
break;
var isBetweenBaseAndScripts = _insertionIndex.FinalSubIndexType is MathListSubIndexType.BetweenBaseAndScripts;
var prevIndexCorrected = isBetweenBaseAndScripts ? _insertionIndex.LevelDown() : _insertionIndex.Previous;
var prevAtom = MathList.AtomAt(prevIndexCorrected);
var script = GetScript(prevAtom);
if (script is null) {
SetScript(prevAtom, MathAtoms.PlaceholderList);
}
_insertionIndex = prevIndexCorrected.LevelUpWithSubIndex(subIndexType, MathListIndex.Level0Index(script?.Atoms?.Count ?? 0));
}
}

Expand Down