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 {
pub fn handle(&self, page: &super::Page) {
pub fn handle(&self, page: &std::rc::Rc<super::Page>) {
page.navigation
.request
.info
@ -29,7 +29,7 @@ impl Text {
.info
.borrow_mut()
.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::Source(uri, data) => (uri, page.content.to_text_source(data)),

View file

@ -358,7 +358,7 @@ fn handle(
} else {
match m.as_str() {
"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),
_ => panic!() // unexpected
}

View file

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

View file

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

View file

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