From 4e2f1eaedf5682492ec7e2ed0c5e8a4488678246 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Sun, 24 Nov 2019 14:46:14 +0200 Subject: [PATCH] Adjusting of insertion for BothRoundBrackets and Absolute from BetweenBaseAndScripts position --- CSharpMath.Editor.Tests/MathKeyboardTests.cs | 1 + CSharpMath.Editor/Keyboards/MathKeyboard.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CSharpMath.Editor.Tests/MathKeyboardTests.cs b/CSharpMath.Editor.Tests/MathKeyboardTests.cs index 4406b4ca2..3c0458394 100644 --- a/CSharpMath.Editor.Tests/MathKeyboardTests.cs +++ b/CSharpMath.Editor.Tests/MathKeyboardTests.cs @@ -183,6 +183,7 @@ public void Return(params K[] inputs) => 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.Plus, K.D1, K.Power, K.X, K.Left, K.Left, K.Backspace), + T(@"a(c-2)^3", K.SmallA, K.Power, K.D3, K.Left, K.Left, K.BothRoundBrackets, K.SmallC, K.Minus, K.D2) ] public void LeftRightBackspace(string latex, params K[] inputs) => Test(latex, inputs); diff --git a/CSharpMath.Editor/Keyboards/MathKeyboard.cs b/CSharpMath.Editor/Keyboards/MathKeyboard.cs index 40ad7c757..bca4077e7 100644 --- a/CSharpMath.Editor/Keyboards/MathKeyboard.cs +++ b/CSharpMath.Editor/Keyboards/MathKeyboard.cs @@ -155,13 +155,19 @@ void InsertParens() { MathList.InsertAndAdvance(ref _insertionIndex, MathAtoms.ForCharacter('('), MathListSubIndexType.None); MathList.InsertAndAdvance(ref _insertionIndex, MathAtoms.ForCharacter(')'), MathListSubIndexType.None); // Don't go to the next insertion index, to start inserting before the close parens. - _insertionIndex = _insertionIndex.Previous; + if (_insertionIndex.FinalSubIndexType is MathListSubIndexType.BetweenBaseAndScripts) + _insertionIndex = _insertionIndex.LevelDown(); + else + _insertionIndex = _insertionIndex.Previous; } void InsertAbsValue() { MathList.InsertAndAdvance(ref _insertionIndex, MathAtoms.ForCharacter('|'), MathListSubIndexType.None); MathList.InsertAndAdvance(ref _insertionIndex, MathAtoms.ForCharacter('|'), MathListSubIndexType.None); // Don't go to the next insertion index, to start inserting before the close parens. - _insertionIndex = _insertionIndex.Previous; + if (_insertionIndex.FinalSubIndexType is MathListSubIndexType.BetweenBaseAndScripts) + _insertionIndex = _insertionIndex.LevelDown(); + else + _insertionIndex = _insertionIndex.Previous; } void MoveCursorLeft() {