Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 3423bf1

Browse files
Merge pull request #364 from FrozenAssassine/fixfor#357
This fixes #357
2 parents 5f98a3e + 37fe5e2 commit 3423bf1

File tree

1 file changed

+53
-9
lines changed

1 file changed

+53
-9
lines changed

TextControlBox/TextControlBox.xaml.cs

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
using TextControlBox.Renderer;
2020
using TextControlBox.Text;
2121
using Windows.ApplicationModel.DataTransfer;
22+
using Windows.Devices.Input;
2223
using Windows.Foundation;
2324
using Windows.Storage;
2425
using Windows.System;
2526
using Windows.UI.Core;
27+
using Windows.UI.Input;
2628
using Windows.UI.Popups;
2729
using Windows.UI.Text.Core;
2830
using Windows.UI.ViewManagement;
@@ -110,6 +112,8 @@ public partial class TextControlBox : UserControl
110112
int PointerClickCount = 0;
111113
DispatcherTimer PointerClickTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 200) };
112114

115+
Point? OldTouchPosition = null;
116+
113117
//CursorPosition
114118
CursorPosition _CursorPosition = new CursorPosition(0, 0);
115119
CursorPosition OldCursorPosition = null;
@@ -892,11 +896,9 @@ private void CleanUp()
892896
Debug.WriteLine("Collect GC");
893897
ListHelper.GCList(TotalLines);
894898
}
895-
896-
#endregion
897-
898899
private void PointerReleasedAction(Point point)
899900
{
901+
OldTouchPosition = null;
900902
selectionrenderer.IsSelectingOverLinenumbers = false;
901903

902904
//End text drag/drop -> insert text at cursorposition
@@ -982,6 +984,36 @@ private void PointerMovedAction(Point point)
982984
UpdateSelection();
983985
}
984986
}
987+
private bool CheckTouchInput(PointerPoint point)
988+
{
989+
if (point.PointerDevice.PointerDeviceType == PointerDeviceType.Touch || point.PointerDevice.PointerDeviceType == PointerDeviceType.Pen)
990+
{
991+
//Get the touch start position:
992+
if (!OldTouchPosition.HasValue)
993+
return true;
994+
995+
//GEt the dragged offset:
996+
double scrollX = OldTouchPosition.Value.X - point.Position.X;
997+
double scrollY = OldTouchPosition.Value.Y - point.Position.Y;
998+
VerticalScrollbar.Value += scrollY > 2 ? 2 : scrollY < -2 ? -2 : scrollY;
999+
HorizontalScrollbar.Value += scrollX > 2 ? 2 : scrollX < -2 ? -2 : scrollX;
1000+
UpdateAll();
1001+
return true;
1002+
}
1003+
return false;
1004+
}
1005+
private bool CheckTouchInput_Click(PointerPoint point)
1006+
{
1007+
if (point.PointerDevice.PointerDeviceType == PointerDeviceType.Touch || point.PointerDevice.PointerDeviceType == PointerDeviceType.Pen)
1008+
{
1009+
OldTouchPosition = point.Position;
1010+
return true;
1011+
}
1012+
return false;
1013+
}
1014+
1015+
1016+
#endregion
9851017

9861018
#region Events
9871019
//Handle keyinputs
@@ -1255,18 +1287,19 @@ private void TextControlBox_KeyDown(object sender, KeyRoutedEventArgs e)
12551287
//Without coreWindow the selection outside of the window would not work
12561288
private void CoreWindow_PointerReleased(CoreWindow sender, PointerEventArgs args)
12571289
{
1258-
Debug.WriteLine("CoreWindow_PointerReleased");
12591290

12601291
var point = Utils.GetPointFromCoreWindowRelativeTo(args, Canvas_Text);
12611292
PointerReleasedAction(point);
12621293
}
12631294
private void Canvas_Selection_PointerReleased(object sender, PointerRoutedEventArgs e)
12641295
{
1265-
Debug.WriteLine("Canvas_Selection_PointerReleased");
12661296
PointerReleasedAction(e.GetCurrentPoint(sender as UIElement).Position);
12671297
}
12681298
private void CoreWindow_PointerMoved(CoreWindow sender, PointerEventArgs args)
12691299
{
1300+
if (CheckTouchInput(args.CurrentPoint))
1301+
return;
1302+
12701303
PointerMovedAction(Utils.GetPointFromCoreWindowRelativeTo(args, Canvas_Text));
12711304
}
12721305
private void Canvas_Selection_PointerMoved(object sender, PointerRoutedEventArgs e)
@@ -1275,6 +1308,9 @@ private void Canvas_Selection_PointerMoved(object sender, PointerRoutedEventArgs
12751308
return;
12761309

12771310
var point = e.GetCurrentPoint(Canvas_Selection);
1311+
1312+
if (CheckTouchInput(point))
1313+
return;
12781314

12791315
if (point.Properties.IsLeftButtonPressed)
12801316
{
@@ -1288,9 +1324,13 @@ private void Canvas_Selection_PointerPressed(object sender, PointerRoutedEventAr
12881324
{
12891325
selectionrenderer.IsSelectingOverLinenumbers = false;
12901326

1291-
Point PointerPosition = e.GetCurrentPoint(sender as UIElement).Position;
1292-
bool LeftButtonPressed = e.GetCurrentPoint(sender as UIElement).Properties.IsLeftButtonPressed;
1293-
bool RightButtonPressed = e.GetCurrentPoint(sender as UIElement).Properties.IsRightButtonPressed;
1327+
var point = e.GetCurrentPoint(sender as UIElement);
1328+
if (CheckTouchInput_Click(point))
1329+
return;
1330+
1331+
Point PointerPosition = point.Position;
1332+
bool LeftButtonPressed = point.Properties.IsLeftButtonPressed;
1333+
bool RightButtonPressed = point.Properties.IsRightButtonPressed;
12941334

12951335
if (LeftButtonPressed && !Utils.IsKeyPressed(VirtualKey.Shift))
12961336
PointerClickCount++;
@@ -1427,8 +1467,12 @@ private void Canvas_Selection_PointerWheelChanged(object sender, PointerRoutedEv
14271467
}
14281468
private void Canvas_LineNumber_PointerPressed(object sender, PointerRoutedEventArgs e)
14291469
{
1470+
var point = e.GetCurrentPoint(sender as UIElement);
1471+
if (CheckTouchInput_Click(point))
1472+
return;
1473+
14301474
//Select the line where the cursor is over
1431-
SelectLine(CursorRenderer.GetCursorLineFromPoint(e.GetCurrentPoint(sender as UIElement).Position, SingleLineHeight, NumberOfRenderedLines, NumberOfStartLine));
1475+
SelectLine(CursorRenderer.GetCursorLineFromPoint(point.Position, SingleLineHeight, NumberOfRenderedLines, NumberOfStartLine));
14321476

14331477
selectionrenderer.IsSelecting = true;
14341478
selectionrenderer.IsSelectingOverLinenumbers = true;

0 commit comments

Comments
 (0)