update navigation entry on fragment change

This commit is contained in:
yggverse 2026-03-11 15:50:57 +02:00
parent 6a491751b6
commit 905eee0aab
5 changed files with 20 additions and 21 deletions

View file

@ -8,7 +8,7 @@ pub enum Text {
} }
impl Text { impl Text {
pub fn handle(&self, page: &super::Page) { pub fn handle(&self, page: &std::rc::Rc<super::Page>) {
page.navigation page.navigation
.request .request
.info .info
@ -29,7 +29,7 @@ impl Text {
.info .info
.borrow_mut() .borrow_mut()
.set_mime(Some("text/markdown".to_string())); .set_mime(Some("text/markdown".to_string()));
page.content.to_text_markdown(&page.profile, uri, data) page.content.to_text_markdown(page, uri, data)
}), }),
Self::Plain(uri, data) => (uri, page.content.to_text_plain(data)), Self::Plain(uri, data) => (uri, page.content.to_text_plain(data)),
Self::Source(uri, data) => (uri, page.content.to_text_source(data)), Self::Source(uri, data) => (uri, page.content.to_text_source(data)),

View file

@ -358,7 +358,7 @@ fn handle(
} else { } else {
match m.as_str() { match m.as_str() {
"text/gemini" => page.content.to_text_gemini(&page.profile, &uri, data), "text/gemini" => page.content.to_text_gemini(&page.profile, &uri, data),
"text/markdown" => page.content.to_text_markdown(&page.profile, &uri, data), "text/markdown" => page.content.to_text_markdown(&page, &uri, data),
"text/plain" => page.content.to_text_plain(data), "text/plain" => page.content.to_text_plain(data),
_ => panic!() // unexpected _ => panic!() // unexpected
} }

View file

@ -7,7 +7,7 @@ use directory::Directory;
use image::Image; use image::Image;
use text::Text; use text::Text;
use crate::profile::Profile; use crate::{app::browser::window::tab::item::page::Page, profile::Profile};
use super::{ItemAction, TabAction, WindowAction}; use super::{ItemAction, TabAction, WindowAction};
use adw::StatusPage; use adw::StatusPage;
@ -162,14 +162,9 @@ impl Content {
} }
/// `text/markdown` /// `text/markdown`
pub fn to_text_markdown(&self, profile: &Rc<Profile>, base: &Uri, data: &str) -> Text { pub fn to_text_markdown(&self, page: &Rc<Page>, base: &Uri, data: &str) -> Text {
self.clean(); self.clean();
let m = Text::markdown( let m = Text::markdown((&self.window_action, &self.item_action), page, base, data);
(&self.window_action, &self.item_action),
profile,
base,
data,
);
self.g_box.append(&m.scrolled_window); self.g_box.append(&m.scrolled_window);
m m
} }

View file

@ -4,7 +4,7 @@ mod nex;
mod plain; mod plain;
mod source; mod source;
use crate::profile::Profile; use crate::{app::browser::window::tab::item::page::Page, profile::Profile};
use super::{ItemAction, WindowAction}; use super::{ItemAction, WindowAction};
use adw::ClampScrollable; use adw::ClampScrollable;
@ -58,11 +58,11 @@ impl Text {
pub fn markdown( pub fn markdown(
actions: (&Rc<WindowAction>, &Rc<ItemAction>), actions: (&Rc<WindowAction>, &Rc<ItemAction>),
profile: &Rc<Profile>, page: &Rc<Page>,
base: &Uri, base: &Uri,
gemtext: &str, gemtext: &str,
) -> Self { ) -> Self {
let markdown = Markdown::build(actions, profile, base, gemtext); let markdown = Markdown::build(actions, page, base, gemtext);
Self { Self {
scrolled_window: reader(&markdown.text_view), scrolled_window: reader(&markdown.text_view),
text_view: markdown.text_view, text_view: markdown.text_view,

View file

@ -2,14 +2,14 @@ mod gutter;
mod tags; mod tags;
use super::{ItemAction, WindowAction}; use super::{ItemAction, WindowAction};
use crate::{app::browser::window::action::Position, profile::Profile}; use crate::app::browser::window::{action::Position, tab::item::page::Page};
use gtk::{ use gtk::{
EventControllerMotion, GestureClick, PopoverMenu, TextBuffer, TextTag, TextTagTable, TextView, EventControllerMotion, GestureClick, PopoverMenu, TextBuffer, TextTag, TextTagTable, TextView,
TextWindowType, UriLauncher, Window, WrapMode, TextWindowType, UriLauncher, Window, WrapMode,
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY, BUTTON_SECONDARY, Display, RGBA}, gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY, BUTTON_SECONDARY, Display, RGBA},
gio::{Cancellable, Menu, SimpleAction, SimpleActionGroup}, gio::{Cancellable, Menu, SimpleAction, SimpleActionGroup},
glib::{ControlFlow, GString, Uri, idle_add_local, uuid_string_random}, glib::{ControlFlow, GString, Uri, idle_add_local, uuid_string_random},
prelude::{PopoverExt, TextBufferExt, TextTagExt, TextViewExt, WidgetExt}, prelude::{EditableExt, PopoverExt, TextBufferExt, TextTagExt, TextViewExt, WidgetExt},
}; };
use gutter::Gutter; use gutter::Gutter;
use sourceview::prelude::{ActionExt, ActionMapExt, DisplayExt, ToVariant}; use sourceview::prelude::{ActionExt, ActionMapExt, DisplayExt, ToVariant};
@ -27,7 +27,7 @@ impl Markdown {
/// Build new `Self` /// Build new `Self`
pub fn build( pub fn build(
(window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>), (window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>),
profile: &Rc<Profile>, page: &Rc<Page>,
base: &Uri, base: &Uri,
markdown: &str, markdown: &str,
) -> Self { ) -> Self {
@ -180,7 +180,7 @@ impl Markdown {
let action_link_bookmark = let action_link_bookmark =
SimpleAction::new_stateful(&uuid_string_random(), None, &String::new().to_variant()); SimpleAction::new_stateful(&uuid_string_random(), None, &String::new().to_variant());
action_link_bookmark.connect_activate({ action_link_bookmark.connect_activate({
let p = profile.clone(); let p = page.profile.clone();
move |this, _| { move |this, _| {
let state = this.state().unwrap().get::<String>().unwrap(); let state = this.state().unwrap().get::<String>().unwrap();
p.bookmark.toggle(&state, None).unwrap(); p.bookmark.toggle(&state, None).unwrap();
@ -315,6 +315,7 @@ impl Markdown {
let headers = headers.clone(); let headers = headers.clone();
let item_action = item_action.clone(); let item_action = item_action.clone();
let links = links.clone(); let links = links.clone();
let page = page.clone();
let text_view = text_view.clone(); let text_view = text_view.clone();
move |_, _, window_x, window_y| { move |_, _, window_x, window_y| {
// Detect tag match current coords hovered // Detect tag match current coords hovered
@ -328,7 +329,7 @@ impl Markdown {
// Tag is link // Tag is link
if let Some(uri) = links.get(&tag) { if let Some(uri) = links.get(&tag) {
return if let Some(fragment) = uri.fragment() { return if let Some(fragment) = uri.fragment() {
scroll_to_anchor(&text_view, &headers, fragment); scroll_to_anchor(&page, &text_view, &headers, fragment);
} else { } else {
open_link_in_current_tab(&uri.to_string(), &item_action); open_link_in_current_tab(&uri.to_string(), &item_action);
}; };
@ -516,10 +517,11 @@ impl Markdown {
// Anchor auto-scroll behavior // Anchor auto-scroll behavior
idle_add_local({ idle_add_local({
let base = base.clone(); let base = base.clone();
let page = page.clone();
let text_view = text_view.clone(); let text_view = text_view.clone();
move || { move || {
if let Some(fragment) = base.fragment() { if let Some(fragment) = base.fragment() {
scroll_to_anchor(&text_view, &headers, fragment); scroll_to_anchor(&page, &text_view, &headers, fragment);
} }
ControlFlow::Break ControlFlow::Break
} }
@ -530,11 +532,12 @@ impl Markdown {
} }
fn scroll_to_anchor( fn scroll_to_anchor(
page: &Rc<Page>,
text_view: &TextView, text_view: &TextView,
headers: &HashMap<TextTag, (String, Uri)>, headers: &HashMap<TextTag, (String, Uri)>,
fragment: GString, fragment: GString,
) { ) {
if let Some((tag, _)) = headers.iter().find(|(_, (_, uri))| { if let Some((tag, (_, uri))) = headers.iter().find(|(_, (_, uri))| {
uri.fragment() uri.fragment()
.is_some_and(|f| fragment == tags::format_header_fragment(&f)) .is_some_and(|f| fragment == tags::format_header_fragment(&f))
}) { }) {
@ -542,6 +545,7 @@ fn scroll_to_anchor(
if iter.starts_tag(Some(tag)) || iter.forward_to_tag_toggle(Some(tag)) { if iter.starts_tag(Some(tag)) || iter.forward_to_tag_toggle(Some(tag)) {
text_view.scroll_to_iter(&mut iter, 0.0, true, 0.0, 0.0); text_view.scroll_to_iter(&mut iter, 0.0, true, 0.0, 0.0);
} }
page.navigation.request.entry.set_text(&uri.to_string())
} }
} }