细化书签功能:正文指示器、侧边栏书签列表、跳转功能

This commit is contained in:
2026-05-15 11:27:22 +08:00
parent 88f15d307a
commit 2df605c864
2 changed files with 108 additions and 8 deletions

View File

@@ -275,9 +275,12 @@ BgType::Custom(ref path) if !path.is_empty() => {
let theme_copy = self.settings.theme;
let profile_names: Vec<String> = self.settings.profiles.iter().map(|p| p.name.clone()).collect();
let bookmarks = self.settings.bookmarks.get(&file_path).cloned().unwrap_or_default();
let mut jump_to_bookmark: Option<usize> = None;
egui::CentralPanel::default().show(ctx, |ui| {
let book = self.state.book.as_mut().unwrap();
let action = crate::reader::reading_view(
let (action, jump) = crate::reader::reading_view(
ui,
book,
&mut self.state.current_section,
@@ -288,7 +291,9 @@ BgType::Custom(ref path) if !path.is_empty() => {
bg_type.clone(),
&file_path,
&profile_names,
&bookmarks,
);
jump_to_bookmark = jump;
if action.go_back {
self.save_reading_position();
@@ -347,8 +352,49 @@ BgType::Custom(ref path) if !path.is_empty() => {
if action.page_next {
self.state.next_page();
}
if action.toggle_bookmark {
let file_path = file_path.clone();
let section = self.state.current_section;
let page = self.state.current_page;
let book = self.state.book.as_ref().unwrap();
let section_title = book.sections.get(section)
.map(|s| s.title.clone())
.unwrap_or_else(|| format!("{}", section + 1));
let bookmarks = self.settings.bookmarks.entry(file_path)
.or_insert_with(Vec::new);
let existing_idx = bookmarks.iter()
.position(|b: &theme::Bookmark| b.section == section && b.page == page);
if let Some(idx) = existing_idx {
bookmarks.remove(idx);
} else {
use std::time::{SystemTime, UNIX_EPOCH};
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs() as i64)
.unwrap_or(0);
bookmarks.push(theme::Bookmark {
section,
page,
label: format!("{} - 第{}页", section_title, page + 1),
timestamp,
});
}
}
});
if let Some(idx) = jump_to_bookmark {
if let Some(bookmarks) = self.settings.bookmarks.get(&file_path) {
if let Some(bm) = bookmarks.get(idx) {
self.state.current_section = bm.section;
self.state.current_page = bm.page;
}
}
}
// Sync style changes back to active profile (outside closure)
if let Some(p) = self.settings.profiles.iter_mut()
.find(|p| p.name == self.settings.active_profile)