OSDN Git Service

フォーカスが失われた直後にフォーカスを獲得すると落ちることがあった
[fooeditengine/FooEditEngine.git] / UWP / FooEditEngine.UWP / FooTextBox.cs
index 26ebcef..90f9659 100644 (file)
@@ -468,7 +468,6 @@ namespace FooEditEngine.UWP
 
         private void RemoveTextContext()
         {
-            this.textEditContext.NotifyFocusLeave();
             this.textEditContext.CompositionStarted -= TextEditContext_CompositionStarted;
             this.textEditContext.CompositionCompleted -= TextEditContext_CompositionCompleted;
             this.textEditContext.LayoutRequested -= TextEditContext_LayoutRequested;
@@ -479,6 +478,7 @@ namespace FooEditEngine.UWP
             this.textEditContext.FormatUpdating -= TextEditContext_FormatUpdating;
             this.textEditContext.FocusRemoved -= TextEditContext_FocusRemoved;
             this.textEditContext.NotifyFocusLeaveCompleted -= TextEditContext_NotifyFocusLeaveCompleted;
+            this.textEditContext.NotifyFocusLeave();
         }
 
         /// <inheritdoc/>
@@ -723,6 +723,8 @@ namespace FooEditEngine.UWP
 
             int start = req.Range.StartCaretPosition;
             int length = req.Range.EndCaretPosition - req.Range.StartCaretPosition;
+            if (length > this.Document.Length)
+                length = this.Document.Length;
 
             System.Diagnostics.Debug.WriteLine("req text start:{0} length:{1}", start, length);
 
@@ -1165,7 +1167,7 @@ namespace FooEditEngine.UWP
 
         void FooTextBox_Loaded(object sender, RoutedEventArgs e)
         {
-            //this.Focus(FocusState.Programmatic);
+            this.Focus(FocusState.Programmatic);
         }
 
         void timer_Tick(object sender, object e)