#507 add right click paste in search

Signed-off-by: Jakub Gladysz <jakub.gladysz@protonmail.com>
This commit is contained in:
jglad
2025-03-21 16:35:24 +01:00
committed by Jakub Gladysz
parent a7f34a9dc7
commit 318f96e37e
8 changed files with 38 additions and 7 deletions

View File

@@ -29,6 +29,7 @@ sha2 = { workspace = true }
bincode = { workspace = true }
ehttp = {workspace = true }
mime_guess = { workspace = true }
egui-winit = { workspace = true }
[dev-dependencies]
tempfile = { workspace = true }

View File

@@ -4,6 +4,7 @@ use crate::{
KeyStorageType, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
};
use egui::ThemePreference;
use egui_winit::clipboard::Clipboard;
use enostr::RelayPool;
use nostrdb::{Config, Ndb, Transaction};
use std::cell::RefCell;
@@ -31,6 +32,7 @@ pub struct Notedeck {
zoom: ZoomHandler,
app_size: AppSizeHandler,
unrecognized_args: BTreeSet<String>,
clipboard: Clipboard,
}
/// Our chrome, which is basically nothing
@@ -214,6 +216,7 @@ impl Notedeck {
zoom,
app_size,
unrecognized_args,
clipboard: Clipboard::new(None),
}
}
@@ -233,6 +236,7 @@ impl Notedeck {
path: &self.path,
args: &self.args,
theme: &mut self.theme,
clipboard: &mut self.clipboard,
}
}

View File

@@ -1,4 +1,5 @@
use crate::{Accounts, Args, DataPath, Images, NoteCache, ThemeHandler, UnknownIds};
use egui_winit::clipboard::Clipboard;
use enostr::RelayPool;
use nostrdb::Ndb;
@@ -15,4 +16,5 @@ pub struct AppContext<'a> {
pub path: &'a DataPath,
pub args: &'a Args,
pub theme: &'a mut ThemeHandler,
pub clipboard: &'a mut Clipboard,
}

View File

@@ -48,6 +48,7 @@ urlencoding = { workspace = true }
uuid = { workspace = true }
sha2 = { workspace = true }
base64 = { workspace = true }
egui-winit = { workspace = true }
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
rfd = "0.15"

View File

@@ -424,7 +424,7 @@ fn render_nav_body(
search_buffer,
&mut note_context,
)
.show(ui)
.show(ui, ctx.clipboard)
.map(RenderNavAction::NoteAction)
}

View File

@@ -5,6 +5,7 @@ use crate::{
actionbar::NoteAction,
ui::{note::NoteOptions, timeline::TimelineTabView},
};
use egui_winit::clipboard::Clipboard;
use nostrdb::{Filter, Transaction};
use notedeck::{MuteFun, NoteRef};
use std::time::{Duration, Instant};
@@ -39,14 +40,18 @@ impl<'a, 'd> SearchView<'a, 'd> {
}
}
pub fn show(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
padding(8.0, ui, |ui| self.show_impl(ui)).inner
pub fn show(&mut self, ui: &mut egui::Ui, clipboard: &mut Clipboard) -> Option<NoteAction> {
padding(8.0, ui, |ui| self.show_impl(ui, clipboard)).inner
}
pub fn show_impl(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
pub fn show_impl(
&mut self,
ui: &mut egui::Ui,
clipboard: &mut Clipboard,
) -> Option<NoteAction> {
ui.spacing_mut().item_spacing = egui::vec2(0.0, 12.0);
if search_box(self.query, ui) {
if search_box(self.query, ui, clipboard) {
self.execute_search(ui.ctx());
}
@@ -132,7 +137,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
}
}
fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui) -> bool {
fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui, clipboard: &mut Clipboard) -> bool {
ui.horizontal(|ui| {
// Container for search input and icon
let search_container = egui::Frame {
@@ -168,6 +173,22 @@ fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui) -> bool {
.frame(false),
);
response.context_menu(|ui| {
if ui.button("paste").clicked() {
if let Some(text) = clipboard.get() {
query.string.clear();
query.string.push_str(&text);
}
}
});
if response.middle_clicked() {
if let Some(text) = clipboard.get() {
query.string.clear();
query.string.push_str(&text);
}
}
if query.focus_state == FocusState::ShouldRequestFocus {
response.request_focus();
query.focus_state = FocusState::RequestedFocus;