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(),
+145
View File
@@ -0,0 +1,145 @@
use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, CommandScope, NoteTarget, ProfileKind, UrlText};
#[test]
fn url_note_records_active_page_context() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let tab_id = core.open_tab(UrlText::parse("https://example.com/notes-url")?);
let active_profile_id = core.active_tab()?.profile_id().clone();
let active_space_id = core.active_tab()?.space_id().clone();
let note_id = core.save_active_url_note("# Research\n- fact")?;
let snapshot = core.snapshot()?;
let [note] = snapshot.notes.as_slice() else {
return Err(format!("expected 1 note, got {}", snapshot.notes.len()).into());
};
assert_eq!(snapshot.active_tab_id, tab_id);
assert_eq!(note.id(), &note_id);
assert_eq!(note.profile_id(), &active_profile_id);
assert_eq!(note.space_id(), &active_space_id);
assert_eq!(note.target(), &NoteTarget::Url(UrlText::parse("https://example.com/notes-url")?));
assert_eq!(note.title(), "example.com");
assert_eq!(note.body(), "# Research\n- fact");
Ok(())
}
#[test]
fn tab_note_records_tab_target() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let tab_id = core.open_tab(UrlText::parse("https://example.com/tab-note")?);
core.save_active_tab_note("- tab detail")?;
let snapshot = core.snapshot()?;
let [note] = snapshot.notes.as_slice() else {
return Err(format!("expected 1 note, got {}", snapshot.notes.len()).into());
};
assert_eq!(note.target(), &NoteTarget::Tab(tab_id));
assert_eq!(note.target_label(), "Tab note");
assert_eq!(note.source_url().as_str(), "https://example.com/tab-note");
Ok(())
}
#[test]
fn url_note_command_updates_existing_note() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/research")?);
core.set_command_query(">note first");
core.submit_command()?;
core.set_command_query(">note second");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(intent, Some(CommandIntent::Command("note second".to_string())));
assert_eq!(snapshot.command_query, "");
assert_eq!(snapshot.notes.len(), 1);
assert_eq!(snapshot.notes[0].body(), "second");
Ok(())
}
#[test]
fn tab_note_command_records_tab_target() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let tab_id = core.open_tab(UrlText::parse("https://example.com/pinned-detail")?);
core.set_command_query(">tab-note - pinned detail");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(intent, Some(CommandIntent::Command("tab-note - pinned detail".to_string())));
assert_eq!(snapshot.command_query, "");
assert_eq!(snapshot.notes.len(), 1);
assert_eq!(snapshot.notes[0].target(), &NoteTarget::Tab(tab_id));
assert_eq!(snapshot.notes[0].body(), "- pinned detail");
Ok(())
}
#[test]
fn notes_scoped_search_opens_matching_note_url() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/matching-note")?);
core.save_active_url_note("# Citation\nunique cue")?;
core.open_tab(UrlText::parse("https://example.com/other")?);
core.set_command_query("@notes unique cue");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: CommandScope::Notes,
query: "unique cue".to_string()
})
);
assert_eq!(core.active_tab()?.url().as_str(), "https://example.com/matching-note");
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn notes_stay_with_active_profile() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let default_profile_id = core.active_tab()?.profile_id().clone();
let personal_profile_id = core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
core.open_tab(UrlText::parse("https://example.com/personal-note")?);
core.save_active_url_note("private cue")?;
core.select_profile(&default_profile_id)?;
core.set_command_query("@notes private cue");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: CommandScope::Notes,
query: "private cue".to_string()
})
);
assert_eq!(core.active_tab()?.profile_id(), &default_profile_id);
assert_ne!(core.active_tab()?.profile_id(), &personal_profile_id);
assert!(snapshot.notes.is_empty());
assert_eq!(snapshot.command_query, "@notes private cue");
Ok(())
}
#[test]
fn open_notes_command_opens_notes_page() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.set_command_query(">open-notes");
let intent = core.submit_command()?;
let active_tab = core.active_tab()?;
assert_eq!(intent, Some(CommandIntent::Command("open-notes".to_string())));
assert_eq!(active_tab.title(), "Notes");
assert_eq!(active_tab.url().as_str(), "ely://notes");
assert_eq!(core.snapshot()?.command_query, "");
Ok(())
}
+2
View File
@@ -12,6 +12,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
core.create_space("Research", "R", 0xf54e00)?;
core.open_tab(UrlText::parse("https://example.com/research")?);
core.bookmark_active_tab()?;
core.save_active_url_note("sync note")?;
core.save_active_tab_to_reading_list()?;
let snapshot = core.snapshot()?;
@@ -26,6 +27,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
SyncObjectStatus::new(SyncObjectKind::Spaces, 2, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Tabs, 3, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Bookmarks, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Notes, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::ReadingList, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Profiles, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::SitePermissions, 0, SyncObjectState::LocalOnly),