Skip to content

Commit d1f38c3

Browse files
committed
Merge right click paste #507
jglad (1): #507 add right click paste in search
2 parents 26b5868 + 318f96e commit d1f38c3

File tree

8 files changed

+38
-7
lines changed

8 files changed

+38
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dirs = "5.0.1"
1919
eframe = { version = "0.31.1", default-features = false, features = [ "wgpu", "wayland", "x11", "android-game-activity" ] }
2020
egui = { version = "0.31.1", features = ["serde"] }
2121
egui_extras = { version = "0.31.1", features = ["all_loaders"] }
22-
egui-winit = { version = "0.31.1", features = ["android-game-activity"] }
22+
egui-winit = { version = "0.31.1", features = ["android-game-activity", "clipboard"] }
2323
egui_nav = { git = "https://github.com/damus-io/egui-nav", rev = "5e816ac95e20f31dbb243a0d76179eab329a8ac0" }
2424
egui_tabs = { git = "https://github.com/damus-io/egui-tabs", rev = "881d86bdf8b424563bf0869eaab5ab9a69e012a4" }
2525
#egui_virtual_list = "0.6.0"

crates/notedeck/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sha2 = { workspace = true }
3030
bincode = { workspace = true }
3131
ehttp = {workspace = true }
3232
mime_guess = { workspace = true }
33+
egui-winit = { workspace = true }
3334

3435
[dev-dependencies]
3536
tempfile = { workspace = true }

crates/notedeck/src/app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
KeyStorageType, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
55
};
66
use egui::ThemePreference;
7+
use egui_winit::clipboard::Clipboard;
78
use enostr::RelayPool;
89
use nostrdb::{Config, Ndb, Transaction};
910
use std::cell::RefCell;
@@ -31,6 +32,7 @@ pub struct Notedeck {
3132
zoom: ZoomHandler,
3233
app_size: AppSizeHandler,
3334
unrecognized_args: BTreeSet<String>,
35+
clipboard: Clipboard,
3436
}
3537

3638
/// Our chrome, which is basically nothing
@@ -214,6 +216,7 @@ impl Notedeck {
214216
zoom,
215217
app_size,
216218
unrecognized_args,
219+
clipboard: Clipboard::new(None),
217220
}
218221
}
219222

@@ -233,6 +236,7 @@ impl Notedeck {
233236
path: &self.path,
234237
args: &self.args,
235238
theme: &mut self.theme,
239+
clipboard: &mut self.clipboard,
236240
}
237241
}
238242

crates/notedeck/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{Accounts, Args, DataPath, Images, NoteCache, ThemeHandler, UnknownIds};
2+
use egui_winit::clipboard::Clipboard;
23

34
use enostr::RelayPool;
45
use nostrdb::Ndb;
@@ -15,4 +16,5 @@ pub struct AppContext<'a> {
1516
pub path: &'a DataPath,
1617
pub args: &'a Args,
1718
pub theme: &'a mut ThemeHandler,
19+
pub clipboard: &'a mut Clipboard,
1820
}

crates/notedeck_columns/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ urlencoding = { workspace = true }
4848
uuid = { workspace = true }
4949
sha2 = { workspace = true }
5050
base64 = { workspace = true }
51+
egui-winit = { workspace = true }
5152

5253
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
5354
rfd = "0.15"

crates/notedeck_columns/src/nav.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn render_nav_body(
424424
search_buffer,
425425
&mut note_context,
426426
)
427-
.show(ui)
427+
.show(ui, ctx.clipboard)
428428
.map(RenderNavAction::NoteAction)
429429
}
430430

crates/notedeck_columns/src/ui/search/mod.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
actionbar::NoteAction,
66
ui::{note::NoteOptions, timeline::TimelineTabView},
77
};
8+
use egui_winit::clipboard::Clipboard;
89
use nostrdb::{Filter, Transaction};
910
use notedeck::{MuteFun, NoteRef};
1011
use std::time::{Duration, Instant};
@@ -39,14 +40,18 @@ impl<'a, 'd> SearchView<'a, 'd> {
3940
}
4041
}
4142

42-
pub fn show(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
43-
padding(8.0, ui, |ui| self.show_impl(ui)).inner
43+
pub fn show(&mut self, ui: &mut egui::Ui, clipboard: &mut Clipboard) -> Option<NoteAction> {
44+
padding(8.0, ui, |ui| self.show_impl(ui, clipboard)).inner
4445
}
4546

46-
pub fn show_impl(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
47+
pub fn show_impl(
48+
&mut self,
49+
ui: &mut egui::Ui,
50+
clipboard: &mut Clipboard,
51+
) -> Option<NoteAction> {
4752
ui.spacing_mut().item_spacing = egui::vec2(0.0, 12.0);
4853

49-
if search_box(self.query, ui) {
54+
if search_box(self.query, ui, clipboard) {
5055
self.execute_search(ui.ctx());
5156
}
5257

@@ -132,7 +137,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
132137
}
133138
}
134139

135-
fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui) -> bool {
140+
fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui, clipboard: &mut Clipboard) -> bool {
136141
ui.horizontal(|ui| {
137142
// Container for search input and icon
138143
let search_container = egui::Frame {
@@ -168,6 +173,22 @@ fn search_box(query: &mut SearchQueryState, ui: &mut egui::Ui) -> bool {
168173
.frame(false),
169174
);
170175

176+
response.context_menu(|ui| {
177+
if ui.button("paste").clicked() {
178+
if let Some(text) = clipboard.get() {
179+
query.string.clear();
180+
query.string.push_str(&text);
181+
}
182+
}
183+
});
184+
185+
if response.middle_clicked() {
186+
if let Some(text) = clipboard.get() {
187+
query.string.clear();
188+
query.string.push_str(&text);
189+
}
190+
}
191+
171192
if query.focus_state == FocusState::ShouldRequestFocus {
172193
response.request_focus();
173194
query.focus_state = FocusState::RequestedFocus;

0 commit comments

Comments
 (0)