From 11de42648234dd36643c50d6c258f22f4df84aea Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Sun, 24 Nov 2019 11:34:05 +0200 Subject: [PATCH] disallow navigation to a BetweenBaseAndScripts position when base is placeholder --- CSharpMath.Editor/Keyboards/MathKeyboard.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CSharpMath.Editor/Keyboards/MathKeyboard.cs b/CSharpMath.Editor/Keyboards/MathKeyboard.cs index 81b368010..40ad7c757 100644 --- a/CSharpMath.Editor/Keyboards/MathKeyboard.cs +++ b/CSharpMath.Editor/Keyboards/MathKeyboard.cs @@ -226,14 +226,18 @@ void MoveCursorLeft() { } if (_insertionIndex is null) throw new InvalidOperationException($"{nameof(_insertionIndex)} is null."); - if (MathList.AtomAt(_insertionIndex) is null && - MathList.AtomAt(_insertionIndex?.Previous)?.AtomType is MathAtomType.Placeholder) + if (_insertionIndex.FinalSubIndexType is MathListSubIndexType.BetweenBaseAndScripts) { + var prevInd = _insertionIndex.LevelDown(); + if (MathList.AtomAt(prevInd).AtomType is MathAtomType.Placeholder) + _insertionIndex = prevInd; + } else if (MathList.AtomAt(_insertionIndex) is null && MathList.AtomAt(_insertionIndex?.Previous)?.AtomType is MathAtomType.Placeholder) _insertionIndex = _insertionIndex.Previous; // Skip right side of placeholders when end of line } void MoveCursorRight() { if (_insertionIndex is null) throw new InvalidOperationException($"{nameof(_insertionIndex)} is null."); - switch (MathList.AtomAt(_insertionIndex)) { + var currentAtom = MathList.AtomAt(_insertionIndex); + switch (currentAtom) { case null: //After Count var levelDown = _insertionIndex.LevelDown(); switch (_insertionIndex.FinalSubIndexType) { @@ -300,6 +304,8 @@ void MoveCursorRight() { } if (_insertionIndex is null) throw new InvalidOperationException($"{nameof(_insertionIndex)} is null."); + if (_insertionIndex.FinalSubIndexType is MathListSubIndexType.BetweenBaseAndScripts && currentAtom?.AtomType is MathAtomType.Placeholder) + MoveCursorRight(); } void DeleteBackwards() {