Skip to content

Commit 77990f7

Browse files
authored
Merge pull request #2528 from Flow-Launcher/fix-improve-query-paste
Prepend clipboard to query
2 parents d84dbc8 + 4a6a66a commit 77990f7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@
221221
Visibility="Visible">
222222
<TextBox.CommandBindings>
223223
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
224-
<CommandBinding Command="ApplicationCommands.Paste" Executed="OnPaste" />
225224
</TextBox.CommandBindings>
226225
<TextBox.ContextMenu>
227226
<ContextMenu MinWidth="160">

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Key = System.Windows.Input.Key;
2626
using System.Media;
2727
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
28+
using DataObject = System.Windows.DataObject;
2829

2930
namespace Flow.Launcher
3031
{
@@ -50,7 +51,8 @@ public MainWindow(Settings settings, MainViewModel mainVM)
5051
_settings = settings;
5152

5253
InitializeComponent();
53-
InitializePosition();
54+
InitializePosition();
55+
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
5456
}
5557

5658
public MainWindow()
@@ -72,12 +74,16 @@ private void OnCopy(object sender, ExecutedRoutedEventArgs e)
7274
}
7375
}
7476

75-
private void OnPaste(object sender, ExecutedRoutedEventArgs e)
77+
private void OnPaste(object sender, DataObjectPastingEventArgs e)
7678
{
77-
if (System.Windows.Clipboard.ContainsText())
79+
var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.UnicodeText, true);
80+
if (isText)
7881
{
79-
_viewModel.ChangeQueryText(System.Windows.Clipboard.GetText().Replace("\n", String.Empty).Replace("\r", String.Empty));
80-
e.Handled = true;
82+
var text = e.SourceDataObject.GetData(System.Windows.DataFormats.UnicodeText) as string;
83+
text = text.Replace(Environment.NewLine, " ");
84+
DataObject data = new DataObject();
85+
data.SetData(System.Windows.DataFormats.UnicodeText, text);
86+
e.DataObject = data;
8187
}
8288
}
8389

0 commit comments

Comments
 (0)