#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

2
Cargo.lock generated
View File

@@ -2729,6 +2729,7 @@ dependencies = [
"dirs", "dirs",
"eframe", "eframe",
"egui", "egui",
"egui-winit",
"ehttp", "ehttp",
"enostr", "enostr",
"hex", "hex",
@@ -2785,6 +2786,7 @@ dependencies = [
"dirs", "dirs",
"eframe", "eframe",
"egui", "egui",
"egui-winit",
"egui_extras", "egui_extras",
"egui_nav", "egui_nav",
"egui_tabs", "egui_tabs",

View File

@@ -19,7 +19,7 @@ dirs = "5.0.1"
eframe = { version = "0.31.1", default-features = false, features = [ "wgpu", "wayland", "x11", "android-game-activity" ] } eframe = { version = "0.31.1", default-features = false, features = [ "wgpu", "wayland", "x11", "android-game-activity" ] }
egui = { version = "0.31.1", features = ["serde"] } egui = { version = "0.31.1", features = ["serde"] }
egui_extras = { version = "0.31.1", features = ["all_loaders"] } egui_extras = { version = "0.31.1", features = ["all_loaders"] }
egui-winit = { version = "0.31.1", features = ["android-game-activity"] } egui-winit = { version = "0.31.1", features = ["android-game-activity", "clipboard"] }
egui_nav = { git = "https://github.com/damus-io/egui-nav", rev = "5e816ac95e20f31dbb243a0d76179eab329a8ac0" } egui_nav = { git = "https://github.com/damus-io/egui-nav", rev = "5e816ac95e20f31dbb243a0d76179eab329a8ac0" }
egui_tabs = { git = "https://github.com/damus-io/egui-tabs", rev = "881d86bdf8b424563bf0869eaab5ab9a69e012a4" } egui_tabs = { git = "https://github.com/damus-io/egui-tabs", rev = "881d86bdf8b424563bf0869eaab5ab9a69e012a4" }
#egui_virtual_list = "0.6.0" #egui_virtual_list = "0.6.0"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,6 +5,7 @@ use crate::{
actionbar::NoteAction, actionbar::NoteAction,
ui::{note::NoteOptions, timeline::TimelineTabView}, ui::{note::NoteOptions, timeline::TimelineTabView},
}; };
use egui_winit::clipboard::Clipboard;
use nostrdb::{Filter, Transaction}; use nostrdb::{Filter, Transaction};
use notedeck::{MuteFun, NoteRef}; use notedeck::{MuteFun, NoteRef};
use std::time::{Duration, Instant}; 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> { pub fn show(&mut self, ui: &mut egui::Ui, clipboard: &mut Clipboard) -> Option<NoteAction> {
padding(8.0, ui, |ui| self.show_impl(ui)).inner 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); 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()); 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| { ui.horizontal(|ui| {
// Container for search input and icon // Container for search input and icon
let search_container = egui::Frame { let search_container = egui::Frame {
@@ -168,6 +173,22 @@ fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui) -> bool {
.frame(false), .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 { if query.focus_state == FocusState::ShouldRequestFocus {
response.request_focus(); response.request_focus();
query.focus_state = FocusState::RequestedFocus; query.focus_state = FocusState::RequestedFocus;