Skip to content

Commit

Permalink
Merge pull request #2528 from Flow-Launcher/fix-improve-query-paste
Browse files Browse the repository at this point in the history
Prepend clipboard to query
  • Loading branch information
jjw24 authored Feb 5, 2024
2 parents d84dbc8 + 4a6a66a commit 77990f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@
Visibility="Visible">
<TextBox.CommandBindings>
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
<CommandBinding Command="ApplicationCommands.Paste" Executed="OnPaste" />
</TextBox.CommandBindings>
<TextBox.ContextMenu>
<ContextMenu MinWidth="160">
Expand Down
16 changes: 11 additions & 5 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Key = System.Windows.Input.Key;
using System.Media;
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
using DataObject = System.Windows.DataObject;

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

InitializeComponent();
InitializePosition();
InitializePosition();
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
}

public MainWindow()
Expand All @@ -72,12 +74,16 @@ private void OnCopy(object sender, ExecutedRoutedEventArgs e)
}
}

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)
{
_viewModel.ChangeQueryText(System.Windows.Clipboard.GetText().Replace("\n", String.Empty).Replace("\r", String.Empty));
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;
}
}

Expand Down

0 comments on commit 77990f7

Please sign in to comment.