From 7ada82afd13edc846a65d7dff0cb9fa7917df4c3 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 4 Feb 2024 10:23:37 -0500 Subject: [PATCH 1/3] Prepend clipboard to query --- Flow.Launcher/MainWindow.xaml.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 7d1a68125..e61b32a94 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -76,7 +76,8 @@ namespace Flow.Launcher { if (System.Windows.Clipboard.ContainsText()) { - _viewModel.ChangeQueryText(System.Windows.Clipboard.GetText().Replace("\n", String.Empty).Replace("\r", String.Empty)); + var clipboardText = System.Windows.Clipboard.GetText().Replace("\r\n", " "); + QueryTextBox.SelectedText = clipboardText; e.Handled = true; } } From e9dba45f82e795691bc24e1b6b1f0a943a3b2625 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 4 Feb 2024 14:33:00 -0500 Subject: [PATCH 2/3] Use caret position for inserted text --- Flow.Launcher/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index e61b32a94..36d852a26 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -77,7 +77,7 @@ namespace Flow.Launcher if (System.Windows.Clipboard.ContainsText()) { var clipboardText = System.Windows.Clipboard.GetText().Replace("\r\n", " "); - QueryTextBox.SelectedText = clipboardText; + _viewModel.ChangeQueryText(QueryTextBox.Text.Insert(QueryTextBox.CaretIndex, clipboardText)); e.Handled = true; } } From b77c9aad13719924c4772c3895c35add01ccdd9c Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 4 Feb 2024 16:02:53 -0500 Subject: [PATCH 3/3] Use DataObject handler method --- Flow.Launcher/MainWindow.xaml | 1 - Flow.Launcher/MainWindow.xaml.cs | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index b65fbc7bb..88e95aa69 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -221,7 +221,6 @@ Visibility="Visible"> - diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 36d852a26..e90582b31 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -25,6 +25,7 @@ using ModernWpf.Controls; using Key = System.Windows.Input.Key; using System.Media; using static Flow.Launcher.ViewModel.SettingWindowViewModel; +using DataObject = System.Windows.DataObject; namespace Flow.Launcher { @@ -50,7 +51,8 @@ namespace Flow.Launcher _settings = settings; InitializeComponent(); - InitializePosition(); + InitializePosition(); + DataObject.AddPastingHandler(QueryTextBox, OnPaste); } public MainWindow() @@ -72,13 +74,16 @@ namespace Flow.Launcher } } - private void OnPaste(object sender, ExecutedRoutedEventArgs e) + private void OnPaste(object sender, DataObjectPastingEventArgs e) { - if (System.Windows.Clipboard.ContainsText()) + var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.UnicodeText, true); + if (isText) { - var clipboardText = System.Windows.Clipboard.GetText().Replace("\r\n", " "); - _viewModel.ChangeQueryText(QueryTextBox.Text.Insert(QueryTextBox.CaretIndex, clipboardText)); - e.Handled = true; + var text = e.SourceDataObject.GetData(System.Windows.DataFormats.UnicodeText) as string; + text = text.Replace(Environment.NewLine, " "); + DataObject data = new DataObject(); + data.SetData(System.Windows.DataFormats.UnicodeText, text); + e.DataObject = data; } }