Add page notes panel

This commit is contained in:
2026-05-08 06:53:31 -04:00
parent bae3c7789f
commit 7e68857eb8
15 changed files with 844 additions and 7 deletions
+13
View File
@@ -17,6 +17,7 @@ fn internal_page_title(url: &str) -> Option<&'static str> {
match url {
"ely://new-tab" => Some("New Tab"),
"ely://bookmarks" => Some("Bookmarks"),
"ely://notes" => Some("Notes"),
"ely://reading-list" => Some("Reading List"),
"ely://downloads" => Some("Downloads"),
"ely://history" => Some("History"),
@@ -91,6 +92,14 @@ pub(crate) fn reading_progress_percent(
ReadingProgressPercent::new(percent).map(Some).map_err(CoreError::from)
}
pub(crate) fn note_body(command: &str) -> Option<&str> {
command_argument(command, &["note ", "add-note ", "add note "])
}
pub(crate) fn tab_note_body(command: &str) -> Option<&str> {
command_argument(command, &["tab-note ", "tab note ", "note-tab ", "note tab "])
}
pub(crate) fn new_profile_name(command: &str) -> Option<&str> {
command_argument(command, &["new-profile ", "new profile "])
}
@@ -134,6 +143,10 @@ pub(crate) fn reading_list_url() -> Result<UrlText, CoreError> {
internal_page_url("ely://reading-list")
}
pub(crate) fn notes_url() -> Result<UrlText, CoreError> {
internal_page_url("ely://notes")
}
pub(crate) fn history_url() -> Result<UrlText, CoreError> {
internal_page_url("ely://history")
}
+8 -2
View File
@@ -3,8 +3,9 @@ use std::{collections::BTreeMap, time::SystemTime};
use ely_domain::{
ArchivePolicy, ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry,
DownloadPolicy, FavoriteLimit, HistoryEntry, HistoryRecordingPolicy, NewTabDestination,
Profile, ProfileId, ProfileKind, ReadingListEntry, SearchEngine, SitePermissionAuditEvent,
SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus, TabId, UrlText,
NoteEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, SearchEngine,
SitePermissionAuditEvent, SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus, TabId,
UrlText,
};
use crate::{CoreError, navigation::tab_title};
@@ -14,6 +15,7 @@ mod bookmarks;
mod commands;
mod downloads;
mod history;
mod notes;
mod plugins;
mod profiles;
mod reading_list;
@@ -51,6 +53,7 @@ pub struct BrowserSnapshot {
pub pinned_tabs: Vec<BrowserTab>,
pub archived_tabs: Vec<ArchivedTab>,
pub bookmarks: Vec<BookmarkEntry>,
pub notes: Vec<NoteEntry>,
pub reading_list: Vec<ReadingListEntry>,
pub site_permissions: Vec<SitePermissionEntry>,
pub site_permission_audit_events: Vec<SitePermissionAuditEvent>,
@@ -83,6 +86,7 @@ pub struct BrowserCore {
tabs: Vec<BrowserTab>,
archived_tabs: Vec<ArchivedTab>,
bookmarks: Vec<BookmarkEntry>,
notes: Vec<NoteEntry>,
reading_list: Vec<ReadingListEntry>,
site_permissions: Vec<SitePermissionEntry>,
site_permission_audit_events: Vec<SitePermissionAuditEvent>,
@@ -151,6 +155,7 @@ impl BrowserCore {
tabs: vec![tab],
archived_tabs: Vec::new(),
bookmarks: Vec::new(),
notes: Vec::new(),
reading_list: Vec::new(),
site_permissions: Vec::new(),
site_permission_audit_events: Vec::new(),
@@ -342,6 +347,7 @@ impl BrowserCore {
pinned_tabs: self.pinned_tabs(),
archived_tabs: self.archived_tabs.clone(),
bookmarks: self.visible_bookmarks(),
notes: self.visible_notes(),
reading_list: self.visible_reading_list(),
site_permissions: self.visible_site_permissions(),
site_permission_audit_events: self.visible_site_permission_audit_events(),
+22 -4
View File
@@ -6,10 +6,10 @@ use crate::{
CoreError,
navigation::{
about_url, archive_idle_days, archive_url, bookmarks_url, downloads_url, history_url,
move_tab_space_name, new_private_profile_name, new_profile_name, new_space_name,
plugin_detail_url, plugins_url, reading_list_url, reading_progress_percent, search_url,
settings_page_url, settings_url, shortcut_settings_url, space_icon, switch_profile_name,
sync_status_url, task_manager_url,
move_tab_space_name, new_private_profile_name, new_profile_name, new_space_name, note_body,
notes_url, plugin_detail_url, plugins_url, reading_list_url, reading_progress_percent,
search_url, settings_page_url, settings_url, shortcut_settings_url, space_icon,
switch_profile_name, sync_status_url, tab_note_body, task_manager_url,
},
};
@@ -61,6 +61,12 @@ impl BrowserCore {
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::Notes, query } => {
if let Some(url) = self.find_note_match(query) {
self.open_tab(url);
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::ReadingList, query } => {
if let Some(url) = self.find_reading_list_match(query) {
self.open_tab(url);
@@ -127,6 +133,14 @@ impl BrowserCore {
self.set_active_tab_reading_progress(percent)?;
return Ok(true);
}
if let Some(body) = tab_note_body(command) {
self.save_active_tab_note(body)?;
return Ok(true);
}
if let Some(body) = note_body(command) {
self.save_active_url_note(body)?;
return Ok(true);
}
match command.to_ascii_lowercase().as_str() {
"new-tab" => {
@@ -150,6 +164,10 @@ impl BrowserCore {
self.open_tab(reading_list_url()?);
Ok(true)
}
"notes" | "open-notes" | "open notes" => {
self.open_tab(notes_url()?);
Ok(true)
}
"history" | "open-history" | "open history" => {
self.open_tab(history_url()?);
Ok(true)
+114
View File
@@ -0,0 +1,114 @@
use std::time::SystemTime;
use ely_domain::{NoteEntry, NoteId, NoteTarget, UrlText};
use crate::CoreError;
use super::BrowserCore;
impl BrowserCore {
pub fn save_active_url_note(&mut self, body: impl Into<String>) -> Result<NoteId, CoreError> {
let active_tab = self.active_tab()?.clone();
let now = SystemTime::now();
let target = NoteTarget::Url(active_tab.url().clone());
if let Some(index) = self.note_index_for_target(active_tab.profile_id(), &target) {
self.notes[index].update(
active_tab.title(),
active_tab.url().clone(),
body.into(),
now,
)?;
return Ok(self.notes[index].id().clone());
}
let entry = NoteEntry::new(
active_tab.profile_id().clone(),
active_tab.space_id().clone(),
target,
active_tab.title(),
active_tab.url().clone(),
body,
now,
)?;
let entry_id = entry.id().clone();
self.notes.push(entry);
Ok(entry_id)
}
pub fn save_active_tab_note(&mut self, body: impl Into<String>) -> Result<NoteId, CoreError> {
let active_tab = self.active_tab()?.clone();
let now = SystemTime::now();
let target = NoteTarget::Tab(active_tab.id().clone());
if let Some(index) = self.note_index_for_target(active_tab.profile_id(), &target) {
self.notes[index].update(
active_tab.title(),
active_tab.url().clone(),
body.into(),
now,
)?;
return Ok(self.notes[index].id().clone());
}
let entry = NoteEntry::new(
active_tab.profile_id().clone(),
active_tab.space_id().clone(),
target,
active_tab.title(),
active_tab.url().clone(),
body,
now,
)?;
let entry_id = entry.id().clone();
self.notes.push(entry);
Ok(entry_id)
}
pub(super) fn find_note_match(&self, query: &str) -> Option<UrlText> {
let normalized_query = query.trim().to_lowercase();
if normalized_query.is_empty() {
return None;
}
self.notes
.iter()
.rev()
.filter(|entry| entry.profile_id() == &self.active_profile_id)
.find(|entry| note_entry_matches_query(entry, &normalized_query))
.map(|entry| entry.source_url().clone())
}
pub(super) fn visible_notes(&self) -> Vec<NoteEntry> {
self.notes
.iter()
.filter(|entry| entry.profile_id() == &self.active_profile_id)
.cloned()
.collect()
}
fn note_index_for_target(
&self,
profile_id: &ely_domain::ProfileId,
target: &NoteTarget,
) -> Option<usize> {
self.notes.iter().position(|entry| {
entry.profile_id() == profile_id && note_targets_match(entry.target(), target)
})
}
}
fn note_targets_match(left: &NoteTarget, right: &NoteTarget) -> bool {
match (left, right) {
(NoteTarget::Url(left_url), NoteTarget::Url(right_url)) => left_url == right_url,
(NoteTarget::Tab(left_tab), NoteTarget::Tab(right_tab)) => left_tab == right_tab,
_ => false,
}
}
fn note_entry_matches_query(entry: &NoteEntry, normalized_query: &str) -> bool {
entry.title().to_lowercase().contains(normalized_query)
|| entry.source_url().as_str().to_lowercase().contains(normalized_query)
|| entry.display_url().to_lowercase().contains(normalized_query)
|| entry.body().to_lowercase().contains(normalized_query)
}
@@ -7,6 +7,7 @@ pub(super) struct SyncObjectPolicies {
spaces: SyncObjectPolicy,
tabs: SyncObjectPolicy,
bookmarks: SyncObjectPolicy,
notes: SyncObjectPolicy,
reading_list: SyncObjectPolicy,
profiles: SyncObjectPolicy,
site_permissions: SyncObjectPolicy,
@@ -20,6 +21,7 @@ impl Default for SyncObjectPolicies {
spaces: SyncObjectPolicy::Enabled,
tabs: SyncObjectPolicy::Enabled,
bookmarks: SyncObjectPolicy::Enabled,
notes: SyncObjectPolicy::Enabled,
reading_list: SyncObjectPolicy::Enabled,
profiles: SyncObjectPolicy::Enabled,
site_permissions: SyncObjectPolicy::Enabled,
@@ -35,6 +37,7 @@ impl SyncObjectPolicies {
SyncObjectKind::Spaces => self.spaces,
SyncObjectKind::Tabs => self.tabs,
SyncObjectKind::Bookmarks => self.bookmarks,
SyncObjectKind::Notes => self.notes,
SyncObjectKind::ReadingList => self.reading_list,
SyncObjectKind::Profiles => self.profiles,
SyncObjectKind::SitePermissions => self.site_permissions,
@@ -48,6 +51,7 @@ impl SyncObjectPolicies {
SyncObjectKind::Spaces => self.spaces = policy,
SyncObjectKind::Tabs => self.tabs = policy,
SyncObjectKind::Bookmarks => self.bookmarks = policy,
SyncObjectKind::Notes => self.notes = policy,
SyncObjectKind::ReadingList => self.reading_list = policy,
SyncObjectKind::Profiles => self.profiles = policy,
SyncObjectKind::SitePermissions => self.site_permissions = policy,
@@ -84,6 +88,11 @@ impl BrowserCore {
self.bookmarks.len(),
SyncObjectState::LocalOnly,
),
self.sync_object_status(
SyncObjectKind::Notes,
self.notes.len(),
SyncObjectState::LocalOnly,
),
self.sync_object_status(
SyncObjectKind::ReadingList,
self.reading_list.len(),