diff --git a/CSharpMath.Editor/Keyboards/MathKeyboard.cs b/CSharpMath.Editor/Keyboards/MathKeyboard.cs index 92f75afcd..81b368010 100644 --- a/CSharpMath.Editor/Keyboards/MathKeyboard.cs +++ b/CSharpMath.Editor/Keyboards/MathKeyboard.cs @@ -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)); } }