Skip to content

Commit d34615a

Browse files
committed
Optimize link status by not resizing label, refactor handle_motion
1 parent 5258ef2 commit d34615a

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

data/resources/ui/window.blp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ template GeopardWindow: Adw.ApplicationWindow {
8787
styles ["background"]
8888
Gtk.Label url_status {
8989
xalign: 0.0;
90-
halign: start;
9190
wrap: true;
92-
wrap-mode: word_char;
9391
margin-top: 6;
9492
margin-bottom: 6;
9593
margin-start: 6;

src/widgets/tab.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use gtk::CompositeTemplate;
1515
use gtk::TemplateChild;
1616
use log::{debug, error, info};
1717
use once_cell::sync::Lazy;
18-
use std::cell::RefCell;
18+
use std::cell::{Cell, RefCell};
1919
use std::collections::HashMap;
2020
use std::marker::PhantomData;
2121
use std::pin::Pin;
@@ -42,6 +42,7 @@ pub struct HistoryStatus {
4242
pub(crate) current: usize,
4343
pub(crate) available: usize,
4444
}
45+
4546
pub mod imp {
4647

4748
pub use super::*;
@@ -223,30 +224,32 @@ impl Tab {
223224
Ok(())
224225
}
225226
fn handle_motion(&self, x: f64, y: f64) -> Result<()> {
227+
// May need some debounce?
228+
226229
let imp = self.imp();
227230
let gemini_text_ext = imp.gemini_text_ext.borrow();
228231
let gemini_text_ext = gemini_text_ext.as_ref().unwrap();
229232
let links = imp.links.borrow();
230233
let entry = Self::extract_linkhandler(&*links, gemini_text_ext, x, y);
231234

232235
let link_ref = entry.as_ref().map(|x| x.1).unwrap_or("");
236+
if link_ref == &*imp.hover_url.borrow() {
237+
return Ok(());
238+
}
233239

234-
// May need optimization. Comparing two strings for each motion event is expensive
235-
if *imp.hover_url.borrow() != link_ref {
236-
match link_ref {
237-
"" => {
238-
gemini_text_ext.text_view.set_cursor_from_name(Some("text"));
239-
}
240-
_ => {
241-
gemini_text_ext
242-
.text_view
243-
.set_cursor_from_name(Some("pointer"));
244-
}
240+
match link_ref {
241+
"" => {
242+
gemini_text_ext.text_view.set_cursor_from_name(Some("text"));
245243
}
246-
imp.hover_url.replace(link_ref.to_owned());
247-
self.notify("hover-url");
248-
}
244+
_ => {
245+
gemini_text_ext
246+
.text_view
247+
.set_cursor_from_name(Some("pointer"));
248+
}
249+
};
249250

251+
imp.hover_url.replace(link_ref.to_owned());
252+
self.notify("hover-url");
250253
Ok(())
251254
}
252255
pub fn spawn_open_url(&self, url: Url) {

0 commit comments

Comments
 (0)