mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
fix(database): clear Table cell focus before closing Peek
This commit is contained in:
1 parent
241210c222
commit
f11c69cecd
2 files changed
+135
-1
No files matched your search
@@ -10,6 +10,13 @@ use crate::PlaygroundView;
|
||||
use super::{inline::DatabaseInlineTarget, snapshot_database};
|
||||
|
||||
impl PlaygroundView {
|
||||
/// Get the row and column of the focused Table cell.
|
||||
pub fn database_focused_cell(&self, block_id: &str) -> Option<(&str, &str)> {
|
||||
let state = self.flow.database_state.ui_state(block_id)?;
|
||||
let (row, column) = state.focused_cell.as_ref()?;
|
||||
Some((row, column))
|
||||
}
|
||||
|
||||
/// Route control/navigation keys to an active database authoring input. Printable text and
|
||||
/// CJK IME composition enter exclusively via [`ui::EntityInputHandler`]. `Cmd/Ctrl+Z` /
|
||||
/// `Shift+Cmd/Ctrl+Z` dismiss popovers and pass through to native Undo/Redo.
|
||||
@@ -176,7 +183,13 @@ impl PlaygroundView {
|
||||
);
|
||||
}
|
||||
if self.database_navigation_ready(&block_id) {
|
||||
return false;
|
||||
return self.database_input.is_none()
|
||||
&& self.dispatch_database_navigation(
|
||||
&block_id,
|
||||
DatabaseNavKey::Escape,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
let clears_search = self
|
||||
.flow
|
||||
|
||||
@@ -740,3 +740,124 @@ fn escape_cancels_callout_picker_composition_before_dismissing_the_picker() {
|
||||
ui.shell(|shell, _, _| assert!(!shell.state.peek_view.is_open()));
|
||||
assert_eq!(ui.input(|input| input.focus_id()), source_focus);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod table_cell_escape {
|
||||
use blocksuite_editor::database::DatabaseAuthoringHitKind;
|
||||
use blocksuite_playground_doc::schema::DatabaseColumnSpec;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn escape_exits_table_cell_edit_then_navigation_before_closing_peek() {
|
||||
const TABLE: &str = "peek-db";
|
||||
const ROW: &str = "peek-row";
|
||||
const COLUMN: &str = "title";
|
||||
|
||||
let ui = Workbench::new(DesktopAppState::seed_showcase(ThemeMode::Light, DATE));
|
||||
ui.click_paragraph();
|
||||
let source_focus = ui.input(|input| input.focus_id().expect("source editor focus"));
|
||||
ui.click_reference(true);
|
||||
|
||||
let peek = ui.shell(|shell, _, cx| {
|
||||
let peek = shell.editor_host().peek_entity().expect("Peek editor");
|
||||
peek.update(cx, |view, cx| {
|
||||
view.edit_document(cx, |doc| {
|
||||
let page = doc.workspace.page_mut(TARGET).unwrap();
|
||||
page.add_block(
|
||||
TABLE,
|
||||
BlockSpec::Database(DatabaseSpec {
|
||||
title: "Planning".into(),
|
||||
columns: vec![DatabaseColumnSpec {
|
||||
id: COLUMN.into(),
|
||||
column_type: "title".into(),
|
||||
name: "Title".into(),
|
||||
data: serde_json::json!({}),
|
||||
}],
|
||||
views: vec![DatabaseViewSpec {
|
||||
id: "table".into(),
|
||||
name: "Table".into(),
|
||||
mode: "table".into(),
|
||||
raw: serde_json::json!({ "columns": [{ "id": COLUMN, "width": 160 }] }),
|
||||
}],
|
||||
..Default::default()
|
||||
}),
|
||||
Some("note-sync"),
|
||||
Some(0),
|
||||
70,
|
||||
)
|
||||
.unwrap();
|
||||
page.add_block(
|
||||
ROW,
|
||||
BlockSpec::Paragraph {
|
||||
paragraph_type: ParagraphType::Text,
|
||||
text: "Project note".into(),
|
||||
},
|
||||
Some(TABLE),
|
||||
None,
|
||||
71,
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
});
|
||||
peek
|
||||
});
|
||||
ui.frame();
|
||||
|
||||
let position = ui.shell(|_, window, cx| {
|
||||
let (x, y) = peek
|
||||
.read(cx)
|
||||
.database_authoring_hit_screen_center(TABLE, window, |hit| {
|
||||
matches!(
|
||||
hit,
|
||||
DatabaseAuthoringHitKind::EditCell { row_id, column_id, .. }
|
||||
if row_id == ROW && column_id == COLUMN
|
||||
)
|
||||
})
|
||||
.expect("Title cell hit target");
|
||||
point(px(x), px(y))
|
||||
});
|
||||
ui.window.simulate_click(position);
|
||||
ui.frame();
|
||||
|
||||
for (open, editing, focused_cell) in [
|
||||
(true, true, Some((ROW, COLUMN))),
|
||||
(true, false, Some((ROW, COLUMN))),
|
||||
(true, false, None),
|
||||
(false, false, None),
|
||||
] {
|
||||
ui.shell(|shell, window, cx| {
|
||||
assert_eq!(shell.state.peek_view.is_open(), open);
|
||||
assert_eq!(
|
||||
window
|
||||
.frame_snapshot()
|
||||
.elements
|
||||
.contains_key("page.database_cell_focus"),
|
||||
editing,
|
||||
);
|
||||
assert_eq!(peek.read(cx).database_focused_cell(TABLE), focused_cell);
|
||||
});
|
||||
if open {
|
||||
ui.escape();
|
||||
ui.frame();
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(ui.input(|input| input.focus_id()), Some(source_focus));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escape_closes_peek_without_an_editor_transient() {
|
||||
let ui = Workbench::new(DesktopAppState::seed_showcase(ThemeMode::Light, DATE));
|
||||
ui.click_paragraph();
|
||||
let source_focus = ui.input(|input| input.focus_id().expect("source editor focus"));
|
||||
ui.click_reference(true);
|
||||
ui.shell(|shell, _, _| assert!(shell.state.peek_view.is_open()));
|
||||
|
||||
ui.escape();
|
||||
ui.frame();
|
||||
|
||||
ui.shell(|shell, _, _| assert!(!shell.state.peek_view.is_open()));
|
||||
assert_eq!(ui.input(|input| input.focus_id()), Some(source_focus));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user