mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-06 19:52:24 +03:00
feat(mobile): unlock database editing, experimental flags, doc info, and journal strip
Gate Page and Database edits of the embedded editor only by the Read-only toggle and trash. Gate Edgeless edits also by the enable_mobile_edgeless_editing flag, which the Settings Experimental sheet toggles. Add the View Info sheet to the page menu. It shows the creation and update times, toggles tags on the document through the workspace bridge, and counts backlinks and outgoing links. A connected workspace takes its tag list from the tag options of the workspace root, so the sheet writes only tag IDs that the root defines. Show a week strip below the header of a journal. A day with a journal replaces the open page, and a day without one opens the Journals tab. Today shows when the journal or the shown week is not today's, and returns the strip to this week. Make the drawer filter a text field. It shares the input handler and the UTF-16 edit rules of the Search query: caret keys, Shift to extend from a kept anchor, select all, and a clear button. Both fields draw the caret at the active end of the selection and highlight the selected text. Replace the Sync & Offline, Storage, and Notifications switches that had no backing service with read-only values. Remove the static sync pill from the page header.
This commit is contained in:
1 parent
438c5cff16
commit
f8e5ff6ea1
36 files changed
+2912
-669
No files matched your search
@@ -4,7 +4,7 @@
|
||||
|
||||
## Scope and integration boundary
|
||||
|
||||
- `affine-mobile` owns the interactive 4-TabBar product shell (`Home`, `Explorer`, `Journals`, `Search`), 10-group `Settings`, `WorkspaceDrawer`, `Page` header (`Breadcrumb`, `Read-only` / `Editing` toggle, `DocActions` sheet with the `Page | Edgeless` view switch and `Default to Edgeless mode`, `Location & Trail`, `Table of contents`, and same-day journal conflict sheets, independent `Backlinks` pill/sheet), embedded live `Entity<playground::PlaygroundView>` (`hide_chrome = true`, `WorkspaceDocDirectory` injection, the document's primary mode or the session's view mode, `page_readonly` for trashed docs and the `Read-only` toggle), `MobileBackCoordinator`, and frame-1 `AccessibilityTree` publication.
|
||||
- `affine-mobile` owns the interactive 4-TabBar product shell (`Home`, `Explorer`, `Journals`, `Search`), 10-group `Settings` (with the `Experimental` sheet), `WorkspaceDrawer` (with its typed filter), `Page` header (`Breadcrumb`, `Read-only` / `Editing` toggle, the journal week strip of a journal, `DocActions` sheet with the `Page | Edgeless` view switch and `Default to Edgeless mode`, `View Info`, `Location & Trail`, `Table of contents`, and same-day journal conflict sheets, independent `Backlinks` pill/sheet), embedded live `Entity<playground::PlaygroundView>` (`hide_chrome = true`, `WorkspaceDocDirectory` injection, the document's primary mode or the session's view mode, Page and Database edits gated by `page_readonly` for trashed docs and the `Read-only` toggle, Edgeless edits gated also by `enable_mobile_edgeless_editing`), `MobileBackCoordinator`, and frame-1 `AccessibilityTree` publication.
|
||||
- Live `affine-store` / `affine-client` SQLite WAL persistence and `SpaceSync` bridge attach via `workspace_bridge/` (for Rust workspace sessions; native iOS and Android thin hosts currently mount `playground::PlaygroundView` + `SqliteWorkspaceStore` bridges directly); `showcase::seed_showcase_state` supplies deterministic in-memory workspaces for offline harness verification and preview galleries.
|
||||
|
||||
## Domain boundaries and invariants
|
||||
@@ -14,6 +14,8 @@
|
||||
- Use logical inline geometry (`ui_kit::LogicalEdges`, `ui_kit::LogicalStyled`, `ui_kit::SafeArea`, `inline_start`, `inline_end`) instead of physical left/right layout helpers so `ar`/`fa`/`ur` locales mirror cleanly.
|
||||
- Drive all transitions from closed-form scheduler time (`ui::Motion`, `ui_kit::Sheet`, `ui_kit::evaluate_micro_icon`). Never call system wall clocks (`Instant::now`, `SystemTime::now`, `Zoned::now`, `Timestamp::now`).
|
||||
- Keep `Settings` aligned with the 10-section mobile contract and never expose `enable_editor_rtl` in Experimental settings.
|
||||
A row without a backing service shows a read-only value (the workspace sync status, where the workspace is stored) instead of a switch that changes nothing.
|
||||
- The `Search` query and the `WorkspaceDrawer` filter take text through the one `EntityInputHandler` of `MobileShellView` and the shared `state::TextFieldMut` edit rules.
|
||||
- Flush a `workspace_bridge/` session through `SqliteWorkspaceStore::flush_session_mutations` (`MobileWorkspaceBridge::flush_session_mutations`) so that local clocks, deletion tombstones, and `pushed_clock` advances commit together.
|
||||
`MobileShellView::connect_workspace` binds the transport and starts a one-second UI scheduler timer. The shell flushes SQLite off the UI thread, projects the result into the binding that ran the tick, repaints only when the projection changed what the shell shows, and delivers sync events to the host. The shell commits pending local changes to the old SQLite store before it replaces or detaches a connected bridge.
|
||||
A page that leaves the root document leaves the shell with its cached bytes, while shell-only drafts stay.
|
||||
|
||||
@@ -383,14 +383,6 @@ pub(crate) fn perform_a11y_action_with_layout(
|
||||
state.open_settings();
|
||||
true
|
||||
}
|
||||
"mobile.settings.group.1" => {
|
||||
state.open_sheet_from(
|
||||
MobileSheet::WorkspaceSelector,
|
||||
Some("mobile.settings.group.1"),
|
||||
now_ms,
|
||||
);
|
||||
true
|
||||
}
|
||||
"mobile.search.clear_btn" => {
|
||||
state.search_query.clear();
|
||||
state.search_preedit = None;
|
||||
@@ -468,7 +460,17 @@ pub(crate) fn perform_a11y_action_with_layout(
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
state.activate_setting(group)
|
||||
state.activate_setting(group, now_ms)
|
||||
}
|
||||
"mobile.page.journal_strip.prev_btn" => state.shift_journal_strip(-1),
|
||||
"mobile.page.journal_strip.next_btn" => state.shift_journal_strip(1),
|
||||
"mobile.page.journal_strip.today_btn" => {
|
||||
let today = state.today_date.clone();
|
||||
state.open_journal_date(&today, now_ms)
|
||||
}
|
||||
_ if node_id.starts_with("mobile.page.journal_strip.day.") => {
|
||||
let date = node_id["mobile.page.journal_strip.day.".len()..].to_string();
|
||||
state.open_journal_date(&date, now_ms)
|
||||
}
|
||||
_ if node_id.starts_with("mobile.journals.day.") => {
|
||||
let date = &node_id["mobile.journals.day.".len()..];
|
||||
|
||||
@@ -25,7 +25,6 @@ use ui_kit::BreadcrumbBarLayout;
|
||||
|
||||
use crate::state::{
|
||||
MobileAppState, MobileRoute, MobileSheet, MobileTab, SettingRowInteraction, SettingsGroupId,
|
||||
ThemePreference,
|
||||
};
|
||||
|
||||
use self::{
|
||||
@@ -315,55 +314,14 @@ pub fn build_accessibility_tree_with_layout(
|
||||
let row_x = content_left + 14.0;
|
||||
let row_w = (content_w - 28.0).max(44.0);
|
||||
for (idx, group) in SettingsGroupId::ALL.iter().copied().enumerate() {
|
||||
let is_info = group.interaction() == SettingRowInteraction::Info;
|
||||
let row_id = if is_info {
|
||||
format!("mobile.settings.group.{idx}")
|
||||
} else {
|
||||
format!("mobile.settings.row.{}", group.a11y_key())
|
||||
};
|
||||
let val = match group {
|
||||
SettingsGroupId::Account => {
|
||||
if state.settings.account_email.trim().is_empty() {
|
||||
strings.sign_in_label.to_string()
|
||||
} else {
|
||||
state.settings.account_email.clone()
|
||||
}
|
||||
let row_id = group.a11y_id();
|
||||
let val = state.setting_value(group);
|
||||
let (role, expanded) = match group.interaction() {
|
||||
SettingRowInteraction::Info => (AccessibilityRole::Region, None),
|
||||
SettingRowInteraction::Cycle => (AccessibilityRole::Button, None),
|
||||
SettingRowInteraction::Sheet(sheet) => {
|
||||
(AccessibilityRole::Button, Some(state.active_sheet == sheet))
|
||||
}
|
||||
SettingsGroupId::Workspace => state.active_workspace().summary.name.clone(),
|
||||
SettingsGroupId::Appearance => match state.settings.theme_preference {
|
||||
ThemePreference::Light => strings.theme_light.to_string(),
|
||||
ThemePreference::Dark => strings.theme_dark.to_string(),
|
||||
ThemePreference::System => strings.theme_system.to_string(),
|
||||
},
|
||||
SettingsGroupId::Language => state.settings.locale.display_name().to_string(),
|
||||
SettingsGroupId::Editor => format!("{}%", state.settings.editor_font_scale_pct),
|
||||
SettingsGroupId::SyncOffline => if state.settings.offline_sync_enabled {
|
||||
strings.toggle_on
|
||||
} else {
|
||||
strings.toggle_off
|
||||
}
|
||||
.to_string(),
|
||||
SettingsGroupId::Storage => format!("{} MB", state.settings.cache_size_mb),
|
||||
SettingsGroupId::Notifications => if state.settings.push_notifications {
|
||||
strings.toggle_on
|
||||
} else {
|
||||
strings.toggle_off
|
||||
}
|
||||
.to_string(),
|
||||
SettingsGroupId::Experimental => {
|
||||
strings.flags_count(locale, state.settings.experimental_flags.len())
|
||||
}
|
||||
SettingsGroupId::About => {
|
||||
format!(
|
||||
"{} v{}",
|
||||
strings.about_version_label, state.settings.app_version
|
||||
)
|
||||
}
|
||||
};
|
||||
let role = if !is_info || group == SettingsGroupId::Workspace {
|
||||
AccessibilityRole::Button
|
||||
} else {
|
||||
AccessibilityRole::Region
|
||||
};
|
||||
nodes.insert(
|
||||
row_id.clone(),
|
||||
@@ -372,7 +330,10 @@ pub fn build_accessibility_tree_with_layout(
|
||||
role,
|
||||
name: strings.settings_groups[idx].to_string(),
|
||||
value: Some(val),
|
||||
state: AccessibilityState::default(),
|
||||
state: AccessibilityState {
|
||||
expanded,
|
||||
..AccessibilityState::default()
|
||||
},
|
||||
focused: false,
|
||||
bounds: AccessibilityBounds {
|
||||
x: row_x,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
//! Page-route accessibility tree builder (breadcrumb landmark, drawer button, sync status,
|
||||
//! document title heading, backlinks pill, trash actions, and block-level semantic nodes).
|
||||
//! Page-route accessibility tree builder (breadcrumb landmark, drawer button, journal week
|
||||
//! strip, document title heading, backlinks pill, trash actions, and block-level semantic nodes).
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use affine_client::{
|
||||
AccessibilityBounds, AccessibilityNode, AccessibilityRole, AccessibilityState, ContextState,
|
||||
WorkspaceSyncStatus,
|
||||
};
|
||||
use ui_kit::{
|
||||
BreadcrumbBarConfig, BreadcrumbBarLayout, BreadcrumbItem, BreadcrumbItemKind,
|
||||
@@ -196,50 +195,6 @@ pub(super) fn insert_page_a11y_nodes(
|
||||
);
|
||||
main_children.push(drawer_id);
|
||||
|
||||
if content_w >= 360.0 {
|
||||
let sync_id = "mobile.page.sync_status".to_string();
|
||||
let sync_name = match state.active_workspace().sync_status {
|
||||
WorkspaceSyncStatus::Synced => strings.sync_synced.to_string(),
|
||||
WorkspaceSyncStatus::Syncing { pending_updates } => {
|
||||
if pending_updates > 0 {
|
||||
format!("{} ({pending_updates})", strings.sync_syncing)
|
||||
} else {
|
||||
strings.sync_syncing.to_string()
|
||||
}
|
||||
}
|
||||
WorkspaceSyncStatus::Connecting => strings.sync_connecting.to_string(),
|
||||
WorkspaceSyncStatus::Offline | WorkspaceSyncStatus::ReconnectScheduled { .. } => {
|
||||
strings.sync_offline.to_string()
|
||||
}
|
||||
WorkspaceSyncStatus::AuthRequired | WorkspaceSyncStatus::PermissionRevoked => {
|
||||
strings.sync_auth_required.to_string()
|
||||
}
|
||||
};
|
||||
nodes.insert(
|
||||
sync_id.clone(),
|
||||
AccessibilityNode {
|
||||
id: sync_id.clone(),
|
||||
role: AccessibilityRole::Status,
|
||||
name: sync_name,
|
||||
value: None,
|
||||
state: AccessibilityState::default(),
|
||||
focused: false,
|
||||
bounds: AccessibilityBounds {
|
||||
x: if is_rtl {
|
||||
content_left + 104.0 + toggle_w
|
||||
} else {
|
||||
content_left + (content_w - 168.0 - toggle_w).max(0.0)
|
||||
},
|
||||
y: safe_top + 14.0,
|
||||
width: 64.0,
|
||||
height: 24.0,
|
||||
},
|
||||
children: Vec::new(),
|
||||
},
|
||||
);
|
||||
main_children.push(sync_id);
|
||||
}
|
||||
|
||||
if toggles_readonly {
|
||||
let toggle_id = "mobile.page.readonly_toggle".to_string();
|
||||
let readonly = state.page_readonly(doc_id);
|
||||
@@ -306,6 +261,18 @@ pub(super) fn insert_page_a11y_nodes(
|
||||
main_children.push(more_id);
|
||||
}
|
||||
|
||||
if !derivation.in_trash {
|
||||
main_children.extend(insert_journal_strip_nodes(
|
||||
state,
|
||||
doc_id,
|
||||
content_left,
|
||||
content_w,
|
||||
safe_top,
|
||||
is_rtl,
|
||||
nodes,
|
||||
));
|
||||
}
|
||||
|
||||
let doc_opt = state.doc_by_id(doc_id).cloned();
|
||||
let ws_id = state.active_workspace_id().to_string();
|
||||
let Some(doc) = doc_opt else {
|
||||
@@ -504,3 +471,94 @@ pub(super) fn insert_page_a11y_nodes(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Buttons of the journal week strip of `doc_id` in reading order, when the document is a
|
||||
/// journal. Painted bounds replace these estimates once the frame is laid out.
|
||||
fn insert_journal_strip_nodes(
|
||||
state: &MobileAppState,
|
||||
doc_id: &str,
|
||||
content_left: f32,
|
||||
content_w: f32,
|
||||
safe_top: f32,
|
||||
is_rtl: bool,
|
||||
nodes: &mut BTreeMap<String, AccessibilityNode>,
|
||||
) -> Vec<String> {
|
||||
let (Some(selected), Some(week_date)) = (
|
||||
state.doc_by_id(doc_id).and_then(|d| d.journal_date.clone()),
|
||||
state.journal_strip_date(doc_id),
|
||||
) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let strings = state.locale().strings();
|
||||
let top = safe_top + 52.0;
|
||||
let inline_x = |start: f32, width: f32| {
|
||||
if is_rtl {
|
||||
content_left + (content_w - start - width).max(0.0)
|
||||
} else {
|
||||
content_left + start
|
||||
}
|
||||
};
|
||||
let mut buttons = vec![(
|
||||
"mobile.page.journal_strip.prev_btn".to_string(),
|
||||
strings.prev_week_label.to_string(),
|
||||
false,
|
||||
(inline_x(4.0, 44.0), top, 44.0),
|
||||
)];
|
||||
if state.journal_strip_shows_today(doc_id) {
|
||||
buttons.push((
|
||||
"mobile.page.journal_strip.today_btn".to_string(),
|
||||
strings.today_btn_label.to_string(),
|
||||
false,
|
||||
(inline_x(content_w - 112.0, 60.0), top, 60.0),
|
||||
));
|
||||
}
|
||||
buttons.push((
|
||||
"mobile.page.journal_strip.next_btn".to_string(),
|
||||
strings.next_week_label.to_string(),
|
||||
false,
|
||||
(inline_x(content_w - 48.0, 44.0), top, 44.0),
|
||||
));
|
||||
let cell_w = ((content_w - 8.0 - 24.0) / 7.0).max(1.0);
|
||||
for (idx, (_, day, date)) in crate::views::week_days_for_date(&week_date)
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
buttons.push((
|
||||
format!("mobile.page.journal_strip.day.{date}"),
|
||||
format!("{} {day}, {date}", strings.weekday_short[idx]),
|
||||
date == selected,
|
||||
(
|
||||
inline_x(4.0 + idx as f32 * (cell_w + 4.0), cell_w),
|
||||
top + 44.0,
|
||||
cell_w,
|
||||
),
|
||||
));
|
||||
}
|
||||
buttons
|
||||
.into_iter()
|
||||
.map(|(id, name, selected, (x, y, width))| {
|
||||
nodes.insert(
|
||||
id.clone(),
|
||||
AccessibilityNode {
|
||||
id: id.clone(),
|
||||
role: AccessibilityRole::Button,
|
||||
name,
|
||||
value: None,
|
||||
state: AccessibilityState {
|
||||
selected,
|
||||
..AccessibilityState::default()
|
||||
},
|
||||
focused: false,
|
||||
bounds: AccessibilityBounds {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height: 44.0,
|
||||
},
|
||||
children: Vec::new(),
|
||||
},
|
||||
);
|
||||
id
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Modal bottom-sheet accessibility tree builder (`LocationAndTrail`, `WorkspaceSelector`, `Backlinks`).
|
||||
//! Modal bottom-sheet accessibility tree builder (every `MobileSheet`, the drawer included).
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -6,8 +6,12 @@ use affine_client::{
|
||||
AccessibilityBounds, AccessibilityNode, AccessibilityRole, AccessibilityState, ContextState,
|
||||
};
|
||||
|
||||
use crate::state::{
|
||||
DocAction, MobileAppState, MobileRoute, MobileSheet, TocEntry, VIEW_MODE_SWITCH,
|
||||
use crate::{
|
||||
state::{
|
||||
DocAction, ExperimentalFlag, MobileAppState, MobileRoute, MobileSheet, TocEntry,
|
||||
VIEW_MODE_SWITCH,
|
||||
},
|
||||
views::{doc_info_rows, doc_info_tag_id},
|
||||
};
|
||||
|
||||
use super::SafeAreaMetrics;
|
||||
@@ -39,6 +43,8 @@ pub(super) fn insert_sheet_a11y_nodes(
|
||||
let mut intro_nodes: Vec<(String, AccessibilityRole, String, f32)> = Vec::new();
|
||||
let mut confirm_rows: Option<(String, String, String, String)> = None;
|
||||
let mut cols: Vec<Vec<(String, String, bool, f32)>> = Vec::new();
|
||||
// Rows of `cols` that switch a setting on and off: their flag is `checked`.
|
||||
let mut switch_rows = false;
|
||||
match state.active_sheet {
|
||||
MobileSheet::LocationAndTrail => {
|
||||
let derivation = state.derive_breadcrumb();
|
||||
@@ -281,9 +287,63 @@ pub(super) fn insert_sheet_a11y_nodes(
|
||||
),
|
||||
]);
|
||||
}
|
||||
MobileSheet::Experimental => {
|
||||
switch_rows = true;
|
||||
cols.push(
|
||||
ExperimentalFlag::ALL
|
||||
.iter()
|
||||
.map(|flag| {
|
||||
(
|
||||
flag.a11y_id(),
|
||||
flag.name(strings).to_string(),
|
||||
state.settings.flag(*flag),
|
||||
64.0,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
MobileSheet::DocInfo => {
|
||||
let doc_id = state.page_doc_id().unwrap_or_default().to_string();
|
||||
let (times, links) = doc_info_rows(state, &doc_id);
|
||||
for (id, _, label, value) in times.into_iter().chain(links) {
|
||||
intro_nodes.push((
|
||||
id.to_string(),
|
||||
AccessibilityRole::Region,
|
||||
format!("{label}: {value}"),
|
||||
44.0,
|
||||
));
|
||||
}
|
||||
switch_rows = true;
|
||||
let doc_tags = state
|
||||
.doc_by_id(&doc_id)
|
||||
.map(|d| d.tags.clone())
|
||||
.unwrap_or_default();
|
||||
cols.push(
|
||||
state
|
||||
.active_workspace()
|
||||
.tags
|
||||
.iter()
|
||||
.map(|(tag_id, name)| {
|
||||
(
|
||||
doc_info_tag_id(tag_id),
|
||||
name.clone(),
|
||||
doc_tags.contains(tag_id),
|
||||
44.0,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
MobileSheet::WorkspaceDrawer => {
|
||||
let is_tablet = viewport_width >= 720.0 && !compact;
|
||||
let sections = state.drawer_sections();
|
||||
intro_nodes.push((
|
||||
"mobile.drawer.filter_bar".to_string(),
|
||||
AccessibilityRole::TextField,
|
||||
strings.drawer_filter_placeholder.to_string(),
|
||||
44.0,
|
||||
));
|
||||
let mut items = vec![
|
||||
(
|
||||
"mobile.drawer.close_btn".to_string(),
|
||||
@@ -304,6 +364,14 @@ pub(super) fn insert_sheet_a11y_nodes(
|
||||
44.0,
|
||||
),
|
||||
];
|
||||
if !state.drawer_filter.is_empty() {
|
||||
items.push((
|
||||
"mobile.drawer.filter_clear_btn".to_string(),
|
||||
strings.clear_label.to_string(),
|
||||
false,
|
||||
44.0,
|
||||
));
|
||||
}
|
||||
if compact {
|
||||
for (id, title) in sections.all_docs.iter().take(2) {
|
||||
items.push((
|
||||
@@ -429,6 +497,10 @@ pub(super) fn insert_sheet_a11y_nodes(
|
||||
intro_y += h;
|
||||
}
|
||||
|
||||
if let Some(field) = nodes.get_mut("mobile.drawer.filter_bar") {
|
||||
field.value = Some(state.drawer_filter.clone());
|
||||
}
|
||||
|
||||
if let Some((cancel_id, cancel_name, confirm_id, confirm_name)) = confirm_rows {
|
||||
let btn_w = ((inner_w - 10.0) * 0.5).max(44.0);
|
||||
let btn_y =
|
||||
@@ -489,7 +561,8 @@ pub(super) fn insert_sheet_a11y_nodes(
|
||||
name,
|
||||
value: None,
|
||||
state: AccessibilityState {
|
||||
selected,
|
||||
selected: selected && !switch_rows,
|
||||
checked: switch_rows.then_some(selected),
|
||||
..AccessibilityState::default()
|
||||
},
|
||||
focused: false,
|
||||
@@ -508,20 +581,7 @@ pub(super) fn insert_sheet_a11y_nodes(
|
||||
}
|
||||
|
||||
let sheet_id = "app.sheet.dialog".to_string();
|
||||
let sheet_name = match state.active_sheet {
|
||||
MobileSheet::WorkspaceSelector => strings.switch_workspace,
|
||||
MobileSheet::WorkspaceDrawer => strings.drawer_title,
|
||||
MobileSheet::DocActions => strings.doc_actions_title,
|
||||
MobileSheet::LocationAndTrail => strings.location_trail_title,
|
||||
MobileSheet::Backlinks => strings.backlinks_label,
|
||||
MobileSheet::ConfirmDeleteDoc => strings.confirm_delete_title,
|
||||
MobileSheet::ConfirmTrashDoc => strings.confirm_trash_title,
|
||||
MobileSheet::Toc => strings.toc_title,
|
||||
MobileSheet::JournalConflicts | MobileSheet::JournalConflictOps => {
|
||||
strings.journal_conflicts
|
||||
}
|
||||
MobileSheet::None => "",
|
||||
};
|
||||
let sheet_name = state.active_sheet.title(strings);
|
||||
nodes.insert(
|
||||
sheet_id.clone(),
|
||||
AccessibilityNode {
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
use affine_client::{BreadcrumbAction, ContextState, LocationChoice, Origin};
|
||||
|
||||
use crate::state::{DocAction, MobileAppState, MobileRoute, MobileSheet, VIEW_MODE_SWITCH};
|
||||
use crate::state::{
|
||||
DocAction, ExperimentalFlag, MobileAppState, MobileRoute, MobileSheet, VIEW_MODE_SWITCH,
|
||||
};
|
||||
|
||||
pub(super) fn perform_sheet_a11y_action(
|
||||
state: &mut MobileAppState,
|
||||
@@ -171,8 +173,12 @@ pub(super) fn perform_sheet_a11y_action(
|
||||
state.close_sheet(now_ms);
|
||||
ok
|
||||
}
|
||||
DocAction::LocationTrail | DocAction::Toc | DocAction::JournalConflicts => {
|
||||
DocAction::ViewInfo
|
||||
| DocAction::LocationTrail
|
||||
| DocAction::Toc
|
||||
| DocAction::JournalConflicts => {
|
||||
let sheet = match action {
|
||||
DocAction::ViewInfo => MobileSheet::DocInfo,
|
||||
DocAction::LocationTrail => MobileSheet::LocationAndTrail,
|
||||
DocAction::Toc => MobileSheet::Toc,
|
||||
_ => MobileSheet::JournalConflicts,
|
||||
@@ -183,6 +189,36 @@ pub(super) fn perform_sheet_a11y_action(
|
||||
DocAction::Trash => state.move_doc_to_trash_scoped(&ws_id, &doc_id, now_ms),
|
||||
}
|
||||
}
|
||||
MobileSheet::Experimental => {
|
||||
let Some(flag) = ExperimentalFlag::ALL
|
||||
.into_iter()
|
||||
.find(|f| f.a11y_id() == node_id)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
state.toggle_experimental_flag(flag);
|
||||
true
|
||||
}
|
||||
MobileSheet::DocInfo => {
|
||||
let ws_id = state.active_workspace_id().to_string();
|
||||
let Some(doc_id) = state.page_doc_id().map(str::to_string) else {
|
||||
return false;
|
||||
};
|
||||
let Some(tags) = node_id
|
||||
.strip_prefix("mobile.sheet.doc_info.tag.")
|
||||
.filter(|tag| {
|
||||
state
|
||||
.active_workspace()
|
||||
.tags
|
||||
.iter()
|
||||
.any(|(id, _)| id == tag)
|
||||
})
|
||||
.and_then(|tag| state.toggled_doc_tags(&doc_id, tag))
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
state.set_doc_tags_scoped(&ws_id, &doc_id, tags)
|
||||
}
|
||||
MobileSheet::Toc => {
|
||||
let Some(entry) = node_id
|
||||
.strip_prefix("mobile.sheet.toc.")
|
||||
@@ -285,6 +321,12 @@ pub(super) fn perform_sheet_a11y_action(
|
||||
state.create_doc(None, now_ms);
|
||||
true
|
||||
}
|
||||
"mobile.drawer.filter_bar" => true,
|
||||
"mobile.drawer.filter_clear_btn" => {
|
||||
let had_filter = !state.drawer_filter.is_empty();
|
||||
state.set_drawer_filter("");
|
||||
had_filter
|
||||
}
|
||||
_ => {
|
||||
let doc_id = node_id
|
||||
.strip_prefix("mobile.drawer.fav.")
|
||||
|
||||
@@ -5,8 +5,8 @@ use std::path::Path;
|
||||
|
||||
use affine_client::{AccessibilityRole, DirectKind, Origin};
|
||||
use affine_mobile::{
|
||||
MobileAppState, MobileLocale, MobileSheet, MobileTab, build_accessibility_tree,
|
||||
seed_showcase_state, validate_accessibility_tree,
|
||||
ExperimentalFlag, MobileAppState, MobileLocale, MobileSheet, MobileTab, SettingsGroupId,
|
||||
build_accessibility_tree, seed_showcase_state, validate_accessibility_tree,
|
||||
};
|
||||
use anyhow::{Result, bail};
|
||||
use serde_json::json;
|
||||
@@ -113,7 +113,7 @@ fn check_doclink_switcher(
|
||||
enum MatrixCase {
|
||||
/// RTL mirror symmetry of the breadcrumb bar at one viewport width.
|
||||
Mirror { vp: (u32, u32) },
|
||||
/// The nine routes of one viewport, theme and locale.
|
||||
/// The thirteen routes and sheets of one viewport, theme and locale.
|
||||
Routes {
|
||||
vp: (u32, u32),
|
||||
theme: ThemeMode,
|
||||
@@ -218,7 +218,7 @@ fn audit_case(case: &MatrixCase, snapshots: Option<&Path>) -> Result<(Vec<String
|
||||
let state = seed_showcase_state(locale, theme, "2026-11-25");
|
||||
let session = start_session(vp_w, vp_h, 1.0, state)?;
|
||||
|
||||
let routes: [(&str, Box<dyn Fn(&mut MobileAppState)>); 9] = [
|
||||
let routes: [(&str, Box<dyn Fn(&mut MobileAppState)>); 13] = [
|
||||
("home", Box::new(|s| s.switch_tab(MobileTab::Home, 0.0))),
|
||||
(
|
||||
"explorer",
|
||||
@@ -258,6 +258,40 @@ fn audit_case(case: &MatrixCase, snapshots: Option<&Path>) -> Result<(Vec<String
|
||||
}),
|
||||
),
|
||||
("settings", Box::new(|s| s.open_settings())),
|
||||
(
|
||||
"experimental_sheet",
|
||||
Box::new(|s| {
|
||||
s.activate_setting(SettingsGroupId::Experimental, 1100.0);
|
||||
s.toggle_experimental_flag(ExperimentalFlag::MobileEdgelessEditing);
|
||||
s.settle_animations(1600.0);
|
||||
}),
|
||||
),
|
||||
(
|
||||
"doc_info_sheet",
|
||||
Box::new(|s| {
|
||||
s.close_sheet(1700.0);
|
||||
s.settle_animations(2200.0);
|
||||
s.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||||
s.open_sheet(MobileSheet::DocInfo, 2200.0);
|
||||
s.settle_animations(2700.0);
|
||||
}),
|
||||
),
|
||||
(
|
||||
"journal_page",
|
||||
Box::new(|s| {
|
||||
s.close_sheet(2800.0);
|
||||
s.settle_animations(3300.0);
|
||||
s.open_doc("doc-journal", Origin::Journal);
|
||||
}),
|
||||
),
|
||||
(
|
||||
"drawer_filter",
|
||||
Box::new(|s| {
|
||||
s.open_workspace_drawer(Some("mobile.page.drawer_btn"), 3300.0);
|
||||
s.set_drawer_filter("Sync");
|
||||
s.settle_animations(3800.0);
|
||||
}),
|
||||
),
|
||||
];
|
||||
|
||||
for (route_name, setup) in &routes {
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
//! - Multi-doc workspace drawer open (iOS 27 `pane_corner = 38pt`, fixed short title, liquid-glass close)
|
||||
//! - Document switch before (`doc-arch`) and after (`doc-sync`) via `open_document`
|
||||
//! - Inserted `affine:image` + `affine:attachment` blocks with blob metadata & upload badges
|
||||
//! - Live `SpaceSync` status indicator (`Synced`, `Syncing (2)`)
|
||||
//! - Live `SpaceSync` status indicator (`Synced`, `Syncing (2)`) in the drawer
|
||||
//! - `Settings -> Experimental`, `View Info`, the journal week strip, and the typed drawer filter
|
||||
//!
|
||||
//! `--only <pattern>` renders the shots whose file name contains the pattern, `--jobs <n>`
|
||||
//! sets the thread count (default: the available cores, at most 4; the phone and the tablet
|
||||
@@ -15,7 +16,8 @@ use std::path::PathBuf;
|
||||
|
||||
use affine_client::{BlobUploadState, DirectKind, Origin, WorkspaceSyncStatus};
|
||||
use affine_mobile::{
|
||||
MobileAppState, MobileDocBlock, MobileLocale, MobileSheet, MobileTab, seed_showcase_state,
|
||||
ExperimentalFlag, MobileAppState, MobileDocBlock, MobileLocale, MobileSheet, MobileTab,
|
||||
SettingsGroupId, seed_showcase_state,
|
||||
};
|
||||
use anyhow::{Context as _, Result};
|
||||
use ui_tokens::ThemeMode;
|
||||
@@ -95,7 +97,7 @@ struct ShellShot {
|
||||
const PHONE: (u32, u32) = (390, 844);
|
||||
const TABLET: (u32, u32) = (1024, 768);
|
||||
|
||||
static SHELL_SHOTS: [ShellShot; 10] = [
|
||||
static SHELL_SHOTS: [ShellShot; 19] = [
|
||||
ShellShot {
|
||||
filename: "mobile-phone-drawer-light.png",
|
||||
size: PHONE,
|
||||
@@ -135,6 +137,64 @@ static SHELL_SHOTS: [ShellShot; 10] = [
|
||||
theme: ThemeMode::Dark,
|
||||
setup: attach_sample_media_blocks,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-experimental-light.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Light,
|
||||
setup: open_experimental_sheet,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-experimental-dark.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Dark,
|
||||
setup: open_experimental_sheet,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-doc-info-light.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Light,
|
||||
setup: open_doc_info_sheet,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-doc-info-dark.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Dark,
|
||||
setup: open_doc_info_sheet,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-journal-strip-light.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Light,
|
||||
setup: open_journal_strip,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-journal-strip-dark.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Dark,
|
||||
setup: open_journal_strip,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-drawer-filter-light.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Light,
|
||||
setup: open_filtered_drawer,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-drawer-filter-dark.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Dark,
|
||||
setup: open_filtered_drawer,
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-phone-doc-actions-light.png",
|
||||
size: PHONE,
|
||||
theme: ThemeMode::Light,
|
||||
setup: |s| {
|
||||
s.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||||
s.open_sheet(MobileSheet::DocActions, 0.0);
|
||||
s.settle_animations(500.0);
|
||||
},
|
||||
},
|
||||
ShellShot {
|
||||
filename: "mobile-tablet-drawer-light.png",
|
||||
size: TABLET,
|
||||
@@ -167,6 +227,34 @@ fn open_phone_drawer(s: &mut MobileAppState) {
|
||||
s.settle_animations(500.0);
|
||||
}
|
||||
|
||||
fn open_experimental_sheet(s: &mut MobileAppState) {
|
||||
s.open_settings();
|
||||
s.activate_setting(SettingsGroupId::Experimental, 0.0);
|
||||
s.toggle_experimental_flag(ExperimentalFlag::MobileEdgelessEditing);
|
||||
s.settle_animations(500.0);
|
||||
}
|
||||
|
||||
fn open_doc_info_sheet(s: &mut MobileAppState) {
|
||||
s.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||||
let ws = s.active_workspace_mut();
|
||||
ws.doc_created_ms
|
||||
.insert("doc-arch".into(), 1_763_712_000_000);
|
||||
if let Some(doc) = ws.doc_mut("doc-arch") {
|
||||
doc.updated_at_ms = 1_764_317_400_000;
|
||||
}
|
||||
s.open_sheet(MobileSheet::DocInfo, 0.0);
|
||||
s.settle_animations(500.0);
|
||||
}
|
||||
|
||||
fn open_journal_strip(s: &mut MobileAppState) {
|
||||
s.open_doc("doc-journal", Origin::Journal);
|
||||
}
|
||||
|
||||
fn open_filtered_drawer(s: &mut MobileAppState) {
|
||||
open_phone_drawer(s);
|
||||
s.set_drawer_filter("Sync");
|
||||
}
|
||||
|
||||
fn open_tablet_drawer(s: &mut MobileAppState) {
|
||||
s.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||||
s.open_sheet(MobileSheet::WorkspaceDrawer, 0.0);
|
||||
|
||||
@@ -31,9 +31,9 @@ pub use a11y::{
|
||||
};
|
||||
pub use showcase::seed_showcase_state;
|
||||
pub use state::{
|
||||
BackOutcome, MobileAppState, MobileBackCoordinator, MobileCollection, MobileDocBlock,
|
||||
MobileDocRecord, MobileRoute, MobileSheet, MobileTab, SettingRowInteraction, SettingsGroupId,
|
||||
SettingsState, ThemePreference, WorkStats, WorkspaceData, WorkspaceSummary,
|
||||
BackOutcome, ExperimentalFlag, MobileAppState, MobileBackCoordinator, MobileCollection,
|
||||
MobileDocBlock, MobileDocRecord, MobileRoute, MobileSheet, MobileTab, SettingRowInteraction,
|
||||
SettingsGroupId, SettingsState, ThemePreference, WorkStats, WorkspaceData, WorkspaceSummary,
|
||||
};
|
||||
pub use state_ops::{decode_scoped_doc_target, encode_scoped_doc_target};
|
||||
pub use strings::{MobileLocale, MobileStrings};
|
||||
|
||||
@@ -369,6 +369,38 @@ impl MobileShellView {
|
||||
self.state.set_doc_primary_mode_scoped(ws_id, doc_id, mode)
|
||||
}
|
||||
|
||||
/// Single authoritative UI entry point for adding a workspace tag to a document, or removing
|
||||
/// it when the document has it.
|
||||
pub fn toggle_doc_tag_action(
|
||||
&mut self,
|
||||
ws_id: &str,
|
||||
doc_id: &str,
|
||||
tag_id: &str,
|
||||
now_ms: f64,
|
||||
) -> bool {
|
||||
let Some(tags) = self.state.toggled_doc_tags(doc_id, tag_id) else {
|
||||
return false;
|
||||
};
|
||||
if let Some(shared) = &self.workspace_bridge {
|
||||
let mut bridge = shared.lock().unwrap_or_else(|e| e.into_inner());
|
||||
return match bridge.set_doc_tags(
|
||||
&mut self.state,
|
||||
ws_id,
|
||||
doc_id,
|
||||
tags,
|
||||
now_ms.max(1.0) as i64,
|
||||
) {
|
||||
Ok(changed) => changed,
|
||||
Err(_) => {
|
||||
self.state
|
||||
.set_sync_status(affine_client::WorkspaceSyncStatus::Offline);
|
||||
false
|
||||
}
|
||||
};
|
||||
}
|
||||
self.state.set_doc_tags_scoped(ws_id, doc_id, tags)
|
||||
}
|
||||
|
||||
/// Single authoritative UI entry point for removing a document's journal date.
|
||||
pub fn remove_journal_date_action(&mut self, ws_id: &str, doc_id: &str, now_ms: f64) -> bool {
|
||||
if let Some(shared) = &self.workspace_bridge {
|
||||
@@ -458,6 +490,23 @@ impl MobileShellView {
|
||||
self.state.close_sheet(now_ms);
|
||||
Some(self.remove_journal_date_action(&ws_id, &doc_id, now_ms))
|
||||
}
|
||||
_ if node_id.starts_with("mobile.sheet.doc_info.tag.")
|
||||
&& self.state.active_sheet == crate::state::MobileSheet::DocInfo =>
|
||||
{
|
||||
let tag_id = node_id.strip_prefix("mobile.sheet.doc_info.tag.")?;
|
||||
if !self
|
||||
.state
|
||||
.active_workspace()
|
||||
.tags
|
||||
.iter()
|
||||
.any(|(id, _)| id == tag_id)
|
||||
{
|
||||
return Some(false);
|
||||
}
|
||||
let ws_id = self.state.active_workspace_id().to_string();
|
||||
let doc_id = self.state.page_doc_id()?.to_string();
|
||||
Some(self.toggle_doc_tag_action(&ws_id, &doc_id, tag_id, now_ms))
|
||||
}
|
||||
_ if node_id.starts_with("app.sheet.trash_confirm.")
|
||||
&& self.state.active_sheet == crate::state::MobileSheet::ConfirmTrashDoc =>
|
||||
{
|
||||
|
||||
@@ -249,6 +249,7 @@ fn build_primary_workspace(locale: MobileLocale, today_date: &str) -> WorkspaceD
|
||||
sync_status: WorkspaceSyncStatus::Synced,
|
||||
collapsed_folders: BTreeSet::new(),
|
||||
doc_crdt_updates: std::collections::BTreeMap::new(),
|
||||
doc_created_ms: std::collections::BTreeMap::new(),
|
||||
revisions: Default::default(),
|
||||
derived: Default::default(),
|
||||
}
|
||||
@@ -363,6 +364,7 @@ fn build_personal_workspace(locale: MobileLocale) -> WorkspaceData {
|
||||
sync_status: WorkspaceSyncStatus::Offline,
|
||||
collapsed_folders: BTreeSet::new(),
|
||||
doc_crdt_updates: std::collections::BTreeMap::new(),
|
||||
doc_created_ms: std::collections::BTreeMap::new(),
|
||||
revisions: Default::default(),
|
||||
derived: Default::default(),
|
||||
}
|
||||
@@ -381,14 +383,13 @@ pub fn seed_showcase_state(
|
||||
let mut settings = SettingsState::default();
|
||||
settings.account_email = "lin@example.com".to_string();
|
||||
settings.account_plan = "Pro Cloud".to_string();
|
||||
settings.cache_size_mb = 42;
|
||||
settings.locale = locale;
|
||||
settings.theme_preference = match theme {
|
||||
ThemeMode::Light => ThemePreference::Light,
|
||||
ThemeMode::Dark => ThemePreference::Dark,
|
||||
};
|
||||
|
||||
MobileAppState {
|
||||
let mut state = MobileAppState {
|
||||
workspace_store: vec![primary, personal],
|
||||
active_workspace_idx: 0,
|
||||
active_tab: MobileTab::Home,
|
||||
@@ -416,13 +417,21 @@ pub fn seed_showcase_state(
|
||||
MobileLocale::Ar => "المزامنة".into(),
|
||||
},
|
||||
search_selection: 0..0,
|
||||
search_reversed: false,
|
||||
search_preedit: None,
|
||||
search_engine: WeightedSearchEngine::default(),
|
||||
settings,
|
||||
system_dark: matches!(theme, ThemeMode::Dark),
|
||||
font_scale: 1.0,
|
||||
drawer_filter: String::new(),
|
||||
drawer_filter_selection: 0..0,
|
||||
drawer_filter_reversed: false,
|
||||
drawer_filter_preedit: None,
|
||||
page_session: Default::default(),
|
||||
sheet_extent: Default::default(),
|
||||
}
|
||||
};
|
||||
// The seeded query reads as typed: the caret sits after it.
|
||||
let end = state.search_query.encode_utf16().count();
|
||||
state.search_selection = end..end;
|
||||
state
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
mod derived;
|
||||
mod page_session;
|
||||
mod text_field;
|
||||
mod workspace;
|
||||
|
||||
use std::ops::Range;
|
||||
@@ -20,11 +21,12 @@ pub use affine_store::directory::DocMode;
|
||||
pub use derived::WorkStats;
|
||||
pub(crate) use derived::cached;
|
||||
pub use page_session::{DocAction, PageSession, TocEntry, VIEW_MODE_SWITCH};
|
||||
pub(crate) use text_field::{CaretMove, utf16_to_byte};
|
||||
pub use workspace::{
|
||||
MobileCollection, MobileDocBlock, MobileDocRecord, WorkspaceData, WorkspaceSummary,
|
||||
};
|
||||
|
||||
use crate::strings::MobileLocale;
|
||||
use crate::strings::{MobileLocale, MobileStrings};
|
||||
|
||||
/// Top-level bottom tab bar slots (4-TabBar).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
@@ -85,6 +87,28 @@ pub enum MobileSheet {
|
||||
Toc,
|
||||
JournalConflicts,
|
||||
JournalConflictOps,
|
||||
Experimental,
|
||||
DocInfo,
|
||||
}
|
||||
|
||||
impl MobileSheet {
|
||||
/// Title of the sheet header and its accessibility dialog.
|
||||
pub const fn title(self, strings: &MobileStrings) -> &'static str {
|
||||
match self {
|
||||
Self::WorkspaceSelector => strings.switch_workspace,
|
||||
Self::WorkspaceDrawer => strings.drawer_title,
|
||||
Self::DocActions => strings.doc_actions_title,
|
||||
Self::LocationAndTrail => strings.location_trail_title,
|
||||
Self::Backlinks => strings.backlinks_label,
|
||||
Self::ConfirmDeleteDoc => strings.confirm_delete_title,
|
||||
Self::ConfirmTrashDoc => strings.confirm_trash_title,
|
||||
Self::Toc => strings.toc_title,
|
||||
Self::JournalConflicts | Self::JournalConflictOps => strings.journal_conflicts,
|
||||
Self::Experimental => strings.experimental_features,
|
||||
Self::DocInfo => strings.view_info,
|
||||
Self::None => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Heights of the open sheet's scroll viewport and content, measured at paint time.
|
||||
@@ -135,12 +159,13 @@ pub enum SettingsGroupId {
|
||||
About,
|
||||
}
|
||||
|
||||
/// Honest interaction kind for each mobile Settings row.
|
||||
/// Honest interaction kind for each mobile Settings row: a read-only value, a preference that
|
||||
/// cycles in place, or a sheet that the row opens.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum SettingRowInteraction {
|
||||
Info,
|
||||
Toggle,
|
||||
Cycle,
|
||||
Sheet(MobileSheet),
|
||||
}
|
||||
|
||||
impl SettingsGroupId {
|
||||
@@ -160,10 +185,22 @@ impl SettingsGroupId {
|
||||
pub const fn interaction(self) -> SettingRowInteraction {
|
||||
match self {
|
||||
Self::Appearance | Self::Language | Self::Editor => SettingRowInteraction::Cycle,
|
||||
Self::SyncOffline | Self::Notifications => SettingRowInteraction::Toggle,
|
||||
Self::Account | Self::Workspace | Self::Storage | Self::Experimental | Self::About => {
|
||||
SettingRowInteraction::Info
|
||||
}
|
||||
Self::Workspace => SettingRowInteraction::Sheet(MobileSheet::WorkspaceSelector),
|
||||
Self::Experimental => SettingRowInteraction::Sheet(MobileSheet::Experimental),
|
||||
Self::Account
|
||||
| Self::SyncOffline
|
||||
| Self::Storage
|
||||
| Self::Notifications
|
||||
| Self::About => SettingRowInteraction::Info,
|
||||
}
|
||||
}
|
||||
|
||||
/// Accessibility and snapshot ID of the row: by position for a read-only row, by key for a
|
||||
/// row that reacts to a tap.
|
||||
pub fn a11y_id(self) -> String {
|
||||
match self.interaction() {
|
||||
SettingRowInteraction::Info => format!("mobile.settings.group.{}", self as usize),
|
||||
_ => format!("mobile.settings.row.{}", self.a11y_key()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +220,40 @@ impl SettingsGroupId {
|
||||
}
|
||||
}
|
||||
|
||||
/// Experimental features of the `Settings -> Experimental` sheet: the `0.27.5` feature flags
|
||||
/// that mobile can configure and this shell implements. `enable_editor_rtl` is never one.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum ExperimentalFlag {
|
||||
/// `enable_mobile_edgeless_editing`: Edgeless mode accepts edits on writable documents.
|
||||
MobileEdgelessEditing,
|
||||
}
|
||||
|
||||
impl ExperimentalFlag {
|
||||
pub const ALL: [Self; 1] = [Self::MobileEdgelessEditing];
|
||||
|
||||
pub const fn key(self) -> &'static str {
|
||||
match self {
|
||||
Self::MobileEdgelessEditing => "enable_mobile_edgeless_editing",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn a11y_id(self) -> String {
|
||||
format!("mobile.sheet.experimental.{}", self.key())
|
||||
}
|
||||
|
||||
pub const fn name(self, strings: &MobileStrings) -> &'static str {
|
||||
match self {
|
||||
Self::MobileEdgelessEditing => strings.edgeless_editing_name,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn description(self, strings: &MobileStrings) -> &'static str {
|
||||
match self {
|
||||
Self::MobileEdgelessEditing => strings.edgeless_editing_description,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Full 10-group mobile settings model.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct SettingsState {
|
||||
@@ -191,14 +262,26 @@ pub struct SettingsState {
|
||||
pub theme_preference: ThemePreference,
|
||||
pub locale: MobileLocale,
|
||||
pub editor_font_scale_pct: u16,
|
||||
pub spell_check: bool,
|
||||
pub offline_sync_enabled: bool,
|
||||
pub cache_size_mb: u32,
|
||||
pub push_notifications: bool,
|
||||
pub experimental_flags: Vec<(&'static str, bool)>,
|
||||
pub enable_mobile_edgeless_editing: bool,
|
||||
pub app_version: &'static str,
|
||||
}
|
||||
|
||||
impl SettingsState {
|
||||
pub const fn flag(&self, flag: ExperimentalFlag) -> bool {
|
||||
match flag {
|
||||
ExperimentalFlag::MobileEdgelessEditing => self.enable_mobile_edgeless_editing,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_flag(&mut self, flag: ExperimentalFlag, enabled: bool) {
|
||||
match flag {
|
||||
ExperimentalFlag::MobileEdgelessEditing => {
|
||||
self.enable_mobile_edgeless_editing = enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SettingsState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -207,15 +290,7 @@ impl Default for SettingsState {
|
||||
theme_preference: ThemePreference::Light,
|
||||
locale: MobileLocale::En,
|
||||
editor_font_scale_pct: 100,
|
||||
spell_check: true,
|
||||
offline_sync_enabled: true,
|
||||
cache_size_mb: 0,
|
||||
push_notifications: true,
|
||||
// Controlled difference #5: `enable_editor_rtl` is NEVER exposed here.
|
||||
experimental_flags: vec![
|
||||
("enable_mobile_keyboard_toolbar", true),
|
||||
("enable_pdf_embed_preview", true),
|
||||
],
|
||||
enable_mobile_edgeless_editing: false,
|
||||
app_version: "0.27.5",
|
||||
}
|
||||
}
|
||||
@@ -289,12 +364,16 @@ pub struct MobileAppState {
|
||||
pub selected_journal_date: String,
|
||||
pub search_query: String,
|
||||
pub search_selection: Range<usize>,
|
||||
pub search_reversed: bool,
|
||||
pub search_preedit: Option<Range<usize>>,
|
||||
pub search_engine: WeightedSearchEngine,
|
||||
pub settings: SettingsState,
|
||||
pub system_dark: bool,
|
||||
pub font_scale: f32,
|
||||
pub drawer_filter: String,
|
||||
pub drawer_filter_selection: Range<usize>,
|
||||
pub drawer_filter_reversed: bool,
|
||||
pub drawer_filter_preedit: Option<Range<usize>>,
|
||||
pub page_session: PageSession,
|
||||
}
|
||||
|
||||
@@ -461,6 +540,10 @@ impl MobileAppState {
|
||||
/// Update the live document filter query inside the workspace drawer.
|
||||
pub fn set_drawer_filter(&mut self, query: impl Into<String>) {
|
||||
self.drawer_filter = query.into();
|
||||
let end = self.drawer_filter.encode_utf16().count();
|
||||
self.drawer_filter_selection = end..end;
|
||||
self.drawer_filter_reversed = false;
|
||||
self.drawer_filter_preedit = None;
|
||||
}
|
||||
|
||||
/// Update the active workspace's live sync status indicator.
|
||||
@@ -681,11 +764,78 @@ mod tests {
|
||||
assert_eq!(settings.app_version, "0.27.5");
|
||||
assert!(settings.account_email.is_empty());
|
||||
assert_eq!(settings.account_plan, "Free");
|
||||
assert!(!settings.enable_mobile_edgeless_editing);
|
||||
assert!(
|
||||
!settings
|
||||
.experimental_flags
|
||||
ExperimentalFlag::ALL
|
||||
.iter()
|
||||
.any(|(k, _)| *k == "enable_editor_rtl")
|
||||
.all(|flag| flag.key() != "enable_editor_rtl" && !settings.flag(*flag))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_rows_show_honest_values_and_open_their_sheets() {
|
||||
use affine_client::WorkspaceSyncStatus;
|
||||
|
||||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||||
state.open_settings();
|
||||
let rows: [(SettingsGroupId, &str, &str, Option<MobileSheet>); 5] = [
|
||||
(
|
||||
SettingsGroupId::Workspace,
|
||||
"mobile.settings.row.workspace",
|
||||
"AFFiNE Core",
|
||||
Some(MobileSheet::WorkspaceSelector),
|
||||
),
|
||||
(
|
||||
SettingsGroupId::SyncOffline,
|
||||
"mobile.settings.group.5",
|
||||
"Synced",
|
||||
None,
|
||||
),
|
||||
(
|
||||
SettingsGroupId::Storage,
|
||||
"mobile.settings.group.6",
|
||||
"Cloud",
|
||||
None,
|
||||
),
|
||||
(
|
||||
SettingsGroupId::Notifications,
|
||||
"mobile.settings.group.7",
|
||||
"Off",
|
||||
None,
|
||||
),
|
||||
(
|
||||
SettingsGroupId::Experimental,
|
||||
"mobile.settings.row.experimental",
|
||||
"0 of 1 on",
|
||||
Some(MobileSheet::Experimental),
|
||||
),
|
||||
];
|
||||
for (group, id, value, sheet) in rows {
|
||||
assert_eq!(
|
||||
(
|
||||
group.a11y_id().as_str(),
|
||||
state.setting_value(group).as_str()
|
||||
),
|
||||
(id, value)
|
||||
);
|
||||
assert_eq!(state.activate_setting(group, 10.0), sheet.is_some(), "{id}");
|
||||
assert_eq!(
|
||||
state.active_sheet,
|
||||
sheet.unwrap_or(MobileSheet::None),
|
||||
"{id}"
|
||||
);
|
||||
assert_eq!(state.sheet_trigger_a11y_id.as_deref(), sheet.map(|_| id));
|
||||
state.close_sheet(20.0);
|
||||
}
|
||||
state.set_sync_status(WorkspaceSyncStatus::Syncing { pending_updates: 3 });
|
||||
assert_eq!(
|
||||
state.setting_value(SettingsGroupId::SyncOffline),
|
||||
"Syncing (3)"
|
||||
);
|
||||
state.toggle_experimental_flag(ExperimentalFlag::MobileEdgelessEditing);
|
||||
assert_eq!(
|
||||
state.setting_value(SettingsGroupId::Experimental),
|
||||
"1 of 1 on"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
//! Editor session state of the open mobile `Page`: the current view mode, the `Read-only`
|
||||
//! toggle, the table of contents, and same-day journal conflicts.
|
||||
//! toggle, the table of contents, the journal week strip, document info, and same-day journal
|
||||
//! conflicts.
|
||||
|
||||
use affine_client::{NavTarget, Origin};
|
||||
use affine_store::directory::DocMode;
|
||||
|
||||
use super::{MobileAppState, MobileDocRecord, MobileRoute, MobileSheet};
|
||||
use super::{MobileAppState, MobileDocRecord, MobileRoute, MobileSheet, MobileTab};
|
||||
use crate::strings::MobileStrings;
|
||||
|
||||
/// One row of the `Table of contents` sheet.
|
||||
@@ -29,6 +31,7 @@ pub enum DocAction {
|
||||
Favorite {
|
||||
favorited: bool,
|
||||
},
|
||||
ViewInfo,
|
||||
LocationTrail,
|
||||
Toc,
|
||||
JournalConflicts,
|
||||
@@ -40,6 +43,7 @@ impl DocAction {
|
||||
match self {
|
||||
Self::DefaultMode(_) => "mobile.sheet.doc_action.default_mode",
|
||||
Self::Favorite { .. } => "mobile.sheet.doc_action.favorite",
|
||||
Self::ViewInfo => "mobile.sheet.doc_action.view_info",
|
||||
Self::LocationTrail => "mobile.sheet.doc_action.location_trail",
|
||||
Self::Toc => "mobile.sheet.doc_action.toc",
|
||||
Self::JournalConflicts => "mobile.sheet.doc_action.journal_conflicts",
|
||||
@@ -53,6 +57,7 @@ impl DocAction {
|
||||
Self::DefaultMode(DocMode::Page) => strings.default_to_page,
|
||||
Self::Favorite { favorited: true } => strings.remove_from_favorites,
|
||||
Self::Favorite { favorited: false } => strings.add_to_favorites,
|
||||
Self::ViewInfo => strings.view_info,
|
||||
Self::LocationTrail => strings.location_trail_title,
|
||||
Self::Toc => strings.view_toc,
|
||||
Self::JournalConflicts => strings.journal_conflicts,
|
||||
@@ -94,6 +99,9 @@ pub struct PageSession {
|
||||
pending_reveal: Option<Option<String>>,
|
||||
/// Journal whose conflict operations the `JournalConflictOps` sheet shows.
|
||||
conflict_target: Option<String>,
|
||||
/// `(doc, date)`: a date of the week the journal strip of the doc shows, when the strip
|
||||
/// moved away from the week of the journal date.
|
||||
journal_week: Option<(String, String)>,
|
||||
}
|
||||
|
||||
impl PageSession {
|
||||
@@ -131,10 +139,12 @@ impl MobileAppState {
|
||||
}
|
||||
|
||||
/// Whether the header shows the `Read-only` / `Editing` toggle: an untrashed document in Page
|
||||
/// mode (Edgeless stays read-only on mobile).
|
||||
/// mode, or in Edgeless mode with `enable_mobile_edgeless_editing` (Edgeless is read-only
|
||||
/// on mobile without it).
|
||||
pub fn page_toggles_readonly(&self, doc_id: &str) -> bool {
|
||||
self.doc_by_id(doc_id).is_some_and(|d| !d.trashed)
|
||||
&& self.page_view_mode(doc_id) == DocMode::Page
|
||||
&& (self.page_view_mode(doc_id) == DocMode::Page
|
||||
|| self.settings.enable_mobile_edgeless_editing)
|
||||
}
|
||||
|
||||
/// Whether the editor gates Page-mode edits of `doc_id`.
|
||||
@@ -193,6 +203,7 @@ impl MobileAppState {
|
||||
DocAction::Favorite {
|
||||
favorited: doc.is_favorite,
|
||||
},
|
||||
DocAction::ViewInfo,
|
||||
DocAction::LocationTrail,
|
||||
DocAction::Toc,
|
||||
];
|
||||
@@ -307,6 +318,114 @@ impl MobileAppState {
|
||||
pub(crate) fn take_toc_reveal(&mut self) -> Option<Option<String>> {
|
||||
self.page_session.pending_reveal.take()
|
||||
}
|
||||
|
||||
/// A date of the week that the journal strip of `doc_id` shows, or `None` when the document
|
||||
/// is no journal.
|
||||
pub fn journal_strip_date(&self, doc_id: &str) -> Option<String> {
|
||||
let date = self.doc_by_id(doc_id)?.journal_date.clone()?;
|
||||
Some(match &self.page_session.journal_week {
|
||||
Some((id, week)) if id == doc_id => week.clone(),
|
||||
_ => date,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the journal strip of `doc_id` shows `Today`: the journal is of another day, or
|
||||
/// the strip shows a week without today.
|
||||
pub fn journal_strip_shows_today(&self, doc_id: &str) -> bool {
|
||||
let Some(week_date) = self.journal_strip_date(doc_id) else {
|
||||
return false;
|
||||
};
|
||||
let today = self.today_date.as_str();
|
||||
self.doc_by_id(doc_id)
|
||||
.is_some_and(|d| d.journal_date.as_deref() != Some(today))
|
||||
|| !crate::views::week_days_for_date(&week_date)
|
||||
.iter()
|
||||
.any(|(_, _, date)| date == today)
|
||||
}
|
||||
|
||||
/// Move the journal strip of the open journal by `weeks` weeks without opening a journal.
|
||||
pub fn shift_journal_strip(&mut self, weeks: i64) -> bool {
|
||||
let Some(doc_id) = self.page_doc_id().map(str::to_string) else {
|
||||
return false;
|
||||
};
|
||||
let Some(date) = self.journal_strip_date(&doc_id) else {
|
||||
return false;
|
||||
};
|
||||
let week = crate::views::shift_iso_date(&date, weeks * 7);
|
||||
self.page_session.journal_week = Some((doc_id, week));
|
||||
true
|
||||
}
|
||||
|
||||
/// Show the journal of `date` in place of the open page, as the `0.27.5` journal date
|
||||
/// picker does: the first journal of that date replaces the current history entry, and a
|
||||
/// date without a journal opens the `Journals` tab on that date.
|
||||
pub fn open_journal_date(&mut self, date: &str, now_ms: f64) -> bool {
|
||||
let Some(journal_id) = self.journals_on(date).next().map(|d| d.id.clone()) else {
|
||||
self.switch_tab(MobileTab::Journals, now_ms);
|
||||
self.select_journal_date(date);
|
||||
return true;
|
||||
};
|
||||
if self.page_doc_id() == Some(journal_id.as_str()) {
|
||||
// The open journal stays; only the strip returns to its week.
|
||||
return self.page_session.journal_week.take().is_some();
|
||||
}
|
||||
self.page_session.journal_week = None;
|
||||
self.page_scroll_y = 0.0;
|
||||
let ws = self.active_workspace_mut();
|
||||
let scope = ws.scope.clone();
|
||||
ws.history
|
||||
.replace_current(scope, NavTarget::Doc(journal_id), Origin::Journal, None);
|
||||
self.sync_route_from_history();
|
||||
true
|
||||
}
|
||||
|
||||
/// Whether an untrashed journal of the active workspace has the journal date `date`.
|
||||
pub fn has_journal_on(&self, date: &str) -> bool {
|
||||
self.journals_on(date).next().is_some()
|
||||
}
|
||||
|
||||
/// Distinct untrashed documents that `doc_id` links to.
|
||||
pub fn outgoing_link_count(&self, doc_id: &str) -> usize {
|
||||
let Some(doc) = self.doc_by_id(doc_id) else {
|
||||
return 0;
|
||||
};
|
||||
let mut targets: Vec<&str> = doc
|
||||
.outgoing_edges
|
||||
.iter()
|
||||
.map(|e| e.target_doc_id.as_str())
|
||||
.filter(|id| *id != doc_id && self.doc_by_id(id).is_some_and(|d| !d.trashed))
|
||||
.collect();
|
||||
targets.sort_unstable();
|
||||
targets.dedup();
|
||||
targets.len()
|
||||
}
|
||||
|
||||
/// Set the tag IDs of an untrashed document of the active workspace.
|
||||
pub fn set_doc_tags_scoped(&mut self, ws_id: &str, doc_id: &str, tags: Vec<String>) -> bool {
|
||||
let ws = self.active_workspace_mut();
|
||||
if ws.scope.workspace_id != ws_id
|
||||
|| !ws.doc(doc_id).is_some_and(|d| !d.trashed && d.tags != tags)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if let Some(doc) = ws.doc_mut(doc_id) {
|
||||
doc.tags = tags;
|
||||
doc.clock += 1;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Tag IDs of `doc_id` with `tag_id` added, or removed when the document has it.
|
||||
pub fn toggled_doc_tags(&self, doc_id: &str, tag_id: &str) -> Option<Vec<String>> {
|
||||
let doc = self.doc_by_id(doc_id)?;
|
||||
let mut tags = doc.tags.clone();
|
||||
if let Some(pos) = tags.iter().position(|t| t == tag_id) {
|
||||
tags.remove(pos);
|
||||
} else {
|
||||
tags.push(tag_id.to_string());
|
||||
}
|
||||
Some(tags)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -318,7 +437,7 @@ mod tests {
|
||||
use crate::{MobileLocale, showcase::seed_showcase_state};
|
||||
|
||||
#[test]
|
||||
fn view_mode_primary_mode_and_readonly_toggle_follow_the_open_doc() {
|
||||
fn view_mode_primary_mode_and_readonly_toggle_follow_the_open_doc_and_edgeless_flag() {
|
||||
let mut s = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||||
let ws = s.active_workspace_id().to_string();
|
||||
s.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||||
@@ -333,6 +452,10 @@ mod tests {
|
||||
assert_eq!(s.page_view_mode("doc-arch"), DocMode::Edgeless);
|
||||
assert_eq!(s.doc_by_id("doc-arch").unwrap().primary_mode, DocMode::Page);
|
||||
assert!(!s.page_toggles_readonly("doc-arch") && !s.toggle_page_readonly());
|
||||
s.settings.enable_mobile_edgeless_editing = true;
|
||||
assert!(s.page_toggles_readonly("doc-arch") && s.toggle_page_readonly());
|
||||
assert!(!s.page_readonly("doc-arch"));
|
||||
s.settings.enable_mobile_edgeless_editing = false;
|
||||
|
||||
assert!(s.set_doc_primary_mode_scoped(&ws, "doc-sync", DocMode::Edgeless));
|
||||
assert_eq!(
|
||||
|
||||
@@ -0,0 +1,398 @@
|
||||
//! UTF-16 editing of the single-line text fields of the shell: the `Search` query and the
|
||||
//! `WorkspaceDrawer` filter share one platform input handler and one set of edit rules.
|
||||
|
||||
use std::ops::Range;
|
||||
|
||||
use super::{MobileAppState, MobileRoute, MobileSheet};
|
||||
|
||||
/// Where a caret key moves the caret of a text field.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(crate) enum CaretMove {
|
||||
/// One character back (`Left` in a left-to-right field).
|
||||
Back,
|
||||
/// One character forward.
|
||||
Forward,
|
||||
Start,
|
||||
End,
|
||||
/// Select the whole text.
|
||||
All,
|
||||
}
|
||||
|
||||
/// Mutable view of one text field: its text, UTF-16 selection, and IME preedit range.
|
||||
pub(crate) struct TextFieldMut<'a> {
|
||||
pub text: &'a mut String,
|
||||
pub selection: &'a mut Range<usize>,
|
||||
/// The active end of the selection is its start, and the anchor its end.
|
||||
pub reversed: &'a mut bool,
|
||||
pub preedit: &'a mut Option<Range<usize>>,
|
||||
/// Distance from the start edge of the field to its first character.
|
||||
pub text_inset: f32,
|
||||
}
|
||||
|
||||
impl TextFieldMut<'_> {
|
||||
fn clamp(&self, range: Range<usize>) -> Range<usize> {
|
||||
let total = self.text.encode_utf16().count();
|
||||
let start = range.start.min(total);
|
||||
start..range.end.min(total).max(start)
|
||||
}
|
||||
|
||||
fn bytes(&self, range: &Range<usize>) -> Range<usize> {
|
||||
utf16_to_byte(self.text, range.start)..utf16_to_byte(self.text, range.end)
|
||||
}
|
||||
|
||||
/// The text of `range`, and `range` clamped to the text.
|
||||
pub fn text_for_range(&self, range: Range<usize>) -> (String, Range<usize>) {
|
||||
let range = self.clamp(range);
|
||||
(self.text[self.bytes(&range)].to_string(), range)
|
||||
}
|
||||
|
||||
pub fn selected_range(&self) -> Range<usize> {
|
||||
self.clamp(self.selection.clone())
|
||||
}
|
||||
|
||||
pub fn len_utf16(&self) -> usize {
|
||||
self.text.encode_utf16().count()
|
||||
}
|
||||
|
||||
/// Select `range` with the active end at its end, clamped to the text and widened to whole
|
||||
/// characters.
|
||||
pub fn select(&mut self, range: Range<usize>) {
|
||||
self.select_from(range.start, range.end);
|
||||
}
|
||||
|
||||
/// Select from `anchor` to the active end `head`, clamped and widened as [`Self::select`].
|
||||
fn select_from(&mut self, anchor: usize, head: usize) {
|
||||
let range = self.clamp(anchor.min(head)..anchor.max(head));
|
||||
let start = self.text[..utf16_to_byte(self.text, range.start)]
|
||||
.encode_utf16()
|
||||
.count();
|
||||
let end = self.text[..utf16_to_byte(self.text, range.end)]
|
||||
.encode_utf16()
|
||||
.count();
|
||||
*self.selection = start..end;
|
||||
*self.reversed = head < anchor;
|
||||
*self.preedit = None;
|
||||
}
|
||||
|
||||
/// Move the caret, or with `extend` move the active end of the selection and keep its
|
||||
/// anchor, so the selection shrinks back over the anchor and grows on its other side.
|
||||
pub fn move_caret(&mut self, to: CaretMove, extend: bool) {
|
||||
let selected = self.selected_range();
|
||||
let end = self.len_utf16();
|
||||
let step = |offset: usize, back: bool| {
|
||||
let byte = utf16_to_byte(self.text, offset);
|
||||
let ch = if back {
|
||||
self.text[..byte].chars().next_back()
|
||||
} else {
|
||||
self.text[byte..].chars().next()
|
||||
};
|
||||
let width = ch.map_or(0, char::len_utf16);
|
||||
if back {
|
||||
offset.saturating_sub(width)
|
||||
} else {
|
||||
offset + width
|
||||
}
|
||||
};
|
||||
let (anchor, head) = if *self.reversed {
|
||||
(selected.end, selected.start)
|
||||
} else {
|
||||
(selected.start, selected.end)
|
||||
};
|
||||
let (anchor, head) = match (to, extend) {
|
||||
(CaretMove::All, _) => (0, end),
|
||||
(CaretMove::Back, true) => (anchor, step(head, true)),
|
||||
(CaretMove::Forward, true) => (anchor, step(head, false)),
|
||||
(CaretMove::Start, true) => (anchor, 0),
|
||||
(CaretMove::End, true) => (anchor, end),
|
||||
(CaretMove::Back, false) if !selected.is_empty() => (selected.start, selected.start),
|
||||
(CaretMove::Forward, false) if !selected.is_empty() => (selected.end, selected.end),
|
||||
(CaretMove::Back, false) => {
|
||||
let at = step(selected.start, true);
|
||||
(at, at)
|
||||
}
|
||||
(CaretMove::Forward, false) => {
|
||||
let at = step(selected.end, false);
|
||||
(at, at)
|
||||
}
|
||||
(CaretMove::Start, false) => (0, 0),
|
||||
(CaretMove::End, false) => (end, end),
|
||||
};
|
||||
self.select_from(anchor, head);
|
||||
}
|
||||
|
||||
/// Commit `new_text` over `range`, else over the preedit, else over the selection.
|
||||
pub fn replace(&mut self, range: Option<Range<usize>>, new_text: &str) {
|
||||
let target = range
|
||||
.or_else(|| self.preedit.take())
|
||||
.unwrap_or_else(|| self.selection.clone());
|
||||
let target = self.clamp(target);
|
||||
let bytes = self.bytes(&target);
|
||||
self.text.replace_range(bytes, new_text);
|
||||
let caret = target.start + new_text.encode_utf16().count();
|
||||
*self.selection = caret..caret;
|
||||
*self.reversed = false;
|
||||
*self.preedit = None;
|
||||
}
|
||||
|
||||
/// Show the composition `new_text` over `range`, else over the preedit, else over the
|
||||
/// selection, and select `new_selected` inside it.
|
||||
pub fn replace_and_mark(
|
||||
&mut self,
|
||||
range: Option<Range<usize>>,
|
||||
new_text: &str,
|
||||
new_selected: Option<Range<usize>>,
|
||||
) {
|
||||
let target = range
|
||||
.or_else(|| self.preedit.clone())
|
||||
.unwrap_or_else(|| self.selection.clone());
|
||||
let target = self.clamp(target);
|
||||
let bytes = self.bytes(&target);
|
||||
self.text.replace_range(bytes, new_text);
|
||||
let start = target.start;
|
||||
let end = start + new_text.encode_utf16().count();
|
||||
*self.preedit = (end > start).then_some(start..end);
|
||||
*self.selection = new_selected.map_or(end..end, |r| (start + r.start)..(start + r.end));
|
||||
*self.reversed = false;
|
||||
}
|
||||
|
||||
/// Delete the selection, else the character before (`backward`) or after the caret.
|
||||
pub fn delete(&mut self, backward: bool) {
|
||||
*self.preedit = None;
|
||||
let selected = self.selected_range();
|
||||
let (bytes, caret) = if !selected.is_empty() {
|
||||
(self.bytes(&selected), selected.start)
|
||||
} else if backward {
|
||||
let end = utf16_to_byte(self.text, selected.start);
|
||||
let Some((start, _)) = self.text[..end].char_indices().next_back() else {
|
||||
return;
|
||||
};
|
||||
(start..end, self.text[..start].encode_utf16().count())
|
||||
} else {
|
||||
let start = utf16_to_byte(self.text, selected.start);
|
||||
let Some(ch) = self.text[start..].chars().next() else {
|
||||
return;
|
||||
};
|
||||
(
|
||||
start..start + ch.len_utf8(),
|
||||
self.text[..start].encode_utf16().count(),
|
||||
)
|
||||
};
|
||||
self.text.replace_range(bytes, "");
|
||||
*self.selection = caret..caret;
|
||||
*self.reversed = false;
|
||||
}
|
||||
}
|
||||
|
||||
impl MobileAppState {
|
||||
/// The field that typed text goes to: the drawer filter while the drawer is open, else the
|
||||
/// query of the `Search` route.
|
||||
pub(crate) fn active_text_field(&mut self) -> Option<TextFieldMut<'_>> {
|
||||
if self.active_sheet == MobileSheet::WorkspaceDrawer {
|
||||
return Some(TextFieldMut {
|
||||
text: &mut self.drawer_filter,
|
||||
selection: &mut self.drawer_filter_selection,
|
||||
reversed: &mut self.drawer_filter_reversed,
|
||||
preedit: &mut self.drawer_filter_preedit,
|
||||
text_inset: 35.0,
|
||||
});
|
||||
}
|
||||
(self.route == MobileRoute::Search).then(|| TextFieldMut {
|
||||
text: &mut self.search_query,
|
||||
selection: &mut self.search_selection,
|
||||
reversed: &mut self.search_reversed,
|
||||
preedit: &mut self.search_preedit,
|
||||
text_inset: 36.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a UTF-16 offset to a UTF-8 boundary. Round up inside a surrogate pair.
|
||||
pub(crate) fn utf16_to_byte(text: &str, utf16_offset: usize) -> usize {
|
||||
let mut units = 0usize;
|
||||
for (byte_idx, ch) in text.char_indices() {
|
||||
if units >= utf16_offset {
|
||||
return byte_idx;
|
||||
}
|
||||
units += ch.len_utf16();
|
||||
}
|
||||
text.len()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn field<'a>(
|
||||
text: &'a mut String,
|
||||
selection: &'a mut Range<usize>,
|
||||
reversed: &'a mut bool,
|
||||
preedit: &'a mut Option<Range<usize>>,
|
||||
) -> TextFieldMut<'a> {
|
||||
TextFieldMut {
|
||||
text,
|
||||
selection,
|
||||
reversed,
|
||||
preedit,
|
||||
text_inset: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn utf16_offsets_round_up_inside_surrogate_pairs() {
|
||||
for (text, offsets) in [
|
||||
("A😀B", &[0, 1, 5, 5, 6, 6][..]),
|
||||
("😀", &[0, 4, 4, 4][..]),
|
||||
("é中", &[0, 2, 5, 5][..]),
|
||||
("", &[0, 0][..]),
|
||||
] {
|
||||
for (offset, &expected) in offsets.iter().enumerate() {
|
||||
assert_eq!(
|
||||
utf16_to_byte(text, offset),
|
||||
expected,
|
||||
"{text:?} at {offset}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edits_compose_commit_delete_and_move_the_caret_from_its_anchor_by_utf16_ranges() {
|
||||
enum Edit {
|
||||
Mark(&'static str),
|
||||
Commit(&'static str),
|
||||
Delete(bool),
|
||||
Select(Range<usize>),
|
||||
Move(CaretMove, bool),
|
||||
}
|
||||
let cases: [(&str, &[Edit], &str, Range<usize>, Option<Range<usize>>); 13] = [
|
||||
(
|
||||
"Sync",
|
||||
&[
|
||||
Edit::Select(2..2),
|
||||
Edit::Move(CaretMove::Back, true),
|
||||
Edit::Move(CaretMove::Forward, true),
|
||||
Edit::Commit("X"),
|
||||
],
|
||||
"SyXnc",
|
||||
3..3,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"",
|
||||
&[Edit::Mark("s"), Edit::Mark("sh"), Edit::Commit("书")],
|
||||
"书",
|
||||
1..1,
|
||||
None,
|
||||
),
|
||||
("A😀", &[Edit::Delete(true)], "A", 1..1, None),
|
||||
(
|
||||
"A😀B",
|
||||
&[Edit::Select(1..1), Edit::Delete(false)],
|
||||
"AB",
|
||||
1..1,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"abc",
|
||||
&[Edit::Select(0..2), Edit::Delete(true)],
|
||||
"c",
|
||||
0..0,
|
||||
None,
|
||||
),
|
||||
("x", &[Edit::Mark("中文")], "x中文", 3..3, Some(1..3)),
|
||||
(
|
||||
"Syc",
|
||||
&[Edit::Move(CaretMove::Back, false), Edit::Commit("n")],
|
||||
"Sync",
|
||||
3..3,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"A😀B",
|
||||
&[
|
||||
Edit::Move(CaretMove::Back, false),
|
||||
Edit::Move(CaretMove::Back, true),
|
||||
],
|
||||
"A😀B",
|
||||
1..3,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"abc",
|
||||
&[
|
||||
Edit::Move(CaretMove::Start, false),
|
||||
Edit::Move(CaretMove::Forward, false),
|
||||
Edit::Move(CaretMove::End, true),
|
||||
Edit::Commit("Z"),
|
||||
],
|
||||
"aZ",
|
||||
2..2,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"abc",
|
||||
&[
|
||||
Edit::Select(2..2),
|
||||
Edit::Move(CaretMove::Back, true),
|
||||
Edit::Move(CaretMove::Forward, true),
|
||||
Edit::Commit("X"),
|
||||
],
|
||||
"abXc",
|
||||
3..3,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"abcd",
|
||||
&[
|
||||
Edit::Select(2..2),
|
||||
Edit::Move(CaretMove::Forward, true),
|
||||
Edit::Move(CaretMove::Back, true),
|
||||
Edit::Move(CaretMove::Back, true),
|
||||
Edit::Move(CaretMove::Back, true),
|
||||
Edit::Delete(true),
|
||||
],
|
||||
"cd",
|
||||
0..0,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"abc",
|
||||
&[Edit::Move(CaretMove::All, false), Edit::Commit("x")],
|
||||
"x",
|
||||
1..1,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"abc",
|
||||
&[
|
||||
Edit::Move(CaretMove::All, false),
|
||||
Edit::Move(CaretMove::Back, false),
|
||||
Edit::Move(CaretMove::Forward, false),
|
||||
],
|
||||
"abc",
|
||||
1..1,
|
||||
None,
|
||||
),
|
||||
];
|
||||
for (initial, edits, text, selection, preedit) in cases {
|
||||
let mut t = initial.to_string();
|
||||
let end = t.encode_utf16().count();
|
||||
let (mut sel, mut rev, mut pre) = (end..end, false, None);
|
||||
let mut f = field(&mut t, &mut sel, &mut rev, &mut pre);
|
||||
for edit in edits {
|
||||
match edit {
|
||||
Edit::Mark(s) => f.replace_and_mark(None, s, None),
|
||||
Edit::Commit(s) => f.replace(None, s),
|
||||
Edit::Delete(backward) => f.delete(*backward),
|
||||
Edit::Select(r) => *f.selection = r.clone(),
|
||||
Edit::Move(to, extend) => f.move_caret(*to, *extend),
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
(f.text.as_str(), f.selection.clone(), f.preedit.clone()),
|
||||
(text, selection, preedit),
|
||||
"{initial:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,8 @@ pub struct WorkspaceData {
|
||||
pub collapsed_folders: BTreeSet<String>,
|
||||
/// Authoritative Yjs V1 CRDT state bytes per document id (single persistence/reload source of truth).
|
||||
pub(crate) doc_crdt_updates: BTreeMap<String, Vec<u8>>,
|
||||
/// Creation time in Unix milliseconds per document id, where the workspace records one.
|
||||
pub doc_created_ms: BTreeMap<String, i64>,
|
||||
pub(crate) revisions: DocRevisions,
|
||||
pub(crate) derived: DerivedCache,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Scoped document creation, journal management, trash restore/delete with confirmation,
|
||||
//! settings toggles, and Explorer vertical scroll helpers on [`MobileAppState`].
|
||||
//! Settings rows, and Explorer vertical scroll helpers on [`MobileAppState`].
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
@@ -8,7 +8,10 @@ use affine_store::workspace_db::FolderRow;
|
||||
use blocksuite_playground_doc::fractional_index::generate_key_between;
|
||||
|
||||
use crate::{
|
||||
state::{MobileAppState, MobileDocRecord, MobileSheet, SettingsGroupId, ThemePreference},
|
||||
state::{
|
||||
ExperimentalFlag, MobileAppState, MobileDocRecord, MobileSheet, SettingRowInteraction,
|
||||
SettingsGroupId, ThemePreference,
|
||||
},
|
||||
strings::MobileLocale,
|
||||
};
|
||||
|
||||
@@ -266,6 +269,7 @@ impl MobileAppState {
|
||||
ws.docs_mut().retain(|d| !doc_ids.contains(&d.id));
|
||||
for doc_id in doc_ids {
|
||||
ws.remove_doc_crdt_update(doc_id);
|
||||
ws.doc_created_ms.remove(doc_id);
|
||||
ws.link_graph.replace_edges(doc_id, Vec::new(), u64::MAX);
|
||||
}
|
||||
let rows_before = ws.folder_rows.len();
|
||||
@@ -441,8 +445,9 @@ impl MobileAppState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply an in-place toggle or cycle action for an interactive Settings row.
|
||||
pub fn activate_setting(&mut self, group: SettingsGroupId) -> bool {
|
||||
/// Activate a Settings row: cycle its preference in place, or open its sheet with the row
|
||||
/// as the trigger. Read-only rows do nothing.
|
||||
pub fn activate_setting(&mut self, group: SettingsGroupId, now_ms: f64) -> bool {
|
||||
match group {
|
||||
SettingsGroupId::Appearance => {
|
||||
self.settings.theme_preference = match self.settings.theme_preference {
|
||||
@@ -473,21 +478,57 @@ impl MobileAppState {
|
||||
self.font_scale = f32::from(next_pct) / 100.0;
|
||||
true
|
||||
}
|
||||
SettingsGroupId::SyncOffline => {
|
||||
self.settings.offline_sync_enabled = !self.settings.offline_sync_enabled;
|
||||
let next_status = if self.settings.offline_sync_enabled {
|
||||
affine_client::WorkspaceSyncStatus::Synced
|
||||
} else {
|
||||
affine_client::WorkspaceSyncStatus::Offline
|
||||
};
|
||||
self.set_sync_status(next_status);
|
||||
true
|
||||
}
|
||||
SettingsGroupId::Notifications => {
|
||||
self.settings.push_notifications = !self.settings.push_notifications;
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
_ => match group.interaction() {
|
||||
SettingRowInteraction::Sheet(sheet) => {
|
||||
self.open_sheet_from(sheet, Some(&group.a11y_id()), now_ms);
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Value that the Settings row of `group` shows. Rows without a backing service state what
|
||||
/// the device does instead of a switch that changes nothing.
|
||||
pub fn setting_value(&self, group: SettingsGroupId) -> String {
|
||||
let locale = self.locale();
|
||||
let strings = locale.strings();
|
||||
let ws = self.active_workspace();
|
||||
match group {
|
||||
SettingsGroupId::Account if self.settings.account_email.trim().is_empty() => {
|
||||
strings.sign_in_label.to_string()
|
||||
}
|
||||
SettingsGroupId::Account => self.settings.account_email.clone(),
|
||||
SettingsGroupId::Workspace => ws.summary.name.clone(),
|
||||
SettingsGroupId::Appearance => match self.settings.theme_preference {
|
||||
ThemePreference::Light => strings.theme_light,
|
||||
ThemePreference::Dark => strings.theme_dark,
|
||||
ThemePreference::System => strings.theme_system,
|
||||
}
|
||||
.to_string(),
|
||||
SettingsGroupId::Language => self.settings.locale.display_name().to_string(),
|
||||
SettingsGroupId::Editor => format!("{}%", self.settings.editor_font_scale_pct),
|
||||
SettingsGroupId::SyncOffline => strings.sync_status_label(ws.sync_status),
|
||||
SettingsGroupId::Storage if ws.summary.is_cloud => strings.storage_cloud.to_string(),
|
||||
SettingsGroupId::Storage => strings.storage_local.to_string(),
|
||||
SettingsGroupId::Notifications => strings.toggle_off.to_string(),
|
||||
SettingsGroupId::Experimental => {
|
||||
let enabled = ExperimentalFlag::ALL
|
||||
.iter()
|
||||
.filter(|flag| self.settings.flag(**flag))
|
||||
.count();
|
||||
strings.flags_enabled(locale, enabled, ExperimentalFlag::ALL.len())
|
||||
}
|
||||
SettingsGroupId::About => format!(
|
||||
"{} v{}",
|
||||
strings.about_version_label, self.settings.app_version
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Flip an experimental feature of the `Settings -> Experimental` sheet.
|
||||
pub fn toggle_experimental_flag(&mut self, flag: ExperimentalFlag) {
|
||||
let enabled = !self.settings.flag(flag);
|
||||
self.settings.set_flag(flag, enabled);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Localized UI strings for `en`, `zh-Hans`, and `ar` (RTL) mobile shell views.
|
||||
|
||||
use affine_client::WorkspaceSyncStatus;
|
||||
use ui::Direction;
|
||||
|
||||
/// Supported showcase and audit locales for the mobile shell.
|
||||
@@ -148,6 +149,18 @@ pub struct MobileStrings {
|
||||
pub no_locations_label: &'static str,
|
||||
pub today_btn_label: &'static str,
|
||||
pub sign_in_label: &'static str,
|
||||
pub experimental_features: &'static str,
|
||||
pub edgeless_editing_name: &'static str,
|
||||
pub edgeless_editing_description: &'static str,
|
||||
pub view_info: &'static str,
|
||||
pub doc_info_created: &'static str,
|
||||
pub doc_info_updated: &'static str,
|
||||
pub outgoing_links: &'static str,
|
||||
pub storage_local: &'static str,
|
||||
pub storage_cloud: &'static str,
|
||||
pub clear_label: &'static str,
|
||||
pub prev_week_label: &'static str,
|
||||
pub next_week_label: &'static str,
|
||||
}
|
||||
|
||||
impl MobileStrings {
|
||||
@@ -159,11 +172,34 @@ impl MobileStrings {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flags_count(&self, locale: MobileLocale, count: usize) -> String {
|
||||
pub fn flags_enabled(&self, locale: MobileLocale, enabled: usize, total: usize) -> String {
|
||||
match locale {
|
||||
MobileLocale::En | MobileLocale::RtlFallback => format!("{count} flags"),
|
||||
MobileLocale::ZhHans => format!("{count} 项开关"),
|
||||
MobileLocale::Ar => format!("{count} خيارات"),
|
||||
MobileLocale::En | MobileLocale::RtlFallback => format!("{enabled} of {total} on"),
|
||||
MobileLocale::ZhHans => format!("已开启 {enabled}/{total}"),
|
||||
MobileLocale::Ar => format!("{enabled} من {total} مفعّلة"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Label of a workspace sync status, with the count of local updates still to push.
|
||||
pub fn sync_status_label(&self, status: WorkspaceSyncStatus) -> String {
|
||||
let (label, pending) = match status {
|
||||
WorkspaceSyncStatus::Synced => (self.sync_synced, 0),
|
||||
WorkspaceSyncStatus::Syncing { pending_updates } => {
|
||||
(self.sync_syncing, pending_updates)
|
||||
}
|
||||
WorkspaceSyncStatus::Connecting => (self.sync_connecting, 0),
|
||||
WorkspaceSyncStatus::ReconnectScheduled {
|
||||
pending_updates, ..
|
||||
} => (self.sync_offline, pending_updates),
|
||||
WorkspaceSyncStatus::Offline => (self.sync_offline, 0),
|
||||
WorkspaceSyncStatus::AuthRequired | WorkspaceSyncStatus::PermissionRevoked => {
|
||||
(self.sync_auth_required, 0)
|
||||
}
|
||||
};
|
||||
if pending > 0 {
|
||||
format!("{label} ({pending})")
|
||||
} else {
|
||||
label.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,6 +384,18 @@ const EN_STRINGS: MobileStrings = MobileStrings {
|
||||
no_locations_label: "Not filed in any folder",
|
||||
today_btn_label: "Today",
|
||||
sign_in_label: "Sign in",
|
||||
experimental_features: "Experimental features",
|
||||
edgeless_editing_name: "Enable Edgeless Editing",
|
||||
edgeless_editing_description: "Once enabled, users can edit edgeless canvas.",
|
||||
view_info: "View Info",
|
||||
doc_info_created: "Created",
|
||||
doc_info_updated: "Updated",
|
||||
outgoing_links: "Outgoing links",
|
||||
storage_local: "On this device",
|
||||
storage_cloud: "Cloud",
|
||||
clear_label: "Clear",
|
||||
prev_week_label: "Previous week",
|
||||
next_week_label: "Next week",
|
||||
};
|
||||
|
||||
const ZH_STRINGS: MobileStrings = MobileStrings {
|
||||
@@ -447,6 +495,18 @@ const ZH_STRINGS: MobileStrings = MobileStrings {
|
||||
no_locations_label: "尚未归入文件夹",
|
||||
today_btn_label: "今天",
|
||||
sign_in_label: "登录",
|
||||
experimental_features: "实验性功能",
|
||||
edgeless_editing_name: "启用无界编辑",
|
||||
edgeless_editing_description: "一旦启用,用户就可以编辑无界。",
|
||||
view_info: "查看信息",
|
||||
doc_info_created: "创建",
|
||||
doc_info_updated: "更新",
|
||||
outgoing_links: "外链",
|
||||
storage_local: "本机",
|
||||
storage_cloud: "云端",
|
||||
clear_label: "清除",
|
||||
prev_week_label: "上一周",
|
||||
next_week_label: "下一周",
|
||||
};
|
||||
|
||||
const AR_STRINGS: MobileStrings = MobileStrings {
|
||||
@@ -546,4 +606,16 @@ const AR_STRINGS: MobileStrings = MobileStrings {
|
||||
no_locations_label: "غير مصنف في مجلد",
|
||||
today_btn_label: "اليوم",
|
||||
sign_in_label: "تسجيل الدخول",
|
||||
experimental_features: "الميزات التجريبية",
|
||||
edgeless_editing_name: "تفعيل التحرير بدون حدود",
|
||||
edgeless_editing_description: "بمجرد التفعيل، يمكن للمستخدمين تحرير اللوحة بدون حدود.",
|
||||
view_info: "عرض المعلومات",
|
||||
doc_info_created: "تم الإنشاء",
|
||||
doc_info_updated: "تم التحديث",
|
||||
outgoing_links: "الروابط الصادرة",
|
||||
storage_local: "على هذا الجهاز",
|
||||
storage_cloud: "السحابة",
|
||||
clear_label: "مسح",
|
||||
prev_week_label: "الأسبوع السابق",
|
||||
next_week_label: "الأسبوع التالي",
|
||||
};
|
||||
@@ -0,0 +1,228 @@
|
||||
//! `View Info` sheet body of the page menu, after the `0.27.5` mobile `DocInfoSheet`: the
|
||||
//! creation and update times, the workspace tags that the document can carry, and its link
|
||||
//! counts.
|
||||
|
||||
use ui::{
|
||||
Context, Direction, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement,
|
||||
Styled, div, px, svg,
|
||||
};
|
||||
use ui_kit::LogicalStyled;
|
||||
use ui_tokens::{IconDef, icons};
|
||||
|
||||
use crate::{state::MobileAppState, strings::MobileStrings};
|
||||
|
||||
use super::{
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe, format_utc_ms,
|
||||
row_dir,
|
||||
};
|
||||
|
||||
/// One read-only `(id, icon, label, value)` row of the sheet.
|
||||
pub(crate) type InfoRow = (&'static str, IconDef, &'static str, String);
|
||||
|
||||
/// Time and link rows of the document info of `doc_id`, in display order.
|
||||
pub(crate) fn doc_info_rows(state: &MobileAppState, doc_id: &str) -> (Vec<InfoRow>, Vec<InfoRow>) {
|
||||
let strings = state.locale().strings();
|
||||
let mut times = Vec::new();
|
||||
if let Some(created) = state.active_workspace().doc_created_ms.get(doc_id) {
|
||||
times.push((
|
||||
"mobile.sheet.doc_info.created",
|
||||
icons::DATE_TIME,
|
||||
strings.doc_info_created,
|
||||
format_utc_ms(*created),
|
||||
));
|
||||
}
|
||||
if let Some(doc) = state.doc_by_id(doc_id) {
|
||||
times.push((
|
||||
"mobile.sheet.doc_info.updated",
|
||||
icons::EDIT,
|
||||
strings.doc_info_updated,
|
||||
format_utc_ms(doc.updated_at_ms),
|
||||
));
|
||||
}
|
||||
let links = vec![
|
||||
(
|
||||
"mobile.sheet.doc_info.backlinks",
|
||||
icons::LINKED_PAGE,
|
||||
strings.backlinks_label,
|
||||
state.backlinks_for(doc_id).items.len().to_string(),
|
||||
),
|
||||
(
|
||||
"mobile.sheet.doc_info.outgoing_links",
|
||||
icons::LINK,
|
||||
strings.outgoing_links,
|
||||
state.outgoing_link_count(doc_id).to_string(),
|
||||
),
|
||||
];
|
||||
(times, links)
|
||||
}
|
||||
|
||||
fn group_box(palette: MobilePalette) -> ui::Div {
|
||||
div()
|
||||
.w_full()
|
||||
.rounded(px(22.0))
|
||||
.bg(palette.bg_canvas)
|
||||
.border_1()
|
||||
.border_color(palette.border)
|
||||
.flex()
|
||||
.flex_col()
|
||||
.overflow_hidden()
|
||||
}
|
||||
|
||||
fn info_row(
|
||||
id: String,
|
||||
(icon, label, value): (IconDef, &str, String),
|
||||
trailing_accent: bool,
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
a11y_bounds: &A11yBoundsMap,
|
||||
) -> ui::Stateful<ui::Div> {
|
||||
row_dir(dir)
|
||||
.id(id.clone())
|
||||
.snapshot(id.clone(), Some("mobile.sheet.panel"))
|
||||
.relative()
|
||||
.w_full()
|
||||
.h(px(44.0))
|
||||
.flex_shrink(0.0)
|
||||
.ps(px(14.0), dir)
|
||||
.pe(px(14.0), dir)
|
||||
.gap(px(10.0))
|
||||
.child(a11y_bounds_probe(id, a11y_bounds.clone()))
|
||||
.child(
|
||||
svg()
|
||||
.data(icon.svg.as_bytes())
|
||||
.w(px(18.0))
|
||||
.h(px(18.0))
|
||||
.flex_shrink(0.0)
|
||||
.text_color(palette.text_secondary),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_primary)
|
||||
.align_start_for(dir)
|
||||
.overflow_hidden()
|
||||
.child(label.to_string()),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_shrink(0.0)
|
||||
.text_size(px(13.0))
|
||||
.text_color(if trailing_accent {
|
||||
palette.accent
|
||||
} else {
|
||||
palette.text_secondary
|
||||
})
|
||||
.child(value),
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn render_doc_info_content(
|
||||
state: &MobileAppState,
|
||||
compact: bool,
|
||||
accepts_input: bool,
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
strings: &'static MobileStrings,
|
||||
a11y_bounds: &A11yBoundsMap,
|
||||
cx: &mut Context<MobileShellView>,
|
||||
) -> ui::AnyElement {
|
||||
let ws_id = state.active_workspace_id().to_string();
|
||||
let doc_id = state.page_doc_id().unwrap_or_default().to_string();
|
||||
let doc_tags = state
|
||||
.doc_by_id(&doc_id)
|
||||
.map(|d| d.tags.clone())
|
||||
.unwrap_or_default();
|
||||
let (times, links) = doc_info_rows(state, &doc_id);
|
||||
let rows_box = |rows: Vec<InfoRow>| {
|
||||
let mut list = group_box(palette);
|
||||
for (idx, (id, icon, label, value)) in rows.into_iter().enumerate() {
|
||||
let mut row = info_row(
|
||||
id.to_string(),
|
||||
(icon, label, value),
|
||||
false,
|
||||
palette,
|
||||
dir,
|
||||
a11y_bounds,
|
||||
);
|
||||
if idx > 0 {
|
||||
row = row.border_t(px(1.0)).border_color(palette.border);
|
||||
}
|
||||
list = list.child(row);
|
||||
}
|
||||
list
|
||||
};
|
||||
|
||||
let mut tags_box = group_box(palette);
|
||||
let tags = &state.active_workspace().tags;
|
||||
if tags.is_empty() {
|
||||
tags_box = tags_box.child(
|
||||
div()
|
||||
.w_full()
|
||||
.p(px(14.0))
|
||||
.text_size(px(13.0))
|
||||
.text_color(palette.text_secondary)
|
||||
.align_start_for(dir)
|
||||
.child(strings.empty_list_label),
|
||||
);
|
||||
}
|
||||
for (idx, (tag_id, name)) in tags.iter().enumerate() {
|
||||
let on = doc_tags.contains(tag_id);
|
||||
let mut row = info_row(
|
||||
doc_info_tag_id(tag_id),
|
||||
(icons::TAG, name, if on { "✓" } else { "" }.to_string()),
|
||||
true,
|
||||
palette,
|
||||
dir,
|
||||
a11y_bounds,
|
||||
);
|
||||
if idx > 0 {
|
||||
row = row.border_t(px(1.0)).border_color(palette.border);
|
||||
}
|
||||
if accepts_input {
|
||||
let (ws_id, doc_id, tag_id) = (ws_id.clone(), doc_id.clone(), tag_id.clone());
|
||||
row = row.on_click(cx.listener(move |this, _, _, cx| {
|
||||
let t = this.now_ms(cx);
|
||||
this.toggle_doc_tag_action(&ws_id, &doc_id, &tag_id, t);
|
||||
cx.notify();
|
||||
}));
|
||||
}
|
||||
tags_box = tags_box.child(row);
|
||||
}
|
||||
|
||||
let heading = |text: &'static str| {
|
||||
div()
|
||||
.w_full()
|
||||
.ps(px(4.0), dir)
|
||||
.text_size(px(12.0))
|
||||
.text_color(palette.text_secondary)
|
||||
.align_start_for(dir)
|
||||
.child(text)
|
||||
};
|
||||
let column = || div().flex_1().min_w(px(0.0)).flex().flex_col().gap(px(8.0));
|
||||
let tags_column = column().child(heading(strings.tags)).child(tags_box);
|
||||
let info_column = column().child(rows_box(times));
|
||||
if compact {
|
||||
// A short landscape sheet shows the tags beside the times and links.
|
||||
row_dir(dir)
|
||||
.w_full()
|
||||
.gap(px(10.0))
|
||||
.items_start()
|
||||
.child(info_column.child(rows_box(links)))
|
||||
.child(tags_column)
|
||||
.into_any_element()
|
||||
} else {
|
||||
info_column
|
||||
.w_full()
|
||||
.child(tags_column)
|
||||
.child(rows_box(links))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
/// Accessibility ID of the tag row of `tag_id` in the `View Info` sheet.
|
||||
pub(crate) fn doc_info_tag_id(tag_id: &str) -> String {
|
||||
format!("mobile.sheet.doc_info.tag.{tag_id}")
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
//! iOS 27 multi-document workspace drawer (`pane_corner = 38pt`, fixed short title,
|
||||
//! `44×44pt` concentric circular liquid-glass close control, workspace identity + sync card,
|
||||
//! live document filter, Favorites, Recent Documents, All Docs list, and New Document action).
|
||||
//! live typed document filter, Favorites, Recent Documents, All Docs list, and New Document action).
|
||||
|
||||
use affine_client::WorkspaceSyncStatus;
|
||||
use ui::{
|
||||
Context, Direction, Hsla, InteractiveElement, IntoElement, ParentElement,
|
||||
StatefulInteractiveElement, Styled, div, px, svg,
|
||||
Context, Direction, ElementInputHandler, FocusHandle, Hsla, InteractiveElement, IntoElement,
|
||||
ParentElement, StatefulInteractiveElement, Styled, canvas, div, px, svg,
|
||||
};
|
||||
use ui_kit::LogicalStyled;
|
||||
use ui_tokens::icons;
|
||||
@@ -16,57 +16,29 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::{
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe, row_dir,
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe,
|
||||
field_text::{FieldText, field_text},
|
||||
row_dir,
|
||||
};
|
||||
|
||||
/// Format the localized sync status badge label and indicator color.
|
||||
pub(super) fn sync_status_badge(
|
||||
/// Localized sync status badge label and its foreground and background colors.
|
||||
fn sync_status_badge(
|
||||
status: WorkspaceSyncStatus,
|
||||
strings: &'static MobileStrings,
|
||||
palette: MobilePalette,
|
||||
) -> (String, Hsla, Hsla) {
|
||||
match status {
|
||||
WorkspaceSyncStatus::Synced => (
|
||||
strings.sync_synced.to_string(),
|
||||
palette.accent,
|
||||
palette.accent_soft,
|
||||
),
|
||||
WorkspaceSyncStatus::Syncing { pending_updates } => (
|
||||
if pending_updates > 0 {
|
||||
format!("{} ({pending_updates})", strings.sync_syncing)
|
||||
} else {
|
||||
strings.sync_syncing.to_string()
|
||||
},
|
||||
palette.accent,
|
||||
palette.accent_soft,
|
||||
),
|
||||
WorkspaceSyncStatus::Connecting => (
|
||||
strings.sync_connecting.to_string(),
|
||||
palette.text_secondary,
|
||||
palette.bg_pill,
|
||||
),
|
||||
WorkspaceSyncStatus::ReconnectScheduled {
|
||||
pending_updates, ..
|
||||
} => (
|
||||
if pending_updates > 0 {
|
||||
format!("{} ({pending_updates})", strings.sync_offline)
|
||||
} else {
|
||||
strings.sync_offline.to_string()
|
||||
},
|
||||
palette.text_secondary,
|
||||
palette.bg_pill,
|
||||
),
|
||||
WorkspaceSyncStatus::Offline => (
|
||||
strings.sync_offline.to_string(),
|
||||
palette.text_secondary,
|
||||
palette.bg_pill,
|
||||
),
|
||||
WorkspaceSyncStatus::AuthRequired | WorkspaceSyncStatus::PermissionRevoked => (
|
||||
strings.sync_auth_required.to_string(),
|
||||
palette.danger,
|
||||
palette.danger_soft,
|
||||
),
|
||||
}
|
||||
let (fg, bg) = match status {
|
||||
WorkspaceSyncStatus::Synced | WorkspaceSyncStatus::Syncing { .. } => {
|
||||
(palette.accent, palette.accent_soft)
|
||||
}
|
||||
WorkspaceSyncStatus::Connecting
|
||||
| WorkspaceSyncStatus::ReconnectScheduled { .. }
|
||||
| WorkspaceSyncStatus::Offline => (palette.text_secondary, palette.bg_pill),
|
||||
WorkspaceSyncStatus::AuthRequired | WorkspaceSyncStatus::PermissionRevoked => {
|
||||
(palette.danger, palette.danger_soft)
|
||||
}
|
||||
};
|
||||
(strings.sync_status_label(status), fg, bg)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -76,6 +48,7 @@ pub(super) fn render_workspace_drawer(
|
||||
viewport_h: f32,
|
||||
progress: f32,
|
||||
accepts_input: bool,
|
||||
(text_focus, focused): (&FocusHandle, bool),
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
strings: &'static MobileStrings,
|
||||
@@ -227,47 +200,18 @@ pub(super) fn render_workspace_drawer(
|
||||
)
|
||||
.child(switch_ws_btn);
|
||||
|
||||
// Search filter display bar + New Document action row.
|
||||
let filter_text = if state.drawer_filter.is_empty() {
|
||||
strings.drawer_filter_placeholder.to_string()
|
||||
} else {
|
||||
state.drawer_filter.clone()
|
||||
};
|
||||
let filter_color = if state.drawer_filter.is_empty() {
|
||||
palette.text_subtle
|
||||
} else {
|
||||
palette.text_primary
|
||||
};
|
||||
let filter_bar = row_dir(dir)
|
||||
.id("mobile.drawer.filter_bar")
|
||||
.snapshot("mobile.drawer.filter_bar", Some("mobile.sheet.panel"))
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.h(px(44.0))
|
||||
.px(px(12.0))
|
||||
.rounded(px(14.0))
|
||||
.bg(palette.bg_canvas)
|
||||
.border_1()
|
||||
.border_color(palette.border)
|
||||
.gap(px(8.0))
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
svg()
|
||||
.data(icons::SEARCH.svg.as_bytes())
|
||||
.w(px(15.0))
|
||||
.h(px(15.0))
|
||||
.text_color(palette.text_muted),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.text_size(px(13.0))
|
||||
.text_color(filter_color)
|
||||
.align_start_for(dir)
|
||||
.overflow_hidden()
|
||||
.child(filter_text),
|
||||
);
|
||||
// Live filter field + New Document action row.
|
||||
let filter_bar = render_filter_field(
|
||||
state,
|
||||
accepts_input,
|
||||
text_focus,
|
||||
focused,
|
||||
palette,
|
||||
dir,
|
||||
strings,
|
||||
a11y_bounds,
|
||||
cx,
|
||||
);
|
||||
|
||||
let mut new_doc_btn = row_dir(dir)
|
||||
.id("mobile.drawer.new_doc_btn")
|
||||
@@ -466,6 +410,9 @@ pub(super) fn render_workspace_drawer(
|
||||
|
||||
if is_tablet {
|
||||
panel = panel.w(px(360.0)).h(px((viewport_h - 32.0).max(260.0)));
|
||||
} else if compact {
|
||||
// A short landscape drawer spends no height on the grabber.
|
||||
panel = panel.w_full().max_h(px((viewport_h - 24.0).max(180.0)));
|
||||
} else {
|
||||
panel = panel
|
||||
.w_full()
|
||||
@@ -507,3 +454,121 @@ pub(super) fn render_workspace_drawer(
|
||||
}
|
||||
backdrop
|
||||
}
|
||||
|
||||
/// The drawer filter: a text field that filters the document groups as the user types, with a
|
||||
/// clear button while it holds text.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn render_filter_field(
|
||||
state: &MobileAppState,
|
||||
accepts_input: bool,
|
||||
text_focus: &FocusHandle,
|
||||
focused: bool,
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
strings: &'static MobileStrings,
|
||||
a11y_bounds: &A11yBoundsMap,
|
||||
cx: &mut Context<MobileShellView>,
|
||||
) -> ui::Stateful<ui::Div> {
|
||||
let filter = &state.drawer_filter;
|
||||
let text = field_text(
|
||||
FieldText {
|
||||
id: "mobile.drawer.filter_bar",
|
||||
text: filter,
|
||||
selection: state.drawer_filter_selection.clone(),
|
||||
reversed: state.drawer_filter_reversed,
|
||||
preedit: state.drawer_filter_preedit.clone(),
|
||||
placeholder: strings.drawer_filter_placeholder,
|
||||
focused,
|
||||
text_size: 13.0,
|
||||
},
|
||||
palette,
|
||||
dir,
|
||||
);
|
||||
|
||||
let mut field = row_dir(dir)
|
||||
.id("mobile.drawer.filter_bar")
|
||||
.snapshot("mobile.drawer.filter_bar", Some("mobile.sheet.panel"))
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.h(px(44.0))
|
||||
.ps(px(12.0), dir)
|
||||
.pe(px(if filter.is_empty() { 12.0 } else { 0.0 }), dir)
|
||||
.rounded(px(14.0))
|
||||
.bg(if focused {
|
||||
palette.accent_soft
|
||||
} else {
|
||||
palette.bg_pill
|
||||
})
|
||||
.gap(px(8.0))
|
||||
.overflow_hidden()
|
||||
.child(a11y_bounds_probe(
|
||||
"mobile.drawer.filter_bar",
|
||||
a11y_bounds.clone(),
|
||||
))
|
||||
.child(
|
||||
svg()
|
||||
.data(icons::SEARCH.svg.as_bytes())
|
||||
.mirror_in_rtl(true)
|
||||
.w(px(15.0))
|
||||
.h(px(15.0))
|
||||
.flex_shrink(0.0)
|
||||
.text_color(palette.text_muted),
|
||||
)
|
||||
.child(text);
|
||||
if accepts_input {
|
||||
let entity = cx.entity();
|
||||
let handle = text_focus.clone();
|
||||
field = field
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
window.focus(&this.search_focus, cx);
|
||||
cx.notify();
|
||||
}))
|
||||
.child(
|
||||
canvas(
|
||||
|_, _, _| (),
|
||||
move |bounds, (), window, cx| {
|
||||
window.handle_input(
|
||||
&handle,
|
||||
ElementInputHandler::new(bounds, entity.clone()),
|
||||
cx,
|
||||
);
|
||||
},
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
);
|
||||
}
|
||||
if !filter.is_empty() {
|
||||
let mut clear = div()
|
||||
.id("mobile.drawer.filter_clear_btn")
|
||||
.snapshot("mobile.drawer.filter_clear_btn", Some("mobile.sheet.panel"))
|
||||
.relative()
|
||||
.w(px(44.0))
|
||||
.h(px(44.0))
|
||||
.flex_shrink(0.0)
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(a11y_bounds_probe(
|
||||
"mobile.drawer.filter_clear_btn",
|
||||
a11y_bounds.clone(),
|
||||
))
|
||||
.child(
|
||||
svg()
|
||||
.data(icons::CLOSE.svg.as_bytes())
|
||||
.w(px(14.0))
|
||||
.h(px(14.0))
|
||||
.text_color(palette.text_secondary),
|
||||
);
|
||||
if accepts_input {
|
||||
clear = clear.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.state.set_drawer_filter("");
|
||||
cx.stop_propagation();
|
||||
cx.notify();
|
||||
}));
|
||||
}
|
||||
field = field.child(clear);
|
||||
}
|
||||
field
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
//! `Settings -> Experimental` sheet body: one row per experimental feature with its name, its
|
||||
//! description, and a switch, as the `0.27.5` `ExperimentalFeatureList` lists them.
|
||||
|
||||
use ui::{
|
||||
Context, Direction, Hsla, InteractiveElement, IntoElement, ParentElement,
|
||||
StatefulInteractiveElement, Styled, div, px,
|
||||
};
|
||||
use ui_kit::LogicalStyled;
|
||||
|
||||
use crate::{
|
||||
state::{ExperimentalFlag, MobileAppState},
|
||||
strings::MobileStrings,
|
||||
};
|
||||
|
||||
use super::{
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe, row_dir,
|
||||
};
|
||||
|
||||
/// A 44 × 26 pt switch whose knob sits at the inline end when `on`.
|
||||
fn switch(on: bool, palette: MobilePalette, dir: Direction) -> impl IntoElement {
|
||||
let track = row_dir(dir)
|
||||
.w(px(44.0))
|
||||
.h(px(26.0))
|
||||
.flex_shrink(0.0)
|
||||
.p(px(2.0))
|
||||
.rounded(px(13.0))
|
||||
.bg(if on { palette.accent } else { palette.bg_pill })
|
||||
.border_1()
|
||||
.border_color(if on { palette.accent } else { palette.border });
|
||||
let track = if on { track.justify_end() } else { track };
|
||||
track.child(
|
||||
div()
|
||||
.w(px(20.0))
|
||||
.h(px(20.0))
|
||||
.rounded(px(10.0))
|
||||
.bg(ui::white())
|
||||
.border_1()
|
||||
.border_color(Hsla {
|
||||
a: 0.08,
|
||||
..palette.text_primary
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn render_experimental_content(
|
||||
state: &MobileAppState,
|
||||
accepts_input: bool,
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
strings: &'static MobileStrings,
|
||||
a11y_bounds: &A11yBoundsMap,
|
||||
cx: &mut Context<MobileShellView>,
|
||||
) -> ui::AnyElement {
|
||||
let mut list = div()
|
||||
.w_full()
|
||||
.rounded(px(22.0))
|
||||
.bg(palette.bg_canvas)
|
||||
.border_1()
|
||||
.border_color(palette.border)
|
||||
.flex()
|
||||
.flex_col()
|
||||
.overflow_hidden();
|
||||
for (idx, flag) in ExperimentalFlag::ALL.into_iter().enumerate() {
|
||||
let id = flag.a11y_id();
|
||||
let mut row = row_dir(dir)
|
||||
.id(id.clone())
|
||||
.snapshot(id.clone(), Some("mobile.sheet.panel"))
|
||||
.relative()
|
||||
.w_full()
|
||||
.min_h(px(64.0))
|
||||
.ps(px(14.0), dir)
|
||||
.pe(px(14.0), dir)
|
||||
.py(px(10.0))
|
||||
.gap(px(12.0))
|
||||
.justify_between()
|
||||
.child(a11y_bounds_probe(id, a11y_bounds.clone()))
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap(px(2.0))
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(15.0))
|
||||
.text_color(palette.text_primary)
|
||||
.align_start_for(dir)
|
||||
.child(flag.name(strings)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(12.0))
|
||||
.text_color(palette.text_secondary)
|
||||
.align_start_for(dir)
|
||||
.child(flag.description(strings)),
|
||||
),
|
||||
)
|
||||
.child(switch(state.settings.flag(flag), palette, dir));
|
||||
if idx > 0 {
|
||||
row = row.border_t(px(1.0)).border_color(palette.border);
|
||||
}
|
||||
if accepts_input {
|
||||
row = row.on_click(cx.listener(move |this, _, _, cx| {
|
||||
this.state.toggle_experimental_flag(flag);
|
||||
cx.notify();
|
||||
}));
|
||||
}
|
||||
list = list.child(row);
|
||||
}
|
||||
list.into_any_element()
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
//! Text line of a single-line field (`Search` query, `WorkspaceDrawer` filter): the placeholder,
|
||||
//! the IME composition underline, and while focused the caret at the active end of the
|
||||
//! selection with the selected text highlighted.
|
||||
|
||||
use std::ops::Range;
|
||||
|
||||
use ui::{Direction, InteractiveElement, IntoElement, ParentElement, Styled, div, px};
|
||||
|
||||
use super::{MobileFlexExt, MobilePalette, row_dir, utf16_to_byte};
|
||||
|
||||
/// What one field line shows.
|
||||
pub(super) struct FieldText<'a> {
|
||||
/// Snapshot ID of the field; the caret records `<id>.caret`.
|
||||
pub id: &'static str,
|
||||
pub text: &'a str,
|
||||
pub selection: Range<usize>,
|
||||
pub reversed: bool,
|
||||
pub preedit: Option<Range<usize>>,
|
||||
pub placeholder: &'static str,
|
||||
pub focused: bool,
|
||||
pub text_size: f32,
|
||||
}
|
||||
|
||||
pub(super) fn field_text(field: FieldText<'_>, palette: MobilePalette, dir: Direction) -> ui::Div {
|
||||
let caret_id = format!("{}.caret", field.id);
|
||||
let caret = || {
|
||||
div()
|
||||
.id(caret_id.clone())
|
||||
.snapshot(caret_id.clone(), Some(field.id))
|
||||
.w(px(2.0))
|
||||
.h(px(18.0))
|
||||
.flex_shrink(0.0)
|
||||
.rounded(px(1.0))
|
||||
.bg(palette.accent)
|
||||
.into_any_element()
|
||||
};
|
||||
let text = field.text;
|
||||
let run = |range: Range<usize>| {
|
||||
div()
|
||||
.flex_shrink(0.0)
|
||||
.text_size(px(field.text_size))
|
||||
.text_color(palette.text_primary)
|
||||
.child(text[range].to_string())
|
||||
};
|
||||
let mut line = row_dir(dir).flex_1().min_w(px(0.0)).overflow_hidden();
|
||||
if text.is_empty() {
|
||||
if field.focused {
|
||||
line = line.child(caret());
|
||||
}
|
||||
return line.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.overflow_hidden()
|
||||
.text_size(px(field.text_size))
|
||||
.text_color(palette.text_muted)
|
||||
.align_start_for(dir)
|
||||
.child(field.placeholder),
|
||||
);
|
||||
}
|
||||
let total = text.encode_utf16().count();
|
||||
let bytes = |r: &Range<usize>| {
|
||||
let start = utf16_to_byte(text, r.start.min(total));
|
||||
start..utf16_to_byte(text, r.end.min(total)).max(start)
|
||||
};
|
||||
let len = text.len();
|
||||
// `(byte range, underline, highlight)` of each run, and the run the caret precedes.
|
||||
let (runs, caret_before) = match &field.preedit {
|
||||
Some(pre) => {
|
||||
let marked = bytes(pre);
|
||||
let runs = [
|
||||
(0..marked.start, false, false),
|
||||
(marked.clone(), true, false),
|
||||
(marked.end..len, false, false),
|
||||
];
|
||||
(runs, None)
|
||||
}
|
||||
None if field.focused => {
|
||||
let selected = bytes(&field.selection);
|
||||
let runs = [
|
||||
(0..selected.start, false, false),
|
||||
(selected.clone(), false, true),
|
||||
(selected.end..len, false, false),
|
||||
];
|
||||
(runs, Some(if field.reversed { 1 } else { 2 }))
|
||||
}
|
||||
None => (
|
||||
[
|
||||
(0..len, false, false),
|
||||
(len..len, false, false),
|
||||
(len..len, false, false),
|
||||
],
|
||||
None,
|
||||
),
|
||||
};
|
||||
for (idx, (range, underline, highlight)) in runs.into_iter().enumerate() {
|
||||
if caret_before == Some(idx) {
|
||||
line = line.child(caret());
|
||||
}
|
||||
if range.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut el = run(range);
|
||||
if underline {
|
||||
el = el.border_b_1().border_color(palette.accent);
|
||||
}
|
||||
if highlight {
|
||||
el = el.bg(palette.accent_soft);
|
||||
}
|
||||
line = line.child(el);
|
||||
}
|
||||
line
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
//! Week strip below the header of a journal page, after the `0.27.5` `JournalDatePicker` week
|
||||
//! view: seven day cells with journal dots, previous and next week, and `Today`.
|
||||
|
||||
use ui::{
|
||||
Context, Direction, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement,
|
||||
Styled, div, px, svg,
|
||||
};
|
||||
use ui_kit::LogicalStyled;
|
||||
use ui_tokens::{IconDef, icons};
|
||||
|
||||
use crate::{state::MobileAppState, strings::MobileStrings};
|
||||
|
||||
use super::{
|
||||
A11yBoundsMap, MobilePalette, MobileShellView, a11y_bounds_probe, row_dir, week_days_for_date,
|
||||
};
|
||||
|
||||
/// IDs and steps of the two week buttons, in reading order.
|
||||
const WEEK_BUTTONS: [(&str, IconDef, i64); 2] = [
|
||||
(
|
||||
"mobile.page.journal_strip.prev_btn",
|
||||
icons::ARROW_LEFT_SMALL,
|
||||
-1,
|
||||
),
|
||||
(
|
||||
"mobile.page.journal_strip.next_btn",
|
||||
icons::ARROW_RIGHT_SMALL,
|
||||
1,
|
||||
),
|
||||
];
|
||||
|
||||
/// The strip of `doc_id`, or `None` when the document is no journal.
|
||||
pub(super) fn render_journal_date_strip(
|
||||
state: &MobileAppState,
|
||||
doc_id: &str,
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
strings: &'static MobileStrings,
|
||||
a11y_bounds: &A11yBoundsMap,
|
||||
cx: &mut Context<MobileShellView>,
|
||||
) -> Option<impl IntoElement> {
|
||||
let selected = state.doc_by_id(doc_id)?.journal_date.clone()?;
|
||||
let week = week_days_for_date(&state.journal_strip_date(doc_id)?);
|
||||
let today = state.today_date.as_str();
|
||||
|
||||
let week_button = |(id, icon, step): (&'static str, IconDef, i64),
|
||||
cx: &mut Context<MobileShellView>| {
|
||||
div()
|
||||
.id(id)
|
||||
.snapshot(id, Some("mobile.shell.root"))
|
||||
.relative()
|
||||
.w(px(44.0))
|
||||
.h(px(44.0))
|
||||
.flex_shrink(0.0)
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.on_click(cx.listener(move |this, _, _, cx| {
|
||||
this.state.shift_journal_strip(step);
|
||||
cx.notify();
|
||||
}))
|
||||
.child(a11y_bounds_probe(id, a11y_bounds.clone()))
|
||||
.child(
|
||||
svg()
|
||||
.data(icon.svg.as_bytes())
|
||||
.mirror_in_rtl(true)
|
||||
.w(px(15.0))
|
||||
.h(px(15.0))
|
||||
.text_color(palette.text_secondary),
|
||||
)
|
||||
};
|
||||
|
||||
// The month of the shown week, as the `0.27.5` header title shows it.
|
||||
let month = week[3].2.get(..7).unwrap_or_default().to_string();
|
||||
let mut title_row = row_dir(dir)
|
||||
.w_full()
|
||||
.h(px(44.0))
|
||||
.child(week_button(WEEK_BUTTONS[0], cx))
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.flex()
|
||||
.justify_center()
|
||||
.text_size(px(14.0))
|
||||
.font_weight(ui::FontWeight::SEMIBOLD)
|
||||
.text_color(palette.text_primary)
|
||||
.child(month),
|
||||
);
|
||||
if state.journal_strip_shows_today(doc_id) {
|
||||
let id = "mobile.page.journal_strip.today_btn";
|
||||
title_row = title_row.child(
|
||||
div()
|
||||
.id(id)
|
||||
.snapshot(id, Some("mobile.shell.root"))
|
||||
.relative()
|
||||
.h(px(44.0))
|
||||
.min_w(px(44.0))
|
||||
.px(px(8.0))
|
||||
.flex_shrink(0.0)
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.text_size(px(13.0))
|
||||
.text_color(palette.accent)
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
let (t, today) = (this.now_ms(cx), this.state.today_date.clone());
|
||||
this.state.open_journal_date(&today, t);
|
||||
cx.notify();
|
||||
}))
|
||||
.child(a11y_bounds_probe(id, a11y_bounds.clone()))
|
||||
.child(strings.today_btn_label),
|
||||
);
|
||||
}
|
||||
title_row = title_row.child(week_button(WEEK_BUTTONS[1], cx));
|
||||
|
||||
let mut days = row_dir(dir).w_full().h(px(48.0)).gap(px(4.0));
|
||||
for (idx, (_, day_num, date)) in week.into_iter().enumerate() {
|
||||
let id = format!("mobile.page.journal_strip.day.{date}");
|
||||
let is_selected = date == selected;
|
||||
let text_color = if is_selected {
|
||||
ui::white()
|
||||
} else if date == today {
|
||||
palette.accent
|
||||
} else {
|
||||
palette.text_primary
|
||||
};
|
||||
let mut cell = div()
|
||||
.id(id.clone())
|
||||
.snapshot(id.clone(), Some("mobile.shell.root"))
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.h(px(48.0))
|
||||
.rounded(px(8.0))
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(a11y_bounds_probe(id, a11y_bounds.clone()))
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(11.0))
|
||||
.text_color(if is_selected {
|
||||
ui::white()
|
||||
} else {
|
||||
palette.text_secondary
|
||||
})
|
||||
.child(strings.weekday_short[idx]),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(15.0))
|
||||
.font_weight(if is_selected {
|
||||
ui::FontWeight::SEMIBOLD
|
||||
} else {
|
||||
ui::FontWeight::NORMAL
|
||||
})
|
||||
.text_color(text_color)
|
||||
.child(day_num),
|
||||
);
|
||||
cell = cell.child(div().w(px(3.0)).h(px(3.0)).rounded(px(1.5)).bg(
|
||||
if !state.has_journal_on(&date) {
|
||||
ui::transparent_black()
|
||||
} else if is_selected {
|
||||
ui::white()
|
||||
} else {
|
||||
palette.accent
|
||||
},
|
||||
));
|
||||
if is_selected {
|
||||
cell = cell.bg(palette.accent);
|
||||
} else {
|
||||
cell = cell.on_click(cx.listener(move |this, _, _, cx| {
|
||||
let t = this.now_ms(cx);
|
||||
this.state.open_journal_date(&date, t);
|
||||
cx.notify();
|
||||
}));
|
||||
}
|
||||
days = days.child(cell);
|
||||
}
|
||||
|
||||
Some(
|
||||
div()
|
||||
.id("mobile.page.journal_strip")
|
||||
.snapshot("mobile.page.journal_strip", Some("mobile.shell.root"))
|
||||
.w_full()
|
||||
.flex_shrink(0.0)
|
||||
.ps(px(4.0), dir)
|
||||
.pe(px(4.0), dir)
|
||||
.pb(px(6.0))
|
||||
.bg(palette.bg_surface)
|
||||
.border_b_1()
|
||||
.border_color(palette.border)
|
||||
.flex()
|
||||
.flex_col()
|
||||
.child(title_row)
|
||||
.child(days),
|
||||
)
|
||||
}
|
||||
@@ -471,6 +471,18 @@ pub(crate) fn week_days_for_date(iso_date: &str) -> Vec<(&'static str, String, S
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Format Unix milliseconds as a UTC `YYYY-MM-DD HH:MM` date and time.
|
||||
pub(crate) fn format_utc_ms(ms: i64) -> String {
|
||||
let secs = ms.div_euclid(1000);
|
||||
let (y, m, d) = civil_from_days(secs.div_euclid(86_400));
|
||||
let day_secs = secs.rem_euclid(86_400);
|
||||
format!(
|
||||
"{y:04}-{m:02}-{d:02} {:02}:{:02}",
|
||||
day_secs / 3600,
|
||||
day_secs % 3600 / 60
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_iso_date(s: &str) -> Option<(i32, u32, u32)> {
|
||||
let mut parts = s.split('-');
|
||||
let y: i32 = parts.next()?.parse().ok()?;
|
||||
@@ -525,4 +537,16 @@ mod tests {
|
||||
assert_eq!(shift_iso_date("2024-02-29", 7), "2024-03-07");
|
||||
assert_eq!(shift_iso_date("2024-03-01", -7), "2024-02-23");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn utc_milliseconds_format_as_date_and_minute() {
|
||||
for (ms, text) in [
|
||||
(0, "1970-01-01 00:00"),
|
||||
(1_764_072_000_000, "2025-11-25 12:00"),
|
||||
(1_709_208_059_999, "2024-02-29 12:00"),
|
||||
(-1, "1969-12-31 23:59"),
|
||||
] {
|
||||
assert_eq!(format_utc_ms(ms), text, "{ms}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
//! L4 mobile shell GPU UI views (`MobileShellView`, 4-TabBar, routes, modal sheets,
|
||||
//! `Focusable` + `EntityInputHandler` for Search IME, and live `AccessibilityTree` publication).
|
||||
|
||||
mod doc_info_sheet;
|
||||
mod drawer;
|
||||
mod experimental_sheet;
|
||||
mod explorer;
|
||||
mod explorer_rows;
|
||||
mod field_text;
|
||||
mod journal_conflicts;
|
||||
mod journal_date_strip;
|
||||
mod journals;
|
||||
mod page;
|
||||
mod page_directory;
|
||||
@@ -17,7 +21,8 @@ mod sheet_actions;
|
||||
mod tabs;
|
||||
mod toc_sheet;
|
||||
|
||||
pub(crate) use journals::{shift_iso_date, week_days_for_date};
|
||||
pub(crate) use doc_info_sheet::{doc_info_rows, doc_info_tag_id};
|
||||
pub(crate) use journals::{format_utc_ms, shift_iso_date, week_days_for_date};
|
||||
pub(super) use palette::{MobilePalette, palette_for};
|
||||
|
||||
use std::{
|
||||
@@ -38,12 +43,13 @@ use ui_kit::{BreadcrumbBarLayout, LogicalStyled, SafeArea, SafeAreaEdges};
|
||||
use ui_tokens::FONT_SANS;
|
||||
|
||||
pub(super) use crate::a11y::{A11yBoundsMap, a11y_bounds_probe, a11y_bounds_probe_border};
|
||||
pub(super) use crate::state::utf16_to_byte;
|
||||
use crate::{
|
||||
a11y::{
|
||||
InMemoryPlatformAccessibility, MobileA11yAction, SafeAreaMetrics, apply_measured_bounds,
|
||||
build_accessibility_tree_with_layout, perform_a11y_action_with_layout,
|
||||
},
|
||||
state::{MobileAppState, MobileRoute, MobileSheet},
|
||||
state::{CaretMove, MobileAppState, MobileRoute, MobileSheet},
|
||||
};
|
||||
|
||||
pub(super) trait MobileFlexExt: Styled {
|
||||
@@ -239,69 +245,41 @@ impl MobileShellView {
|
||||
now.saturating_duration_since(origin).as_secs_f64() * 1000.0
|
||||
}
|
||||
|
||||
/// Control-key handler for `Search` (`Backspace`, `Delete`, `Escape`).
|
||||
/// Control-key handler of the active text field (`Backspace`, `Delete`, `Escape`, caret
|
||||
/// keys with `Shift` to extend, and `Cmd` / `Ctrl` + `A`).
|
||||
/// Printable character insertion flows exclusively through [`EntityInputHandler`] so
|
||||
/// physical keyboard events never duplicate characters on Web or native hosts.
|
||||
fn handle_search_key_down(
|
||||
fn handle_text_key_down(
|
||||
&mut self,
|
||||
event: &KeyDownEvent,
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.state.route != MobileRoute::Search {
|
||||
let rtl = self.state.locale().direction().is_rtl();
|
||||
let Some(mut field) = self.state.active_text_field() else {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let modifiers = &event.keystroke.modifiers;
|
||||
let (back, forward) = if rtl {
|
||||
("right", "left")
|
||||
} else {
|
||||
("left", "right")
|
||||
};
|
||||
match event.keystroke.key.as_str() {
|
||||
"backspace" => {
|
||||
self.state.search_preedit = None;
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let start = self.state.search_selection.start.min(total);
|
||||
let end = self.state.search_selection.end.min(total).max(start);
|
||||
if end > start {
|
||||
let bs = utf16_to_byte(&self.state.search_query, start);
|
||||
let be = utf16_to_byte(&self.state.search_query, end);
|
||||
self.state.search_query.replace_range(bs..be, "");
|
||||
self.state.search_selection = start..start;
|
||||
} else if start > 0 {
|
||||
let be = utf16_to_byte(&self.state.search_query, start);
|
||||
if let Some((prev_b, prev_ch)) =
|
||||
self.state.search_query[..be].char_indices().next_back()
|
||||
{
|
||||
self.state.search_query.replace_range(prev_b..be, "");
|
||||
let new_pos = start.saturating_sub(prev_ch.len_utf16());
|
||||
self.state.search_selection = new_pos..new_pos;
|
||||
}
|
||||
}
|
||||
cx.stop_propagation();
|
||||
cx.notify();
|
||||
"backspace" => field.delete(true),
|
||||
"delete" => field.delete(false),
|
||||
"escape" => *field.preedit = None,
|
||||
"a" if modifiers.platform || modifiers.control => {
|
||||
field.move_caret(CaretMove::All, false)
|
||||
}
|
||||
"delete" => {
|
||||
self.state.search_preedit = None;
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let start = self.state.search_selection.start.min(total);
|
||||
let end = self.state.search_selection.end.min(total).max(start);
|
||||
if end > start {
|
||||
let bs = utf16_to_byte(&self.state.search_query, start);
|
||||
let be = utf16_to_byte(&self.state.search_query, end);
|
||||
self.state.search_query.replace_range(bs..be, "");
|
||||
self.state.search_selection = start..start;
|
||||
} else if start < total {
|
||||
let bs = utf16_to_byte(&self.state.search_query, start);
|
||||
if let Some(next_ch) = self.state.search_query[bs..].chars().next() {
|
||||
let be = bs + next_ch.len_utf8();
|
||||
self.state.search_query.replace_range(bs..be, "");
|
||||
}
|
||||
}
|
||||
cx.stop_propagation();
|
||||
cx.notify();
|
||||
}
|
||||
"escape" => {
|
||||
self.state.search_preedit = None;
|
||||
cx.stop_propagation();
|
||||
cx.notify();
|
||||
}
|
||||
_ => {}
|
||||
key if key == back => field.move_caret(CaretMove::Back, modifiers.shift),
|
||||
key if key == forward => field.move_caret(CaretMove::Forward, modifiers.shift),
|
||||
"home" => field.move_caret(CaretMove::Start, modifiers.shift),
|
||||
"end" => field.move_caret(CaretMove::End, modifiers.shift),
|
||||
_ => return,
|
||||
}
|
||||
cx.stop_propagation();
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,6 +289,7 @@ impl Focusable for MobileShellView {
|
||||
}
|
||||
}
|
||||
|
||||
/// Platform text input of the `Search` query and the `WorkspaceDrawer` filter.
|
||||
impl EntityInputHandler for MobileShellView {
|
||||
fn text_for_range(
|
||||
&mut self,
|
||||
@@ -319,13 +298,9 @@ impl EntityInputHandler for MobileShellView {
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) -> Option<String> {
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let s = range.start.min(total);
|
||||
let e = range.end.min(total).max(s);
|
||||
*adjusted_range = Some(s..e);
|
||||
let bs = utf16_to_byte(&self.state.search_query, s);
|
||||
let be = utf16_to_byte(&self.state.search_query, e);
|
||||
Some(self.state.search_query[bs..be].to_string())
|
||||
let (text, range) = self.state.active_text_field()?.text_for_range(range);
|
||||
*adjusted_range = Some(range);
|
||||
Some(text)
|
||||
}
|
||||
|
||||
fn selected_text_range(
|
||||
@@ -334,26 +309,50 @@ impl EntityInputHandler for MobileShellView {
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) -> Option<UTF16Selection> {
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let start = self.state.search_selection.start.min(total);
|
||||
let end = self.state.search_selection.end.min(total).max(start);
|
||||
let field = self.state.active_text_field()?;
|
||||
Some(UTF16Selection {
|
||||
range: start..end,
|
||||
reversed: false,
|
||||
range: field.selected_range(),
|
||||
reversed: *field.reversed,
|
||||
})
|
||||
}
|
||||
|
||||
fn set_selected_text_range(
|
||||
&mut self,
|
||||
range_utf16: Range<usize>,
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if let Some(mut field) = self.state.active_text_field() {
|
||||
field.select(range_utf16);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn text_length_utf16(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) -> Option<usize> {
|
||||
Some(self.state.active_text_field()?.len_utf16())
|
||||
}
|
||||
|
||||
fn marked_text_range(
|
||||
&self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) -> Option<Range<usize>> {
|
||||
self.state.search_preedit.clone()
|
||||
if self.state.active_sheet == MobileSheet::WorkspaceDrawer {
|
||||
self.state.drawer_filter_preedit.clone()
|
||||
} else {
|
||||
self.state.search_preedit.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.state.search_preedit = None;
|
||||
cx.notify();
|
||||
if let Some(field) = self.state.active_text_field() {
|
||||
*field.preedit = None;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn replace_text_in_range(
|
||||
@@ -363,23 +362,10 @@ impl EntityInputHandler for MobileShellView {
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let target = range
|
||||
.or_else(|| self.state.search_preedit.take())
|
||||
.unwrap_or_else(|| {
|
||||
let s = self.state.search_selection.start.min(total);
|
||||
let e = self.state.search_selection.end.min(total).max(s);
|
||||
s..e
|
||||
});
|
||||
let start_u16 = target.start.min(total);
|
||||
let end_u16 = target.end.min(total).max(start_u16);
|
||||
let bs = utf16_to_byte(&self.state.search_query, start_u16);
|
||||
let be = utf16_to_byte(&self.state.search_query, end_u16);
|
||||
self.state.search_query.replace_range(bs..be, text);
|
||||
let new_caret = start_u16 + text.encode_utf16().count();
|
||||
self.state.search_selection = new_caret..new_caret;
|
||||
self.state.search_preedit = None;
|
||||
cx.notify();
|
||||
if let Some(mut field) = self.state.active_text_field() {
|
||||
field.replace(range, text);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn replace_and_mark_text_in_range(
|
||||
@@ -390,31 +376,10 @@ impl EntityInputHandler for MobileShellView {
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let target = range
|
||||
.or_else(|| self.state.search_preedit.clone())
|
||||
.unwrap_or_else(|| {
|
||||
let s = self.state.search_selection.start.min(total);
|
||||
let e = self.state.search_selection.end.min(total).max(s);
|
||||
s..e
|
||||
});
|
||||
let start_u16 = target.start.min(total);
|
||||
let end_u16 = target.end.min(total).max(start_u16);
|
||||
let bs = utf16_to_byte(&self.state.search_query, start_u16);
|
||||
let be = utf16_to_byte(&self.state.search_query, end_u16);
|
||||
self.state.search_query.replace_range(bs..be, new_text);
|
||||
let inserted_len = new_text.encode_utf16().count();
|
||||
self.state.search_preedit = if inserted_len > 0 {
|
||||
Some(start_u16..(start_u16 + inserted_len))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let sel = new_selected_range.map_or(
|
||||
(start_u16 + inserted_len)..(start_u16 + inserted_len),
|
||||
|r| (start_u16 + r.start)..(start_u16 + r.end),
|
||||
);
|
||||
self.state.search_selection = sel;
|
||||
cx.notify();
|
||||
if let Some(mut field) = self.state.active_text_field() {
|
||||
field.replace_and_mark(range, new_text, new_selected_range);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn bounds_for_range(
|
||||
@@ -425,11 +390,12 @@ impl EntityInputHandler for MobileShellView {
|
||||
_cx: &mut Context<Self>,
|
||||
) -> Option<Bounds<Pixels>> {
|
||||
let char_w = 8.0 * self.state.font_scale.max(0.5);
|
||||
let inset = self.state.active_text_field()?.text_inset;
|
||||
let origin_x: f32 = element_bounds.origin.x.into();
|
||||
let origin_y: f32 = element_bounds.origin.y.into();
|
||||
let max_w: f32 = element_bounds.size.width.into();
|
||||
let x = (origin_x + 36.0 + (range_utf16.start as f32) * char_w)
|
||||
.min(origin_x + (max_w - 48.0).max(36.0));
|
||||
let x = (origin_x + inset + (range_utf16.start as f32) * char_w)
|
||||
.min(origin_x + (max_w - 48.0).max(inset));
|
||||
let w = ((range_utf16.end.saturating_sub(range_utf16.start) as f32) * char_w).max(2.0);
|
||||
Some(Bounds::new(
|
||||
Point::new(px(x), px(origin_y + 12.0)),
|
||||
@@ -443,10 +409,12 @@ impl EntityInputHandler for MobileShellView {
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) -> Option<usize> {
|
||||
let total = self.state.search_query.encode_utf16().count();
|
||||
let char_w = 8.0 * self.state.font_scale.max(0.5);
|
||||
let field = self.state.active_text_field()?;
|
||||
let total = field.text.encode_utf16().count();
|
||||
let px_x: f32 = point.x.into();
|
||||
let rel = (px_x - 52.0).max(0.0);
|
||||
// Both fields sit inside a 16 pt content inset.
|
||||
let rel = (px_x - 16.0 - field.text_inset).max(0.0);
|
||||
Some(((rel / char_w).round() as usize).min(total))
|
||||
}
|
||||
}
|
||||
@@ -540,9 +508,9 @@ impl Render for MobileShellView {
|
||||
)
|
||||
.into_any_element(),
|
||||
MobileRoute::Page(doc_id) => {
|
||||
let editor_entity = self
|
||||
.page_editor
|
||||
.sync(&mut self.state, &doc_id, content_w, cx);
|
||||
let editor_entity =
|
||||
self.page_editor
|
||||
.sync(&mut self.state, &doc_id, content_w, window, cx);
|
||||
let (el, bc_layout) = page::render_page(
|
||||
&mut self.state,
|
||||
&doc_id,
|
||||
@@ -601,7 +569,7 @@ impl Render for MobileShellView {
|
||||
.id("mobile.shell.root")
|
||||
.snapshot("mobile.shell.root", None)
|
||||
.track_focus(&self.search_focus)
|
||||
.on_key_down(cx.listener(Self::handle_search_key_down))
|
||||
.on_key_down(cx.listener(Self::handle_text_key_down))
|
||||
.size_full()
|
||||
.relative()
|
||||
.pt(safe.top)
|
||||
@@ -659,6 +627,7 @@ impl Render for MobileShellView {
|
||||
viewport_h,
|
||||
sheet_snap.progress as f32,
|
||||
sheet_snap.accepts_input,
|
||||
(&self.search_focus, search_focused),
|
||||
palette,
|
||||
dir,
|
||||
strings,
|
||||
@@ -690,38 +659,3 @@ impl Render for MobileShellView {
|
||||
root
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a UTF-16 offset to a UTF-8 boundary. Round up inside a surrogate pair.
|
||||
fn utf16_to_byte(text: &str, utf16_offset: usize) -> usize {
|
||||
let mut units = 0usize;
|
||||
for (byte_idx, ch) in text.char_indices() {
|
||||
if units >= utf16_offset {
|
||||
return byte_idx;
|
||||
}
|
||||
units += ch.len_utf16();
|
||||
}
|
||||
text.len()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod utf16_tests {
|
||||
use super::utf16_to_byte;
|
||||
|
||||
#[test]
|
||||
fn utf16_offsets_round_up_inside_surrogate_pairs() {
|
||||
for (text, offsets) in [
|
||||
("A😀B", &[0, 1, 5, 5, 6, 6][..]),
|
||||
("😀", &[0, 4, 4, 4][..]),
|
||||
("é中", &[0, 2, 5, 5][..]),
|
||||
("", &[0, 0][..]),
|
||||
] {
|
||||
for (offset, &expected) in offsets.iter().enumerate() {
|
||||
assert_eq!(
|
||||
utf16_to_byte(text, offset),
|
||||
expected,
|
||||
"{text:?} at {offset}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Mobile `Page` route (interactive header, real-measured single-line interactive `Breadcrumb`,
|
||||
//! independent `Backlinks` pill, and RTL-aligned title/body).
|
||||
//! Mobile `Page` route (interactive header, journal week strip, real-measured single-line
|
||||
//! interactive `Breadcrumb`, independent `Backlinks` pill, and RTL-aligned title/body).
|
||||
|
||||
use affine_client::{BacklinkCompleteness, BreadcrumbAction, ContextState};
|
||||
use ui::{
|
||||
@@ -19,7 +19,7 @@ use crate::{
|
||||
|
||||
use super::{
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe,
|
||||
a11y_bounds_probe_border, drawer::sync_status_badge, row_dir,
|
||||
a11y_bounds_probe_border, journal_date_strip::render_journal_date_strip, row_dir,
|
||||
};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -91,28 +91,7 @@ pub(super) fn render_page(
|
||||
),
|
||||
)
|
||||
.child({
|
||||
let (sync_label, sync_fg, sync_bg) =
|
||||
sync_status_badge(state.active_workspace().sync_status, strings, palette);
|
||||
let mut trailing = row_dir(dir).flex_shrink(0.0).gap(px(4.0));
|
||||
if viewport_w >= 360.0 {
|
||||
trailing = trailing.child(
|
||||
div()
|
||||
.id("mobile.page.sync_status")
|
||||
.snapshot("mobile.page.sync_status", Some("mobile.shell.root"))
|
||||
.relative()
|
||||
.px(px(8.0))
|
||||
.py(px(3.0))
|
||||
.rounded(px(10.0))
|
||||
.bg(sync_bg)
|
||||
.text_size(px(11.0))
|
||||
.text_color(sync_fg)
|
||||
.child(a11y_bounds_probe(
|
||||
"mobile.page.sync_status",
|
||||
a11y_bounds.clone(),
|
||||
))
|
||||
.child(sync_label),
|
||||
);
|
||||
}
|
||||
trailing = trailing.child(
|
||||
div()
|
||||
.id("mobile.page.drawer_btn")
|
||||
@@ -218,6 +197,12 @@ pub(super) fn render_page(
|
||||
.flex_col()
|
||||
.overflow_hidden()
|
||||
.child(header);
|
||||
if !derivation.in_trash
|
||||
&& let Some(strip) =
|
||||
render_journal_date_strip(state, doc_id, palette, dir, strings, a11y_bounds, cx)
|
||||
{
|
||||
page_col = page_col.child(strip);
|
||||
}
|
||||
|
||||
let mut measured_layout = None;
|
||||
if !derivation.should_hide_bar_on_mobile && !derivation.crumbs.is_empty() {
|
||||
|
||||
@@ -16,7 +16,7 @@ use playground::{
|
||||
FormFactor, PlaygroundMode, PlaygroundOptions, PlaygroundTheme, PlaygroundView,
|
||||
room_client::DocState,
|
||||
};
|
||||
use ui::{Context, Entity, prelude::*};
|
||||
use ui::{Context, Entity, Window, prelude::*};
|
||||
use ui_tokens::ThemeMode;
|
||||
|
||||
use super::page_directory::{
|
||||
@@ -199,12 +199,30 @@ pub(super) fn load_doc_into_playground_state(
|
||||
doc_state.workspace = ws;
|
||||
}
|
||||
|
||||
/// Write gates of the embedded editor: `page` gates Page text and Database edits, `edgeless`
|
||||
/// gates Edgeless authoring.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(super) struct EditorGates {
|
||||
pub page: bool,
|
||||
pub edgeless: bool,
|
||||
}
|
||||
|
||||
impl EditorGates {
|
||||
fn for_doc(state: &MobileAppState, doc_id: &str) -> Self {
|
||||
let page = state.page_readonly(doc_id);
|
||||
Self {
|
||||
page,
|
||||
edgeless: page || !state.settings.enable_mobile_edgeless_editing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create the embedded `Entity<PlaygroundView>` configured for the mobile shell.
|
||||
pub(super) fn create_mobile_playground(
|
||||
theme: ThemeMode,
|
||||
viewport_w: f32,
|
||||
mode: PlaygroundMode,
|
||||
readonly: bool,
|
||||
gates: EditorGates,
|
||||
shared: Rc<RefCell<MobileDirShared>>,
|
||||
cx: &mut Context<super::MobileShellView>,
|
||||
) -> Entity<PlaygroundView> {
|
||||
@@ -220,9 +238,9 @@ pub(super) fn create_mobile_playground(
|
||||
};
|
||||
options.mode = mode;
|
||||
options.hide_chrome = true;
|
||||
options.page_readonly = readonly;
|
||||
options.edgeless_readonly = true;
|
||||
options.database_readonly = true;
|
||||
options.page_readonly = gates.page;
|
||||
options.edgeless_readonly = gates.edgeless;
|
||||
options.database_readonly = gates.page;
|
||||
|
||||
let open_shared = shared.clone();
|
||||
cx.new(|cx| {
|
||||
@@ -340,6 +358,8 @@ pub(super) struct EmbeddedPageEditor {
|
||||
dir_snapshot: Option<(String, u64, u64, crate::strings::MobileLocale)>,
|
||||
last_seen_view_sv: Vec<u8>,
|
||||
last_doc_rev: u64,
|
||||
/// Gates last applied to the editor; `None` until the first sync of a new editor.
|
||||
applied_gates: Option<EditorGates>,
|
||||
syncing: Rc<std::cell::Cell<bool>>,
|
||||
_observer: Option<ui::Subscription>,
|
||||
}
|
||||
@@ -366,11 +386,12 @@ impl EmbeddedPageEditor {
|
||||
state: &mut MobileAppState,
|
||||
doc_id: &str,
|
||||
content_w: f32,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<super::MobileShellView>,
|
||||
) -> Option<Entity<PlaygroundView>> {
|
||||
let resolved_theme = state.resolved_theme();
|
||||
state.doc_by_id(doc_id)?;
|
||||
let readonly = state.page_readonly(doc_id);
|
||||
let gates = EditorGates::for_doc(state, doc_id);
|
||||
let mode = match state.page_view_mode(doc_id) {
|
||||
DocMode::Page => PlaygroundMode::Page,
|
||||
DocMode::Edgeless => PlaygroundMode::Edgeless,
|
||||
@@ -406,6 +427,7 @@ impl EmbeddedPageEditor {
|
||||
self.entity = None;
|
||||
self._observer = None;
|
||||
self.loaded_doc = None;
|
||||
self.applied_gates = None;
|
||||
self.last_seen_view_sv.clear();
|
||||
}
|
||||
|
||||
@@ -416,7 +438,7 @@ impl EmbeddedPageEditor {
|
||||
resolved_theme,
|
||||
content_w,
|
||||
mode,
|
||||
readonly,
|
||||
gates,
|
||||
self.dir.clone(),
|
||||
cx,
|
||||
);
|
||||
@@ -500,7 +522,14 @@ impl EmbeddedPageEditor {
|
||||
let (doc_rev, next_sv) = entity.update(cx, |pv, cx| {
|
||||
pv.set_theme(pg_theme, cx);
|
||||
pv.set_mode_immediate(mode, cx);
|
||||
pv.set_page_readonly(readonly, cx);
|
||||
// A phone editor starts with Database edits gated, so the first sync applies the
|
||||
// gates too. Each gate change leaves the editor in one consistent state.
|
||||
if self.applied_gates != Some(gates) {
|
||||
pv.set_page_readonly(gates.page, cx);
|
||||
pv.set_readonly_immediate(gates.page, cx);
|
||||
pv.set_edgeless_readonly(gates.edgeless, window, cx);
|
||||
self.applied_gates = Some(gates);
|
||||
}
|
||||
let crdt_update = ws.doc_crdt_updates().get(doc_id).map(Vec::as_slice);
|
||||
if switched_doc && let Some(doc) = ws.doc(doc_id) {
|
||||
pv.edit_document(cx, |doc_state| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Mobile `Search` tab screen with UTF-16 highlight span rendering, focus caret,
|
||||
//! IME preedit underline, matched tag badges, vertical scroll, and clear button.
|
||||
//! Mobile `Search` tab screen with UTF-16 highlight span rendering, the shared field line (caret,
|
||||
//! selection, IME preedit underline), matched tag badges, vertical scroll, and clear button.
|
||||
|
||||
use affine_client::{DirectKind, Origin};
|
||||
use ui::{
|
||||
@@ -12,8 +12,9 @@ use ui_tokens::icons;
|
||||
use crate::{state::MobileAppState, strings::MobileStrings};
|
||||
|
||||
use super::{
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe, row_dir,
|
||||
utf16_to_byte,
|
||||
A11yBoundsMap, MobileFlexExt, MobilePalette, MobileShellView, a11y_bounds_probe,
|
||||
field_text::{FieldText, field_text},
|
||||
row_dir, utf16_to_byte,
|
||||
};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -31,86 +32,20 @@ pub(super) fn render_search(
|
||||
let hits = state.search_hits();
|
||||
let search_entity = cx.entity();
|
||||
|
||||
let mut input_text = row_dir(dir)
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.overflow_hidden()
|
||||
.gap(px(1.0));
|
||||
if state.search_query.is_empty() {
|
||||
if is_focused {
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.w(px(2.0))
|
||||
.h(px(18.0))
|
||||
.flex_shrink(0.0)
|
||||
.rounded(px(1.0))
|
||||
.bg(palette.accent),
|
||||
);
|
||||
}
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.0))
|
||||
.overflow_hidden()
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_muted)
|
||||
.align_start_for(dir)
|
||||
.child(strings.search_placeholder),
|
||||
);
|
||||
} else if let Some(pre) = state.search_preedit.clone() {
|
||||
let total = state.search_query.encode_utf16().count();
|
||||
let s = utf16_to_byte(&state.search_query, pre.start.min(total));
|
||||
let e = utf16_to_byte(
|
||||
&state.search_query,
|
||||
pre.end.min(total).max(pre.start.min(total)),
|
||||
);
|
||||
if s > 0 {
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_primary)
|
||||
.child(state.search_query[..s].to_string()),
|
||||
);
|
||||
}
|
||||
if e > s {
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.border_b_1()
|
||||
.border_color(palette.accent)
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_primary)
|
||||
.child(state.search_query[s..e].to_string()),
|
||||
);
|
||||
}
|
||||
if e < state.search_query.len() {
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_primary)
|
||||
.child(state.search_query[e..].to_string()),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.min_w(px(0.0))
|
||||
.overflow_hidden()
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_primary)
|
||||
.align_start_for(dir)
|
||||
.child(state.search_query.clone()),
|
||||
);
|
||||
if is_focused {
|
||||
input_text = input_text.child(
|
||||
div()
|
||||
.w(px(2.0))
|
||||
.h(px(18.0))
|
||||
.flex_shrink(0.0)
|
||||
.rounded(px(1.0))
|
||||
.bg(palette.accent),
|
||||
);
|
||||
}
|
||||
}
|
||||
let input_text = field_text(
|
||||
FieldText {
|
||||
id: "mobile.search.input",
|
||||
text: &state.search_query,
|
||||
selection: state.search_selection.clone(),
|
||||
reversed: state.search_reversed,
|
||||
preedit: state.search_preedit.clone(),
|
||||
placeholder: strings.search_placeholder,
|
||||
focused: is_focused,
|
||||
text_size: 14.0,
|
||||
},
|
||||
palette,
|
||||
dir,
|
||||
);
|
||||
|
||||
let mut search_bar = row_dir(dir)
|
||||
.id("mobile.search.input")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Mobile `Settings` view covering all 10 required sections (without `enable_editor_rtl`)
|
||||
//! with a `>= 44×44pt` back button and interactive preference toggles.
|
||||
//! Mobile `Settings` view covering all 10 required sections with a `>= 44×44pt` back button,
|
||||
//! preferences that cycle in place, and rows that open the workspace and `Experimental` sheets.
|
||||
|
||||
use ui::{
|
||||
Context, Direction, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement,
|
||||
@@ -9,10 +9,7 @@ use ui_kit::{LogicalStyled, bidi_isolate};
|
||||
use ui_tokens::icons;
|
||||
|
||||
use crate::{
|
||||
state::{
|
||||
MobileAppState, MobileBackCoordinator, MobileSheet, SettingRowInteraction, SettingsGroupId,
|
||||
ThemePreference,
|
||||
},
|
||||
state::{MobileAppState, MobileBackCoordinator, SettingRowInteraction, SettingsGroupId},
|
||||
strings::MobileStrings,
|
||||
};
|
||||
|
||||
@@ -29,7 +26,6 @@ pub(super) fn render_settings(
|
||||
a11y_bounds: &A11yBoundsMap,
|
||||
cx: &mut Context<MobileShellView>,
|
||||
) -> impl IntoElement {
|
||||
let locale = state.locale();
|
||||
let landscape = viewport_h < 520.0;
|
||||
|
||||
let back_btn = row_dir(dir)
|
||||
@@ -86,12 +82,6 @@ pub(super) fn render_settings(
|
||||
),
|
||||
);
|
||||
|
||||
let theme_label = match state.settings.theme_preference {
|
||||
ThemePreference::Light => strings.theme_light,
|
||||
ThemePreference::Dark => strings.theme_dark,
|
||||
ThemePreference::System => strings.theme_system,
|
||||
};
|
||||
|
||||
let mut rows: Vec<ui::AnyElement> = Vec::with_capacity(SettingsGroupId::ALL.len());
|
||||
for (idx, group) in SettingsGroupId::ALL.iter().copied().enumerate() {
|
||||
let top_border = if landscape {
|
||||
@@ -99,44 +89,7 @@ pub(super) fn render_settings(
|
||||
} else {
|
||||
idx > 0
|
||||
};
|
||||
let title = strings.settings_groups[idx];
|
||||
let value = match group {
|
||||
SettingsGroupId::Account => {
|
||||
if state.settings.account_email.trim().is_empty() {
|
||||
strings.sign_in_label.to_string()
|
||||
} else {
|
||||
state.settings.account_email.clone()
|
||||
}
|
||||
}
|
||||
SettingsGroupId::Workspace => state.active_workspace().summary.name.clone(),
|
||||
SettingsGroupId::Appearance => theme_label.to_string(),
|
||||
SettingsGroupId::Language => state.settings.locale.display_name().to_string(),
|
||||
SettingsGroupId::Editor => format!("{}%", state.settings.editor_font_scale_pct),
|
||||
SettingsGroupId::SyncOffline => {
|
||||
if state.settings.offline_sync_enabled {
|
||||
strings.toggle_on.to_string()
|
||||
} else {
|
||||
strings.toggle_off.to_string()
|
||||
}
|
||||
}
|
||||
SettingsGroupId::Storage => format!("{} MB", state.settings.cache_size_mb),
|
||||
SettingsGroupId::Notifications => {
|
||||
if state.settings.push_notifications {
|
||||
strings.toggle_on.to_string()
|
||||
} else {
|
||||
strings.toggle_off.to_string()
|
||||
}
|
||||
}
|
||||
SettingsGroupId::Experimental => {
|
||||
strings.flags_count(locale, state.settings.experimental_flags.len())
|
||||
}
|
||||
SettingsGroupId::About => {
|
||||
format!(
|
||||
"{} v{}",
|
||||
strings.about_version_label, state.settings.app_version
|
||||
)
|
||||
}
|
||||
};
|
||||
let value = state.setting_value(group);
|
||||
let display_value = if dir.is_rtl() {
|
||||
bidi_isolate(&value)
|
||||
} else {
|
||||
@@ -144,29 +97,7 @@ pub(super) fn render_settings(
|
||||
};
|
||||
|
||||
let interaction = group.interaction();
|
||||
let toggle_enabled = match group {
|
||||
SettingsGroupId::SyncOffline => state.settings.offline_sync_enabled,
|
||||
SettingsGroupId::Notifications => state.settings.push_notifications,
|
||||
_ => false,
|
||||
};
|
||||
let trailing: ui::AnyElement = match interaction {
|
||||
SettingRowInteraction::Toggle => div()
|
||||
.px(px(10.0))
|
||||
.py(px(4.0))
|
||||
.rounded(px(999.0))
|
||||
.bg(if toggle_enabled {
|
||||
palette.accent
|
||||
} else {
|
||||
palette.bg_pill
|
||||
})
|
||||
.text_size(px(12.0))
|
||||
.text_color(if toggle_enabled {
|
||||
ui::white()
|
||||
} else {
|
||||
palette.text_secondary
|
||||
})
|
||||
.child(display_value)
|
||||
.into_any_element(),
|
||||
SettingRowInteraction::Cycle => div()
|
||||
.px(px(10.0))
|
||||
.py(px(4.0))
|
||||
@@ -178,6 +109,23 @@ pub(super) fn render_settings(
|
||||
.text_color(palette.text_primary)
|
||||
.child(display_value)
|
||||
.into_any_element(),
|
||||
SettingRowInteraction::Sheet(_) => row_dir(dir)
|
||||
.gap(px(2.0))
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(12.0))
|
||||
.text_color(palette.text_secondary)
|
||||
.child(display_value),
|
||||
)
|
||||
.child(
|
||||
svg()
|
||||
.data(icons::ARROW_RIGHT_SMALL.svg.as_bytes())
|
||||
.mirror_in_rtl(true)
|
||||
.w(px(16.0))
|
||||
.h(px(16.0))
|
||||
.text_color(palette.text_muted),
|
||||
)
|
||||
.into_any_element(),
|
||||
SettingRowInteraction::Info => div()
|
||||
.text_size(px(12.0))
|
||||
.text_color(palette.text_secondary)
|
||||
@@ -185,11 +133,7 @@ pub(super) fn render_settings(
|
||||
.into_any_element(),
|
||||
};
|
||||
|
||||
let row_id = if interaction == SettingRowInteraction::Info {
|
||||
format!("mobile.settings.group.{idx}")
|
||||
} else {
|
||||
format!("mobile.settings.row.{}", group.a11y_key())
|
||||
};
|
||||
let row_id = group.a11y_id();
|
||||
let mut row = row_dir(dir)
|
||||
.id(row_id.clone())
|
||||
.snapshot(row_id.clone(), Some("mobile.shell.root"))
|
||||
@@ -205,21 +149,14 @@ pub(super) fn render_settings(
|
||||
div()
|
||||
.text_size(px(13.0))
|
||||
.text_color(palette.text_primary)
|
||||
.child(title),
|
||||
.child(strings.settings_groups[idx]),
|
||||
)
|
||||
.child(trailing);
|
||||
row = row.child(a11y_bounds_probe(row_id.clone(), a11y_bounds.clone()));
|
||||
.child(trailing)
|
||||
.child(a11y_bounds_probe(row_id, a11y_bounds.clone()));
|
||||
if interaction != SettingRowInteraction::Info {
|
||||
row = row.on_click(cx.listener(move |this, _, _, cx| {
|
||||
this.state.activate_setting(group);
|
||||
cx.notify();
|
||||
}));
|
||||
} else if group == SettingsGroupId::Workspace {
|
||||
let trigger_id = row_id;
|
||||
row = row.on_click(cx.listener(move |this, _, _, cx| {
|
||||
let t = this.now_ms(cx);
|
||||
this.state
|
||||
.open_sheet_from(MobileSheet::WorkspaceSelector, Some(&trigger_id), t);
|
||||
this.state.activate_setting(group, t);
|
||||
cx.notify();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//! Closed-form animated mobile bottom sheets (`Location & Trail`, `Backlinks`,
|
||||
//! `WorkspaceSelector`, `DocActions` and its `Table of contents` and journal conflict sheets)
|
||||
//! with closing-transition content retention and input release.
|
||||
//! `WorkspaceSelector`, `Experimental`, `DocActions` and its `View Info`, `Table of contents`,
|
||||
//! and journal conflict sheets) with closing-transition content retention and input release.
|
||||
|
||||
use std::{cell::Cell, rc::Rc};
|
||||
|
||||
use affine_client::{BreadcrumbAction, ContextState, LocationChoice, Origin};
|
||||
use ui::{
|
||||
Context, Direction, Hsla, InteractiveElement, IntoElement, ParentElement,
|
||||
Context, Direction, FocusHandle, Hsla, InteractiveElement, IntoElement, ParentElement,
|
||||
StatefulInteractiveElement, Styled, canvas, div, px,
|
||||
};
|
||||
use ui_kit::LogicalStyled;
|
||||
@@ -28,6 +28,7 @@ pub(super) fn render_active_sheet(
|
||||
viewport_h: f32,
|
||||
progress: f32,
|
||||
accepts_input: bool,
|
||||
text_focus: (&FocusHandle, bool),
|
||||
palette: MobilePalette,
|
||||
dir: Direction,
|
||||
strings: &'static MobileStrings,
|
||||
@@ -41,6 +42,7 @@ pub(super) fn render_active_sheet(
|
||||
viewport_h,
|
||||
progress,
|
||||
accepts_input,
|
||||
text_focus,
|
||||
palette,
|
||||
dir,
|
||||
strings,
|
||||
@@ -49,7 +51,10 @@ pub(super) fn render_active_sheet(
|
||||
)
|
||||
.into_any_element();
|
||||
}
|
||||
let palette = if matches!(sheet_kind, MobileSheet::DocActions | MobileSheet::Toc) {
|
||||
let palette = if matches!(
|
||||
sheet_kind,
|
||||
MobileSheet::DocActions | MobileSheet::Toc | MobileSheet::DocInfo
|
||||
) {
|
||||
let theme = state.resolved_theme();
|
||||
MobilePalette {
|
||||
accent: ui::rgba(ui_tokens::tokens::theme(theme).link.to_u32()).into(),
|
||||
@@ -66,20 +71,7 @@ pub(super) fn render_active_sheet(
|
||||
};
|
||||
let p = progress.clamp(0.0, 1.0);
|
||||
let compact = viewport_h < 460.0;
|
||||
let title = match sheet_kind {
|
||||
MobileSheet::WorkspaceSelector => strings.switch_workspace,
|
||||
MobileSheet::WorkspaceDrawer => strings.drawer_title,
|
||||
MobileSheet::DocActions => strings.doc_actions_title,
|
||||
MobileSheet::LocationAndTrail => strings.location_trail_title,
|
||||
MobileSheet::Backlinks => strings.backlinks_label,
|
||||
MobileSheet::ConfirmDeleteDoc => strings.confirm_delete_title,
|
||||
MobileSheet::ConfirmTrashDoc => strings.confirm_trash_title,
|
||||
MobileSheet::Toc => strings.toc_title,
|
||||
MobileSheet::JournalConflicts | MobileSheet::JournalConflictOps => {
|
||||
strings.journal_conflicts
|
||||
}
|
||||
MobileSheet::None => "",
|
||||
};
|
||||
let title = sheet_kind.title(strings);
|
||||
|
||||
let mut content = div().w_full().flex().flex_col().gap(px(10.0));
|
||||
|
||||
@@ -583,6 +575,29 @@ pub(super) fn render_active_sheet(
|
||||
),
|
||||
);
|
||||
}
|
||||
MobileSheet::Experimental => {
|
||||
content = content.child(super::experimental_sheet::render_experimental_content(
|
||||
state,
|
||||
accepts_input,
|
||||
palette,
|
||||
dir,
|
||||
strings,
|
||||
a11y_bounds,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
MobileSheet::DocInfo => {
|
||||
content = content.child(super::doc_info_sheet::render_doc_info_content(
|
||||
state,
|
||||
compact,
|
||||
accepts_input,
|
||||
palette,
|
||||
dir,
|
||||
strings,
|
||||
a11y_bounds,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
MobileSheet::WorkspaceDrawer | MobileSheet::None => {}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ pub(super) fn render_doc_actions_content(
|
||||
DocAction::DefaultMode(DocMode::Page) => icons::PAGE,
|
||||
DocAction::Favorite { favorited: true } => icons::FAVORITED,
|
||||
DocAction::Favorite { favorited: false } => icons::FAVORITE,
|
||||
DocAction::ViewInfo => icons::INFORMATION,
|
||||
DocAction::LocationTrail => icons::FOLDER,
|
||||
DocAction::Toc => icons::TOC,
|
||||
DocAction::JournalConflicts => icons::TODAY,
|
||||
@@ -128,6 +129,11 @@ pub(super) fn render_doc_actions_content(
|
||||
this.toggle_favorite_action(&ws_id, &doc_id, t);
|
||||
this.state.close_sheet(t);
|
||||
}
|
||||
DocAction::ViewInfo => this.state.open_sheet_from(
|
||||
MobileSheet::DocInfo,
|
||||
Some("mobile.page.more_btn"),
|
||||
t,
|
||||
),
|
||||
DocAction::LocationTrail => this.state.open_sheet_from(
|
||||
MobileSheet::LocationAndTrail,
|
||||
Some("mobile.page.more_btn"),
|
||||
|
||||
@@ -373,10 +373,20 @@ impl MobileWorkspaceBridge {
|
||||
{
|
||||
return;
|
||||
}
|
||||
let (persisted_pages, journals, favorites, edgeless) = {
|
||||
let (persisted_pages, journals, favorites, edgeless, tags) = {
|
||||
let dir = self.session.directory().lock_directory();
|
||||
let db = dir.db();
|
||||
let pages = db.root().list_pages().unwrap_or_default();
|
||||
// The tag options of `meta.properties.tags` are the only tags a document can carry.
|
||||
let tags: Vec<(String, String)> = db
|
||||
.root()
|
||||
.navigation_tags()
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|tag| (tag.id, tag.name))
|
||||
.collect();
|
||||
let prop_rows = db
|
||||
.db_table(WorkspaceDbTableName::DocProperties)
|
||||
.and_then(|table| table.list_rows::<DocPropertiesRow>().ok())
|
||||
@@ -400,7 +410,7 @@ impl MobileWorkspaceBridge {
|
||||
favorites.insert(row.id);
|
||||
}
|
||||
}
|
||||
(pages, journals, favorites, edgeless)
|
||||
(pages, journals, favorites, edgeless, tags)
|
||||
};
|
||||
let persisted_ids: HashSet<String> = persisted_pages.iter().map(|p| p.id.clone()).collect();
|
||||
let ws_id = state.active_workspace_id().to_string();
|
||||
@@ -436,9 +446,14 @@ impl MobileWorkspaceBridge {
|
||||
}
|
||||
}
|
||||
let ws = state.active_workspace_mut();
|
||||
if ws.tags != tags {
|
||||
ws.tags = tags;
|
||||
}
|
||||
let mut added = Vec::new();
|
||||
for page in persisted_pages {
|
||||
let updated_at_ms = page.updated_date_ms.unwrap_or(page.create_date_ms);
|
||||
ws.doc_created_ms
|
||||
.insert(page.id.clone(), page.create_date_ms);
|
||||
let journal_date = journals.get(&page.id).cloned();
|
||||
let is_favorite = favorites.contains(&page.id);
|
||||
let primary_mode = if edgeless.contains(&page.id) {
|
||||
|
||||
@@ -145,6 +145,23 @@ impl MobileWorkspaceBridge {
|
||||
Ok(changed)
|
||||
}
|
||||
|
||||
/// Persist the tag IDs of `doc_id` in `meta.pages` and mirror them into `MobileAppState`.
|
||||
pub fn set_doc_tags(
|
||||
&mut self,
|
||||
state: &mut MobileAppState,
|
||||
ws_id: &str,
|
||||
doc_id: &str,
|
||||
tags: Vec<String>,
|
||||
now_ms: i64,
|
||||
) -> ClientResult<bool> {
|
||||
if ws_id != self.session.space_id() || !state.doc_by_id(doc_id).is_some_and(|d| !d.trashed)
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
self.session.set_document_tags(doc_id, &tags, now_ms)?;
|
||||
Ok(state.set_doc_tags_scoped(ws_id, doc_id, tags))
|
||||
}
|
||||
|
||||
/// Persist a primary mode in `db$docProperties` and mirror into `MobileAppState`.
|
||||
pub fn set_doc_primary_mode(
|
||||
&mut self,
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
//! dispatch, multi-workspace isolation, Explorer drill-down & ancestor breadcrumbs,
|
||||
//! `d0 -> cur` location pick + `Return to Trail`, Search focus + keyboard + IME commit,
|
||||
//! live frame-1 `published_a11y_tree` Dialog children + focus restoration, closing-sheet
|
||||
//! content retention & click-through, and compact `568x320` landscape sheet reachability.
|
||||
//! content retention & click-through, compact `568x320` landscape sheet reachability, editor
|
||||
//! write gates, `Experimental` and `View Info` sheets, the journal week strip, and the typed
|
||||
//! drawer filter.
|
||||
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
@@ -489,9 +491,24 @@ fn compact_landscape_location_sheet_keeps_owner_locations_and_use_trail_reachabl
|
||||
);
|
||||
|
||||
// Pick cur's own location, reopen sheet, and verify `Return to Trail` is mounted and >= 44x44.
|
||||
// The compact menu scrolls its rows, so the reopen goes through the accessibility actions.
|
||||
t.click_id("mobile.sheet.loc.0");
|
||||
t.click_id("mobile.page.more_btn");
|
||||
t.click_id("mobile.sheet.doc_action.location_trail");
|
||||
t.app
|
||||
.update(|cx| {
|
||||
t.window_handle.update(cx, |v, _, cx| {
|
||||
assert!(v.perform_a11y_action(
|
||||
"mobile.sheet.doc_action.location_trail",
|
||||
MobileA11yAction::Activate,
|
||||
cx,
|
||||
));
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
t.platform.run_until_parked();
|
||||
t.platform.advance_clock(Duration::from_millis(400));
|
||||
t.platform.run_until_parked();
|
||||
t.headless_win.request_frame();
|
||||
let use_trail_bounds = t
|
||||
.app
|
||||
.update(|cx| {
|
||||
@@ -2163,3 +2180,297 @@ fn journals_tab_publishes_conflict_row_and_opens_a_same_day_journal() {
|
||||
"a date with one journal or none has no conflict row"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_gates_follow_the_readonly_toggle_and_the_edgeless_editing_flag() {
|
||||
use playground::PlaygroundMode;
|
||||
|
||||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||||
t.click_id("mobile.home.doc.doc-arch");
|
||||
// `(page, database, edgeless)` read-only gates of the embedded editor.
|
||||
let gates = |t: &TestApp| {
|
||||
t.read(|v, cx| {
|
||||
let pv = v.page_editor().expect("editor").read(cx);
|
||||
(
|
||||
pv.page_readonly(),
|
||||
pv.database_readonly(),
|
||||
pv.edgeless_readonly(),
|
||||
)
|
||||
})
|
||||
};
|
||||
assert_eq!(
|
||||
gates(&t),
|
||||
(false, false, true),
|
||||
"an editable doc unlocks Database"
|
||||
);
|
||||
t.click_id("mobile.page.readonly_toggle");
|
||||
assert_eq!(gates(&t), (true, true, true));
|
||||
t.click_id("mobile.page.readonly_toggle");
|
||||
|
||||
t.click_id("mobile.page.back_btn");
|
||||
t.click_id("mobile.home.settings_btn");
|
||||
t.click_id("mobile.settings.row.experimental");
|
||||
assert_eq!(
|
||||
t.read(|v, _| v.state.active_sheet),
|
||||
MobileSheet::Experimental
|
||||
);
|
||||
t.click_id("mobile.sheet.experimental.enable_mobile_edgeless_editing");
|
||||
let (enabled, checked) = t.read(|v, _| {
|
||||
(
|
||||
v.state.settings.enable_mobile_edgeless_editing,
|
||||
v.published_a11y_tree().nodes["mobile.sheet.experimental.enable_mobile_edgeless_editing"]
|
||||
.state
|
||||
.checked,
|
||||
)
|
||||
});
|
||||
assert_eq!((enabled, checked), (true, Some(true)));
|
||||
t.click_id("mobile.sheet.done_btn");
|
||||
t.click_id("mobile.settings.back_btn");
|
||||
|
||||
t.click_id("mobile.home.doc.doc-arch");
|
||||
t.click_id("mobile.page.more_btn");
|
||||
t.click_id("mobile.sheet.doc_action.mode.edgeless");
|
||||
let mode = t.read(|v, cx| v.page_editor().expect("editor").read(cx).mode());
|
||||
assert_eq!(mode, PlaygroundMode::Edgeless);
|
||||
assert_eq!(
|
||||
gates(&t),
|
||||
(false, false, false),
|
||||
"the flag unlocks Edgeless edits"
|
||||
);
|
||||
assert!(t.has_element("mobile.page.readonly_toggle"));
|
||||
t.click_id("mobile.page.readonly_toggle");
|
||||
assert_eq!(gates(&t), (true, true, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn view_info_sheet_toggles_doc_tags_and_lists_times_and_link_counts() {
|
||||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||||
let ws = state.active_workspace_mut();
|
||||
ws.doc_created_ms
|
||||
.insert("doc-arch".into(), 1_763_712_000_000);
|
||||
ws.doc_mut("doc-arch").expect("doc").updated_at_ms = 1_764_072_000_000;
|
||||
let t = TestApp::launch_with_state(390, 844, state);
|
||||
t.click_id("mobile.home.doc.doc-arch");
|
||||
t.click_id("mobile.page.more_btn");
|
||||
t.click_id("mobile.sheet.doc_action.view_info");
|
||||
assert_eq!(t.read(|v, _| v.state.active_sheet), MobileSheet::DocInfo);
|
||||
let tags = |t: &TestApp| t.read(|v, _| v.state.doc_by_id("doc-arch").unwrap().tags.clone());
|
||||
for expected in [vec!["rust", "mobile", "sync"], vec!["rust", "mobile"]] {
|
||||
t.click_id("mobile.sheet.doc_info.tag.sync");
|
||||
assert_eq!(tags(&t), expected);
|
||||
}
|
||||
t.click_id("mobile.sheet.doc_info.tag.rust");
|
||||
assert_eq!(tags(&t), vec!["mobile"]);
|
||||
let (names, rust_checked, errors) = t.read(|v, _| {
|
||||
let tree = v.published_a11y_tree();
|
||||
(
|
||||
[
|
||||
"mobile.sheet.doc_info.created",
|
||||
"mobile.sheet.doc_info.updated",
|
||||
"mobile.sheet.doc_info.backlinks",
|
||||
"mobile.sheet.doc_info.outgoing_links",
|
||||
]
|
||||
.map(|id| tree.nodes[id].name.clone()),
|
||||
tree.nodes["mobile.sheet.doc_info.tag.rust"].state.checked,
|
||||
validate_accessibility_tree(tree),
|
||||
)
|
||||
});
|
||||
assert_eq!(
|
||||
names,
|
||||
[
|
||||
"Created: 2025-11-21 08:00".to_string(),
|
||||
"Updated: 2025-11-25 12:00".to_string(),
|
||||
"Backlinks: 2".to_string(),
|
||||
"Outgoing links: 0".to_string(),
|
||||
]
|
||||
);
|
||||
assert_eq!(rust_checked, Some(false));
|
||||
assert!(errors.is_empty(), "{errors:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn journal_strip_returns_to_today_and_opens_a_dated_journal_in_place_or_an_empty_day_on_the_journals_tab()
|
||||
{
|
||||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||||
let ws = state.active_workspace_mut();
|
||||
let mut monday = ws.doc("doc-journal").expect("journal").clone();
|
||||
monday.id = "doc-journal-monday".into();
|
||||
monday.journal_date = Some("2026-11-23".into());
|
||||
ws.docs_mut().push(monday);
|
||||
let t = TestApp::launch_with_state(390, 844, state);
|
||||
t.app
|
||||
.update(|cx| {
|
||||
t.window_handle.update(cx, |v, _, cx| {
|
||||
v.state.open_doc("doc-journal", Origin::Journal);
|
||||
cx.notify();
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
let can_back = |t: &TestApp| t.read(|v, _| v.state.active_workspace().history.can_back());
|
||||
let back_before = can_back(&t);
|
||||
assert!(!t.has_element("mobile.page.journal_strip.today_btn"));
|
||||
|
||||
// Two weeks back from today's journal, `Today` returns the strip without navigating.
|
||||
t.click_id("mobile.page.journal_strip.prev_btn");
|
||||
t.click_id("mobile.page.journal_strip.prev_btn");
|
||||
assert!(t.has_element("mobile.page.journal_strip.day.2026-11-09"));
|
||||
let today_node = t.read(|v, _| {
|
||||
v.published_a11y_tree()
|
||||
.nodes
|
||||
.contains_key("mobile.page.journal_strip.today_btn")
|
||||
});
|
||||
assert!(today_node);
|
||||
t.click_id("mobile.page.journal_strip.today_btn");
|
||||
assert!(t.has_element("mobile.page.journal_strip.day.2026-11-25"));
|
||||
assert!(!t.has_element("mobile.page.journal_strip.today_btn"));
|
||||
let route = t.read(|v, _| v.state.route.clone());
|
||||
assert_eq!(route, MobileRoute::Page("doc-journal".into()));
|
||||
assert_eq!(
|
||||
can_back(&t),
|
||||
back_before,
|
||||
"returning the strip keeps the history"
|
||||
);
|
||||
|
||||
t.click_id("mobile.page.journal_strip.day.2026-11-23");
|
||||
let route = t.read(|v, _| v.state.route.clone());
|
||||
assert_eq!(route, MobileRoute::Page("doc-journal-monday".into()));
|
||||
assert_eq!(
|
||||
can_back(&t),
|
||||
back_before,
|
||||
"the picked journal replaces the entry"
|
||||
);
|
||||
t.click_id("mobile.page.journal_strip.today_btn");
|
||||
let route = t.read(|v, _| v.state.route.clone());
|
||||
assert_eq!(route, MobileRoute::Page("doc-journal".into()));
|
||||
|
||||
t.click_id("mobile.page.journal_strip.prev_btn");
|
||||
assert!(t.has_element("mobile.page.journal_strip.day.2026-11-16"));
|
||||
t.click_id("mobile.page.journal_strip.next_btn");
|
||||
t.click_id("mobile.page.journal_strip.day.2026-11-27");
|
||||
let (route, date) =
|
||||
t.read(|v, _| (v.state.route.clone(), v.state.selected_journal_date.clone()));
|
||||
assert_eq!(
|
||||
(route, date.as_str()),
|
||||
(MobileRoute::Journals, "2026-11-27")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drawer_filter_takes_ime_text_moves_and_draws_the_caret_filters_rows_and_clears() {
|
||||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||||
t.click_id("mobile.home.doc.doc-arch");
|
||||
t.click_id("mobile.page.drawer_btn");
|
||||
t.click_id("mobile.drawer.filter_bar");
|
||||
let key = |t: &TestApp, keystroke: &'static str| {
|
||||
t.headless_win
|
||||
.dispatch_input(PlatformInput::KeyDown(KeyDownEvent {
|
||||
keystroke: Keystroke::parse(keystroke).unwrap(),
|
||||
is_held: false,
|
||||
prefer_character_input: false,
|
||||
}));
|
||||
t.platform.run_until_parked();
|
||||
};
|
||||
let typed = |t: &TestApp, text: &'static str| {
|
||||
t.app
|
||||
.update(|cx| {
|
||||
t.window_handle.update(cx, |v, window, cx| {
|
||||
v.replace_text_in_range(None, text, window, cx);
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
t.platform.run_until_parked();
|
||||
};
|
||||
t.app
|
||||
.update(|cx| {
|
||||
t.window_handle.update(cx, |v, window, cx| {
|
||||
v.replace_and_mark_text_in_range(None, "Sy", None, window, cx);
|
||||
assert_eq!(v.marked_text_range(window, cx), Some(0..2));
|
||||
v.replace_text_in_range(None, "Syc", window, cx);
|
||||
assert_eq!(v.text_length_utf16(window, cx), Some(3));
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
t.platform.run_until_parked();
|
||||
assert!(!t.has_element("mobile.drawer.doc.doc-sync"));
|
||||
let caret_x = |t: &TestApp| {
|
||||
t.headless_win.request_frame();
|
||||
t.app
|
||||
.update(|cx| {
|
||||
t.window_handle.update(cx, |_, window, _| {
|
||||
window.frame_snapshot().elements["mobile.drawer.filter_bar.caret"]
|
||||
.bounds
|
||||
.x
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
let at_end = caret_x(&t);
|
||||
|
||||
// A typo fixed in place: `Left` then `n` turns `Syc` into `Sync`, and the caret is drawn
|
||||
// where it inserts.
|
||||
key(&t, "left");
|
||||
assert!(caret_x(&t) < at_end, "the caret moves into the word");
|
||||
typed(&t, "n");
|
||||
assert_eq!(t.read(|v, _| v.state.drawer_filter.clone()), "Sync");
|
||||
assert!(t.has_element("mobile.drawer.doc.doc-sync"));
|
||||
assert!(!t.has_element("mobile.drawer.doc.doc-arch"));
|
||||
|
||||
// `End`, `Home`, then `Shift+Right`: each frame draws the field differently, as the caret
|
||||
// moves to the start and the first character gets the selection highlight.
|
||||
let field_pixels = |t: &TestApp| {
|
||||
t.headless_win.request_frame();
|
||||
t.app
|
||||
.update(|cx| {
|
||||
t.window_handle.update(cx, |_, window, _| {
|
||||
let b = window.frame_snapshot().elements["mobile.drawer.filter_bar"].bounds;
|
||||
let image = window.render_to_image().expect("render frame");
|
||||
let width = image.width() as usize;
|
||||
let raw = image.as_raw();
|
||||
let mut pixels = Vec::new();
|
||||
for y in b.y as usize..(b.y + b.height) as usize {
|
||||
let row = (y * width + b.x as usize) * 4;
|
||||
pixels.extend_from_slice(&raw[row..row + b.width as usize * 4]);
|
||||
}
|
||||
pixels
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
let mut frames = Vec::new();
|
||||
for k in ["end", "home", "shift-right"] {
|
||||
key(&t, k);
|
||||
frames.push(field_pixels(&t));
|
||||
}
|
||||
let selection = t.read(|v, _| v.state.drawer_filter_selection.clone());
|
||||
assert_eq!(selection, 0..1);
|
||||
for (a, b) in [(0, 1), (1, 2), (0, 2)] {
|
||||
assert_ne!(
|
||||
frames[a], frames[b],
|
||||
"frames {a} and {b} draw the same field"
|
||||
);
|
||||
}
|
||||
key(&t, "end");
|
||||
|
||||
for (keys, text, filter) in [
|
||||
(&["home", "shift-right"][..], "X", "Xync"),
|
||||
(&["end", "backspace"][..], "", "Xyn"),
|
||||
(&["cmd-a"][..], "Sync", "Sync"),
|
||||
] {
|
||||
for k in keys {
|
||||
key(&t, k);
|
||||
}
|
||||
if !text.is_empty() {
|
||||
typed(&t, text);
|
||||
}
|
||||
assert_eq!(
|
||||
t.read(|v, _| v.state.drawer_filter.clone()),
|
||||
filter,
|
||||
"{keys:?}"
|
||||
);
|
||||
}
|
||||
|
||||
t.click_id("mobile.drawer.filter_clear_btn");
|
||||
let (filter, sheet) = t.read(|v, _| (v.state.drawer_filter.clone(), v.state.active_sheet));
|
||||
assert_eq!((filter.as_str(), sheet), ("", MobileSheet::WorkspaceDrawer));
|
||||
assert!(t.has_element("mobile.drawer.doc.doc-arch"));
|
||||
}
|
||||
@@ -174,9 +174,9 @@ fn workspace_drawer_doc_switch_media_undo_and_production_a11y_tree() {
|
||||
page_tree.nodes["mobile.page.title"].role,
|
||||
AccessibilityRole::Heading
|
||||
);
|
||||
assert_eq!(
|
||||
page_tree.nodes["mobile.page.sync_status"].role,
|
||||
AccessibilityRole::Status
|
||||
assert!(
|
||||
!page_tree.nodes.contains_key("mobile.page.sync_status"),
|
||||
"the page header carries no sync status of its own"
|
||||
);
|
||||
assert_eq!(
|
||||
page_tree.nodes[&format!("mobile.page.block.{}", img_res.block_id)].role,
|
||||
@@ -410,17 +410,23 @@ fn mobile_shell_locale_back_doc_actions_journals_settings_search_and_backlinks()
|
||||
));
|
||||
assert_eq!(state.selected_journal_date, "2026-11-25");
|
||||
|
||||
// Settings Editor font scale + SyncOffline status.
|
||||
// Settings Editor font scale; Sync & Offline only reports the workspace sync status.
|
||||
state.open_settings();
|
||||
assert!(state.activate_setting(SettingsGroupId::Editor));
|
||||
assert!(state.activate_setting(SettingsGroupId::Editor, 115.0));
|
||||
assert!((state.font_scale - 1.15).abs() < 0.01);
|
||||
assert!(state.activate_setting(SettingsGroupId::SyncOffline));
|
||||
assert!(!state.activate_setting(SettingsGroupId::SyncOffline, 115.0));
|
||||
assert_eq!(
|
||||
state.active_workspace().sync_status,
|
||||
WorkspaceSyncStatus::Offline
|
||||
WorkspaceSyncStatus::Synced
|
||||
);
|
||||
let settings_tree = build_accessibility_tree(&mut state, 390.0, 844.0);
|
||||
assert!(settings_tree.nodes.contains_key("mobile.settings.group.0"));
|
||||
assert_eq!(
|
||||
settings_tree.nodes["mobile.settings.group.5"]
|
||||
.value
|
||||
.as_deref(),
|
||||
Some("Synced")
|
||||
);
|
||||
assert!(
|
||||
settings_tree
|
||||
.nodes
|
||||
|
||||
@@ -5,6 +5,7 @@ mod crdt_media;
|
||||
mod editor_interaction;
|
||||
mod remote_delete;
|
||||
mod sqlite_bridge;
|
||||
mod sqlite_doc_tags;
|
||||
mod sqlite_lifecycle;
|
||||
mod sqlite_sync_tick;
|
||||
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
//! `View Info` tags of a connected SQLite workspace: the tag options of the workspace root, and
|
||||
//! tag writes that stay inside them across a cold reopen.
|
||||
|
||||
use affine_client::{HostKind, SqliteWorkspaceStore, WorkspaceSession};
|
||||
use affine_mobile::{
|
||||
MobileA11yAction, MobileLocale, MobileSheet, MobileShellView, MobileWorkspaceBridge,
|
||||
register_mobile_fonts, seed_showcase_state,
|
||||
};
|
||||
use affine_store::workspace_db::{NavigationEdit, WorkspaceTag};
|
||||
use ui::{
|
||||
Application, Bounds, HeadlessPlatform, WindowBounds, WindowHandle, WindowOptions, point,
|
||||
prelude::*, px, size,
|
||||
};
|
||||
use ui_tokens::ThemeMode;
|
||||
|
||||
/// The primary showcase workspace, so the shell scope and the session space agree.
|
||||
const WS_ID: &str = "ws-mobile-rust";
|
||||
|
||||
async fn load(store: &SqliteWorkspaceStore, client_id: u64, now_ms: i64) -> WorkspaceSession {
|
||||
store
|
||||
.load_workspace_session(
|
||||
"u-demo",
|
||||
client_id,
|
||||
HostKind::Native,
|
||||
"local",
|
||||
"https://app.affine.pro",
|
||||
now_ms,
|
||||
)
|
||||
.await
|
||||
.expect("load session")
|
||||
}
|
||||
|
||||
/// `(tag IDs of every page, tag IDs the root defines)` of a session.
|
||||
fn page_tags_and_defined(session: &WorkspaceSession) -> (Vec<(String, Vec<String>)>, Vec<String>) {
|
||||
let dir = session.directory().lock_directory();
|
||||
let root = dir.db().root();
|
||||
let pages = root
|
||||
.list_pages()
|
||||
.expect("list pages")
|
||||
.into_iter()
|
||||
.map(|page| (page.id, page.tags))
|
||||
.collect();
|
||||
let defined = root.defined_tag_ids().expect("defined tags");
|
||||
(pages, defined.into_iter().collect())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn view_info_lists_root_tags_and_writes_only_defined_tag_ids_across_reopen() {
|
||||
let base_dir = std::env::temp_dir().join(format!(
|
||||
"affine-mobile-view-info-tags-{}",
|
||||
std::process::id()
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&base_dir);
|
||||
let store = SqliteWorkspaceStore::open(&base_dir, "workspace", "local", WS_ID)
|
||||
.await
|
||||
.expect("open sqlite store");
|
||||
let mut bridge = MobileWorkspaceBridge::new(load(&store, 9811, 1_000).await);
|
||||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-28");
|
||||
bridge.sync_into_state(&mut state, 1_010);
|
||||
let doc_id = bridge
|
||||
.create_and_open_document_in_folder(&mut state, "Proof", None, None, 1_020)
|
||||
.expect("create doc")
|
||||
.id
|
||||
.as_str()
|
||||
.to_string();
|
||||
let session = bridge.session_mut();
|
||||
session
|
||||
.edit_workspace_navigation(
|
||||
&NavigationEdit::CreateTag(WorkspaceTag {
|
||||
id: "tag-proof".into(),
|
||||
name: "Manuscript".into(),
|
||||
color: "var(--affine-tag-blue)".into(),
|
||||
}),
|
||||
1_030,
|
||||
)
|
||||
.expect("define tag");
|
||||
session
|
||||
.set_document_tags(&doc_id, &["tag-proof".to_string()], 1_040)
|
||||
.expect("tag doc");
|
||||
bridge
|
||||
.flush_session_mutations(&state, &store, 1_050)
|
||||
.await
|
||||
.expect("flush");
|
||||
store.checkpoint().await.expect("checkpoint");
|
||||
store.close().await;
|
||||
|
||||
// Cold reopen behind a fresh showcase state, whose own tags are `Rust` and `Sync`.
|
||||
let store = SqliteWorkspaceStore::open(&base_dir, "workspace", "local", WS_ID)
|
||||
.await
|
||||
.expect("reopen sqlite store");
|
||||
let bridge = MobileWorkspaceBridge::new(load(&store, 9812, 2_000).await);
|
||||
let state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-28");
|
||||
let platform = HeadlessPlatform::new(390, 844, 1.0);
|
||||
let handle: std::rc::Rc<std::cell::RefCell<Option<WindowHandle<MobileShellView>>>> =
|
||||
Default::default();
|
||||
let handle_out = handle.clone();
|
||||
let app = Application::with_platform(platform.clone()).run_embedded(move |cx| {
|
||||
register_mobile_fonts(cx).expect("register mobile fonts");
|
||||
let win = cx
|
||||
.open_window(
|
||||
WindowOptions {
|
||||
window_bounds: Some(WindowBounds::Windowed(Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
size(px(390.0), px(844.0)),
|
||||
))),
|
||||
..WindowOptions::default()
|
||||
},
|
||||
|_, cx| cx.new(|cx| MobileShellView::with_workspace_bridge(state, bridge, cx)),
|
||||
)
|
||||
.expect("open mobile window");
|
||||
*handle_out.borrow_mut() = Some(win);
|
||||
});
|
||||
let window = handle.borrow_mut().take().expect("window");
|
||||
let headless = platform
|
||||
.windows()
|
||||
.into_iter()
|
||||
.next()
|
||||
.expect("headless window");
|
||||
let open_doc_id = doc_id.clone();
|
||||
app.update(|cx| {
|
||||
window.update(cx, |v, _, cx| {
|
||||
v.state.open_document(&open_doc_id, 0.0);
|
||||
v.state.open_sheet(MobileSheet::DocInfo, 0.0);
|
||||
v.state.settle_animations(500.0);
|
||||
cx.notify();
|
||||
})
|
||||
})
|
||||
.expect("open View Info");
|
||||
platform.run_until_parked();
|
||||
headless.request_frame();
|
||||
|
||||
let tag_rows = |app: &ui::ApplicationHandle| {
|
||||
app.update(|cx| {
|
||||
window.update(cx, |v, _, _| {
|
||||
v.published_a11y_tree()
|
||||
.nodes
|
||||
.values()
|
||||
.filter(|n| n.id.starts_with("mobile.sheet.doc_info.tag."))
|
||||
.map(|n| (n.id.clone(), n.name.clone(), n.state.checked))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
})
|
||||
.expect("read tree")
|
||||
};
|
||||
assert_eq!(
|
||||
tag_rows(&app),
|
||||
vec![(
|
||||
"mobile.sheet.doc_info.tag.tag-proof".to_string(),
|
||||
"Manuscript".to_string(),
|
||||
Some(true)
|
||||
)],
|
||||
"View Info lists the root tags only"
|
||||
);
|
||||
|
||||
for expected in [Vec::<String>::new(), vec!["tag-proof".to_string()]] {
|
||||
let tags = app
|
||||
.update(|cx| {
|
||||
window.update(cx, |v, _, cx| {
|
||||
assert!(v.perform_a11y_action(
|
||||
"mobile.sheet.doc_info.tag.tag-proof",
|
||||
MobileA11yAction::Activate,
|
||||
cx,
|
||||
));
|
||||
v.state.doc_by_id(&doc_id).expect("doc").tags.clone()
|
||||
})
|
||||
})
|
||||
.expect("toggle tag");
|
||||
assert_eq!(tags, expected);
|
||||
}
|
||||
// A showcase tag ID is no row of this workspace and writes nothing.
|
||||
let rust = app
|
||||
.update(|cx| {
|
||||
window.update(cx, |v, _, cx| {
|
||||
v.perform_a11y_action(
|
||||
"mobile.sheet.doc_info.tag.rust",
|
||||
MobileA11yAction::Activate,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
})
|
||||
.expect("toggle showcase tag");
|
||||
assert!(!rust);
|
||||
|
||||
let (mut bridge, state) = app
|
||||
.update(|cx| {
|
||||
window.update(cx, |v, _, _| {
|
||||
let bridge = v
|
||||
.take_workspace_bridge(3_000)
|
||||
.expect("mounted bridge")
|
||||
.expect("detach bridge");
|
||||
let state = std::mem::replace(
|
||||
&mut v.state,
|
||||
seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-28"),
|
||||
);
|
||||
(bridge, state)
|
||||
})
|
||||
})
|
||||
.expect("detach");
|
||||
bridge
|
||||
.flush_session_mutations(&state, &store, 3_010)
|
||||
.await
|
||||
.expect("flush");
|
||||
store.checkpoint().await.expect("checkpoint");
|
||||
store.close().await;
|
||||
|
||||
let store = SqliteWorkspaceStore::open(&base_dir, "workspace", "local", WS_ID)
|
||||
.await
|
||||
.expect("third open");
|
||||
let (pages, defined) = page_tags_and_defined(&load(&store, 9813, 4_000).await);
|
||||
assert_eq!(defined, vec!["tag-proof".to_string()]);
|
||||
assert!(
|
||||
pages
|
||||
.iter()
|
||||
.all(|(_, tags)| tags.iter().all(|t| defined.contains(t))),
|
||||
"every page tag is a root tag: {pages:?}"
|
||||
);
|
||||
assert!(pages.contains(&(doc_id, vec!["tag-proof".to_string()])));
|
||||
store.close().await;
|
||||
let _ = std::fs::remove_dir_all(&base_dir);
|
||||
}
|
||||
Reference in new issue
Block a user