From 0d9fc801c979065bd1b7e0404d67893e8d3d81fa Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 13 Oct 2024 07:56:48 +0300 Subject: [PATCH] toggle cursor icon if tag contain URI --- .../item/page/content/text/gemini/reader.rs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs index fd46aeb1..2fa523cc 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs @@ -9,8 +9,7 @@ use gtk::{ gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}, gio::SimpleAction, glib::{GString, TimeZone, Uri}, - pango::Underline, - prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextTagExt, TextViewExt, ToVariant}, + prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt}, EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType, WrapMode, }; @@ -139,12 +138,15 @@ impl Reader { let gobject = widget.gobject().clone(); let _links_ = links.clone(); // is copy move |_, _, x, y| { + // Detect tag match current coords hovered let (window_x, window_y) = gobject.window_to_buffer_coords(TextWindowType::Widget, x as i32, y as i32); if let Some(iter) = gobject.iter_at_location(window_x, window_y) { for tag in iter.tags() { + // Detect links on tag contain URI if let Some(uri) = _links_.get(&tag) { + // Select handler by scheme match uri.scheme().as_str() { "gemini" => { // Open new page @@ -162,27 +164,21 @@ impl Reader { let gobject = widget.gobject().clone(); let _links_ = links.clone(); // is copy move |_, x, y| { - // Remove underline decoration from all tags - gobject.buffer().tag_table().foreach(|tag| { - tag.set_underline(Underline::None); - }); - // Detect tag match current coords hovered let (window_x, window_y) = gobject.window_to_buffer_coords(TextWindowType::Widget, x as i32, y as i32); if let Some(iter) = gobject.iter_at_location(window_x, window_y) { for tag in iter.tags() { - // Show underline if tag contain URI (is link) - if let Some(_) = _links_.get(&tag) { - tag.set_underline(Underline::Single); - - // @TODO Show tooltip + // Toggle cursor icon if tag contain URI (is link) + match _links_.get(&tag) { + Some(_) => gobject.set_cursor_from_name(Some("pointer")), // @TODO Show tooltip + None => gobject.set_cursor_from_name(Some("text")), } } } - } // @TODO expensive for CPU - }); + } + }); // @TODO may be expensive for CPU // @TODO // middle_button_controller(|_, _, _, _| {});