OSDN Git Service

スクロールをピクセル単位で行うようにした
authortest <test@yahoo.co.jp>
Thu, 7 Jan 2021 15:34:39 +0000 (00:34 +0900)
committertest <test@yahoo.co.jp>
Thu, 7 Jan 2021 15:34:39 +0000 (00:34 +0900)
Core/Controller.cs
UWP/FooEditEngine.UWP/FooTextBox.cs
WPF/FooEditEngine/FooTextBox.cs
Windows/FooEditEngine/FooTextBox.cs

index d468870..4e5949b 100644 (file)
@@ -422,7 +422,6 @@ namespace FooEditEngine
             this.SelectWithMoveCaret(isSelected);
         }
 
-        double noti;
         /// <summary>
         /// スクロールする
         /// </summary>
@@ -430,7 +429,7 @@ namespace FooEditEngine
         /// <param name="delta">ピクセル単位の値でスクロール量を指定する</param>
         /// <param name="isSelected">選択状態にするなら真</param>
         /// <param name="withCaret">同時にキャレットを移動させるなら真</param>
-        public void ScrollByPixel(ScrollDirection dir,int delta, bool isSelected, bool withCaret)
+        public void ScrollByPixel(ScrollDirection dir,double delta, bool isSelected, bool withCaret)
         {
             if (this.Document.FireUpdateEvent == false)
                 throw new InvalidOperationException("");
@@ -441,23 +440,20 @@ namespace FooEditEngine
                 return;
             }
 
-            if(dir == ScrollDirection.Up || dir == ScrollDirection.Down)
+            if(dir == ScrollDirection.Up)
+            {
+                this.View.TryScroll(0, -delta);
+            }
+            else if (dir == ScrollDirection.Down)
             {
-                noti += delta;
-
-                if (noti < this.View.render.emSize.Height)
-                    return;
-
-                int delta_row = (int)(noti / this.View.render.emSize.Height + 1.0);
-
-                noti = 0;
-
                 this.View.TryScroll(0, delta);
             }
 
             if (withCaret)
             {
                 //カーソルを適切な位置に移動させる必要がある
+                TextPoint tp = this.View.GetTextPointFromPostion(this.View.CaretLocation);
+                this.View.JumpCaret(tp.row, tp.col);
                 this.View.AdjustCaretAndSrc();
                 this.SelectWithMoveCaret(isSelected);
             }
index 5ce14e5..6bc1735 100644 (file)
@@ -549,6 +549,7 @@ namespace FooEditEngine.UWP
             if (autocomplete != null && autocomplete.ProcessKeyDown(this, e, isControlPressed, isShiftPressed))
                 return;
 
+            double alignedPage = (int)(this.Render.TextArea.Height / this.Render.emSize.Height) * this.Render.emSize.Height;
             switch (e.Key)
             {
                 case VirtualKey.Up:
@@ -576,12 +577,12 @@ namespace FooEditEngine.UWP
                     isMovedCaret = true;
                     break;
                 case VirtualKey.PageUp:
-                    this._Controller.Scroll(ScrollDirection.Up, this._View.LineCountOnScreen, isShiftPressed, true);
+                    this._Controller.ScrollByPixel(ScrollDirection.Up, alignedPage, isShiftPressed, true);
                     this.Refresh();
                     isMovedCaret = true;
                     break;
                 case VirtualKey.PageDown:
-                    this._Controller.Scroll(ScrollDirection.Down, this._View.LineCountOnScreen, isShiftPressed, true);
+                    this._Controller.ScrollByPixel(ScrollDirection.Down, alignedPage, isShiftPressed, true);
                     this.Refresh();
                     isMovedCaret = true;
                     break;
index feec422..2d5fb7f 100644 (file)
@@ -724,6 +724,7 @@ namespace FooEditEngine.WPF
             }
 
             bool movedCaret = false;
+            double alignedPage = (int)(this.Render.TextArea.Height / this.Render.emSize.Height) * this.Render.emSize.Height;
             switch (e.Key)
             {
                 case Key.Up:
@@ -751,12 +752,12 @@ namespace FooEditEngine.WPF
                     movedCaret = true;
                     break;
                 case Key.PageUp:
-                    this._Controller.Scroll(ScrollDirection.Up,this._View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
+                    this._Controller.ScrollByPixel(ScrollDirection.Up, alignedPage, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), true);
                     this.Refresh();
                     movedCaret = true;
                     break;
                 case Key.PageDown:
-                    this._Controller.Scroll(ScrollDirection.Down,this._View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
+                    this._Controller.ScrollByPixel(ScrollDirection.Down, alignedPage, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), true);
                     this.Refresh();
                     movedCaret = true;
                     break;
index 8f360e7..76d85cd 100644 (file)
@@ -1290,6 +1290,7 @@ namespace FooEditEngine.Windows
             if (e.Handled)
                 return;
 
+            double alignedPage = (int)(this.render.TextArea.Height / this.render.emSize.Height) * this.render.emSize.Height;
             switch (e.KeyCode)
             {
                 case Keys.Up:
@@ -1309,11 +1310,11 @@ namespace FooEditEngine.Windows
                     this.Refresh();
                     break;
                 case Keys.PageUp:
-                    this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
+                    this.Controller.ScrollByPixel(ScrollDirection.Up, alignedPage,e.Shift,true);
                     this.Refresh();
                     break;
                 case Keys.PageDown:
-                    this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
+                    this.Controller.ScrollByPixel(ScrollDirection.Down, alignedPage, e.Shift, true);
                     this.Refresh();
                     break;
                 case Keys.Insert: