Răsfoiți Sursa

Merge pull request #1357 from sdoroff/text-box-key-down-change

Altered OnKeyDown to accurately set handled
Jeremy Koritzinsky 7 ani în urmă
părinte
comite
6b3946abec
1 a modificat fișierele cu 24 adăugiri și 13 ștergeri
  1. 24 13
      src/Avalonia.Controls/TextBox.cs

+ 24 - 13
src/Avalonia.Controls/TextBox.cs

@@ -325,7 +325,7 @@ namespace Avalonia.Controls
             string text = Text ?? string.Empty;
             int caretIndex = CaretIndex;
             bool movement = false;
-            bool handled = true;
+            bool handled = false;
             var modifiers = e.Modifiers;
 
             switch (e.Key)
@@ -334,13 +334,14 @@ namespace Avalonia.Controls
                     if (modifiers == InputModifiers.Control)
                     {
                         SelectAll();
+                        handled = true;
                     }
-
                     break;
                 case Key.C:
                     if (modifiers == InputModifiers.Control)
                     {
                         Copy();
+                        handled = true;
                     }
                     break;
 
@@ -349,6 +350,7 @@ namespace Avalonia.Controls
                     {
                         Copy();
                         DeleteSelection();
+                        handled = true;
                     }
                     break;
 
@@ -356,19 +358,24 @@ namespace Avalonia.Controls
                     if (modifiers == InputModifiers.Control)
                     {
                         Paste();
+                        handled = true;
                     }
 
                     break;
 
                 case Key.Z:
                     if (modifiers == InputModifiers.Control)
+                    {
                         _undoRedoHelper.Undo();
-
+                        handled = true;
+                    }
                     break;
                 case Key.Y:
                     if (modifiers == InputModifiers.Control)
+                    {
                         _undoRedoHelper.Redo();
-
+                        handled = true;
+                    }
                     break;
                 case Key.Left:
                     MoveHorizontal(-1, modifiers);
@@ -381,13 +388,11 @@ namespace Avalonia.Controls
                     break;
 
                 case Key.Up:
-                    MoveVertical(-1, modifiers);
-                    movement = true;
+                    movement = MoveVertical(-1, modifiers);
                     break;
 
                 case Key.Down:
-                    MoveVertical(1, modifiers);
-                    movement = true;
+                    movement = MoveVertical(1, modifiers);
                     break;
 
                 case Key.Home:
@@ -423,7 +428,7 @@ namespace Avalonia.Controls
                         CaretIndex -= removedCharacters;
                         SelectionStart = SelectionEnd = CaretIndex;
                     }
-
+                    handled = true;
                     break;
 
                 case Key.Delete:
@@ -447,13 +452,14 @@ namespace Avalonia.Controls
 
                         SetTextInternal(text.Substring(0, caretIndex) + text.Substring(caretIndex + removedCharacters));
                     }
-
+                    handled = true;
                     break;
 
                 case Key.Enter:
                     if (AcceptsReturn)
                     {
                         HandleTextInput("\r\n");
+                        handled = true;
                     }
 
                     break;
@@ -462,11 +468,11 @@ namespace Avalonia.Controls
                     if (AcceptsTab)
                     {
                         HandleTextInput("\t");
+                        handled = true;
                     }
                     else
                     {
                         base.OnKeyDown(e);
-                        handled = false;
                     }
 
                     break;
@@ -485,7 +491,7 @@ namespace Avalonia.Controls
                 SelectionStart = SelectionEnd = CaretIndex;
             }
 
-            if (handled)
+            if (handled || movement)
             {
                 e.Handled = true;
             }
@@ -662,7 +668,7 @@ namespace Avalonia.Controls
             }
         }
 
-        private void MoveVertical(int count, InputModifiers modifiers)
+        private bool MoveVertical(int count, InputModifiers modifiers)
         {
             var formattedText = _presenter.FormattedText;
             var lines = formattedText.GetLines().ToList();
@@ -677,6 +683,11 @@ namespace Avalonia.Controls
                 var point = new Point(rect.X, y + (count * (line.Height / 2)));
                 var hit = formattedText.HitTestPoint(point);
                 CaretIndex = hit.TextPosition + (hit.IsTrailing ? 1 : 0);
+                return true;
+            }
+            else
+            {
+                return false;
             }
         }