mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[ITT] fix crashes on shift selection and clipboard access (#20166)
* [ITT] fix crashes on shift selection and clipboard access * exception logging
This commit is contained in:
@@ -58,7 +58,7 @@ public partial class App : Application, IDisposable
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
Logger.LogError($"PowerOCR got an exception on start: {ex}");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -42,6 +42,8 @@ public partial class OCROverlay : Window
|
||||
private double xShiftDelta;
|
||||
private double yShiftDelta;
|
||||
|
||||
private const double ActiveOpacity = 0.4;
|
||||
|
||||
public OCROverlay()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -55,7 +57,7 @@ public partial class OCROverlay : Window
|
||||
KeyUp += MainWindow_KeyUp;
|
||||
|
||||
BackgroundImage.Source = ImageMethods.GetWindowBoundsImage(this);
|
||||
BackgroundBrush.Opacity = 0.4;
|
||||
BackgroundBrush.Opacity = ActiveOpacity;
|
||||
}
|
||||
|
||||
private void Window_Unloaded(object sender, RoutedEventArgs e)
|
||||
@@ -84,9 +86,6 @@ public partial class OCROverlay : Window
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.LeftShift:
|
||||
isShiftDown = false;
|
||||
clickedPoint = new Point(clickedPoint.X + xShiftDelta, clickedPoint.Y + yShiftDelta);
|
||||
break;
|
||||
case Key.RightShift:
|
||||
isShiftDown = false;
|
||||
clickedPoint = new Point(clickedPoint.X + xShiftDelta, clickedPoint.Y + yShiftDelta);
|
||||
@@ -110,7 +109,7 @@ public partial class OCROverlay : Window
|
||||
|
||||
private void RegionClickCanvas_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.RightButton == MouseButtonState.Pressed)
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -147,6 +146,7 @@ public partial class OCROverlay : Window
|
||||
if (scr.Bounds.Contains(formsPoint))
|
||||
{
|
||||
CurrentScreen = scr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public partial class OCROverlay : Window
|
||||
|
||||
clippingGeometry.Rect = new Rect(
|
||||
new Point(leftValue, topValue),
|
||||
new Size(selectBorder.Width - 2, selectBorder.Height - 2));
|
||||
new Size(selectBorder.Width, selectBorder.Height));
|
||||
Canvas.SetLeft(selectBorder, leftValue - 1);
|
||||
Canvas.SetTop(selectBorder, topValue - 1);
|
||||
return;
|
||||
@@ -235,11 +235,6 @@ public partial class OCROverlay : Window
|
||||
movingPoint.X = Math.Round(movingPoint.X);
|
||||
movingPoint.Y = Math.Round(movingPoint.Y);
|
||||
|
||||
if (mPt == movingPoint)
|
||||
{
|
||||
Debug.WriteLine("Probably on Screen 1");
|
||||
}
|
||||
|
||||
double xDimScaled = Canvas.GetLeft(selectBorder) * m.M11;
|
||||
double yDimScaled = Canvas.GetTop(selectBorder) * m.M22;
|
||||
|
||||
@@ -262,7 +257,6 @@ public partial class OCROverlay : Window
|
||||
|
||||
if (regionScaled.Width < 3 || regionScaled.Height < 3)
|
||||
{
|
||||
BackgroundBrush.Opacity = 0;
|
||||
grabbedText = await ImageMethods.GetClickedWord(this, new Point(xDimScaled, yDimScaled));
|
||||
}
|
||||
else
|
||||
@@ -272,7 +266,15 @@ public partial class OCROverlay : Window
|
||||
|
||||
if (string.IsNullOrWhiteSpace(grabbedText) == false)
|
||||
{
|
||||
Clipboard.SetText(grabbedText);
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(grabbedText);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Clipboard.SetText exception: {ex}");
|
||||
}
|
||||
|
||||
WindowUtilities.CloseAllOCROverlays();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user