Skip to content

Commit 7ebcb3e

Browse files
Jack251970TBM13
authored andcommitted
Merge pull request Flow-Launcher#3816 from Flow-Launcher/clipboard_invalid
Use try-catch for query text box paste
1 parent fb7611e commit 7ebcb3e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public partial class MainWindow : IDisposable
4444

4545
#region Private Fields
4646

47+
// Class Name
48+
private static readonly string ClassName = nameof(MainWindow);
49+
4750
// Dependency Injection
4851
private readonly Settings _settings;
4952
private readonly Theme _theme;
@@ -960,14 +963,21 @@ private void QueryTextBox_OnCopy(object sender, ExecutedRoutedEventArgs e)
960963

961964
private void QueryTextBox_OnPaste(object sender, DataObjectPastingEventArgs e)
962965
{
963-
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
964-
if (isText)
966+
try
967+
{
968+
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
969+
if (isText)
970+
{
971+
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
972+
text = text.Replace(Environment.NewLine, " ");
973+
DataObject data = new DataObject();
974+
data.SetData(DataFormats.UnicodeText, text);
975+
e.DataObject = data;
976+
}
977+
}
978+
catch (Exception ex)
965979
{
966-
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
967-
text = text.Replace(Environment.NewLine, " ");
968-
DataObject data = new DataObject();
969-
data.SetData(DataFormats.UnicodeText, text);
970-
e.DataObject = data;
980+
App.API.LogException(ClassName, "Failed to paste text", ex);
971981
}
972982
}
973983

0 commit comments

Comments
 (0)