test(playground): remove noop reference clone in tests_b6_r2

This commit is contained in:
DarkSky committed 2026-11-29 03:02:03 +09:00
1 parent b547e83415
commit 00ece8f2e0
8 files changed
+167 -20

No files matched your search

@@ -499,6 +499,7 @@ impl PlaygroundView {
pub fn set_document(&mut self, state: crate::DocState, cx: &mut ui::Context<Self>) {
self.finish_inline_targets(crate::overlays::InlineTargetEnd::DiscardPreedit, None, None);
self.editor = Default::default();
self.saved_page_selection = None;
self.overlays.reset();
self.reading_anchor = None;
self.flow = crate::block_flow::BlockFlow::new();
@@ -63,7 +63,7 @@ pub fn min_spatial_index(snapshot: &PageSnapshot) -> Option<String> {
min_idx
}
pub(super) fn find_surface_element<'a>(
pub(crate) fn find_surface_element<'a>(
snapshot: &'a PageSnapshot,
id: &str,
) -> Option<(&'a str, &'a SurfaceElement)> {
@@ -8,12 +8,13 @@ mod gestures;
mod group_ops;
mod inline_edit;
mod paste;
mod paste_convert;
pub(crate) mod paste_convert;
mod shape_picker;
pub use blocksuite_editor::edgeless::*;
use commands::{find_block, find_surface_element, max_spatial_index};
pub(crate) use commands::find_surface_element;
use commands::{find_block, max_spatial_index};
impl EdgelessToolbarHost for crate::PlaygroundView {
fn edgeless_active_tool(&self) -> EdgelessTool {
@@ -154,7 +154,7 @@ pub(super) fn remap_mindmap_children(
SessionValue::Map(remapped)
}
pub(super) fn remap_group_children(val: &Value, id_map: &HashMap<String, String>) -> SessionValue {
pub(crate) fn remap_group_children(val: &Value, id_map: &HashMap<String, String>) -> SessionValue {
let inner = val
.as_object()
.and_then(|o| o.get("value").and_then(Value::as_object).or(Some(o)));
@@ -162,12 +162,20 @@ pub(super) fn remap_group_children(val: &Value, id_map: &HashMap<String, String>
return surface_json_to_session_value(val);
};
let mut remapped: Vec<(String, SessionValue)> = Vec::new();
for (old_id, _v) in map {
let new_id = id_map
.get(old_id)
.cloned()
.unwrap_or_else(|| old_id.clone());
remapped.push((new_id, SessionValue::Any(Any::True)));
for (old_id, v) in map {
let is_active = match v {
Value::Bool(b) => *b,
Value::Null => false,
Value::Object(o) => o.get("value").and_then(Value::as_bool).unwrap_or(true),
_ => true,
};
if !is_active {
continue;
}
let Some(new_id) = id_map.get(old_id) else {
continue;
};
remapped.push((new_id.clone(), SessionValue::Any(Any::True)));
}
SessionValue::Map(remapped)
}
@@ -369,11 +369,15 @@ impl PlaygroundView {
}
let now_ms = self.now_ms(cx);
let current_x = self.indicator_x(now_ms);
let prev_mode = self.mode;
// Commit any pending inline edit (table cell or Edgeless label) cleanly before switching modes.
self.finish_inline_targets(InlineTargetEnd::CommitPreedit, Some(window), Some(cx));
if self.edgeless.authoring.editing_spatial_block().is_some() {
self.edgeless_commit_inline_edit(window, cx);
}
if prev_mode == PlaygroundMode::Page && target == PlaygroundMode::Edgeless {
self.saved_page_selection = self.editor.selection.take();
}
self.edgeless.authoring.reset_transient();
self.page_scroll_fling = None;
self.code_scroll_fling = None;
@@ -386,6 +390,9 @@ impl PlaygroundView {
self.context_paste_task = None;
self.context_menu_target = None;
self.overlays.reset();
if target == PlaygroundMode::Page && self.editor.selection.is_none() {
self.editor.selection = self.saved_page_selection.take();
}
self.prune_dangling_selection(Some(window), cx);
self.pill_motion = Some(Motion::new(
current_x,
+2
View File
@@ -256,6 +256,7 @@ pub struct PlaygroundView {
pub(crate) last_touch_scroll_ms: Option<f64>,
pub(crate) keep_keyboard_on_block_selection: bool,
pub(crate) block_selection_return_caret: Option<String>,
pub(crate) saved_page_selection: Option<editor_session::DocumentSelection>,
pub(crate) touch_long_press_anchor:
Option<(editor_session::DocPoint, editor_session::DocPoint)>,
pub(crate) touch_selection_menu_open: bool,
@@ -424,6 +425,7 @@ impl PlaygroundView {
native_selection_drag_anchor: None,
native_selection_drag_cell_anchor: None,
native_selection_drag_active: false,
saved_page_selection: None,
edgeless_readonly_selection_target: None,
caret_active_since_ms: 0.0,
caret_blink_task: None,
@@ -3,7 +3,7 @@
//! `@ Edgeless notes` linked page + `< Back`, and Edgeless multi-kind copy/paste + Linux word-delete.
use blocksuite_playground_doc::schema::{BlockSpec, ParagraphType};
use ui::{KeyDownEvent, Keystroke, Modifiers, Render};
use ui::{KeyDownEvent, Keystroke, Modifiers};
use super::{
OverlayEvent,
@@ -57,8 +57,8 @@ fn mode_scoped_selection_invariant_blocks_hidden_edgeless_text_and_restores_clea
.unwrap()
.to_string();
let layout = view.flow_layout().unwrap();
let last = layout.blocks.last().unwrap().clone();
view.handle_click_below_last_block(&last, window, cx);
let last = layout.blocks.last().unwrap();
view.handle_click_below_last_block(last, window, cx);
let cmd = Modifiers {
platform: cfg!(target_os = "macos"),
control: !cfg!(target_os = "macos"),
@@ -167,7 +167,7 @@ fn collapsed_heading_drag_packs_section_escape_cancels_drag_and_db_new_record_re
// + Database `+ New record` typing invalidates `Database` layout cache immediately!
let showcase = seed_showcase_doc().unwrap();
let (_p2, app2, win2, hw2) = open_doc(showcase);
app2.update(|cx| {
let (db_id, body_before, row_id) = app2.update(|cx| {
win2.update(cx, |view, window, cx| {
let layout0 = view.flow_layout().unwrap();
let db_block0 = layout0
@@ -184,6 +184,13 @@ fn collapsed_heading_drag_packs_section_escape_cancels_drag_and_db_new_record_re
.add_database_row(&db_id, &row_id, 5_000)
.unwrap();
view.apply_database_commit(commit, Some(window), cx);
(db_id, body_before, row_id)
})
.unwrap()
});
hw2.request_frame();
let body_after_add = app2.update(|cx| {
win2.update(cx, |view, window, cx| {
let body_after_add = view
.flow_layout()
.unwrap()
@@ -204,6 +211,13 @@ fn collapsed_heading_drag_packs_section_escape_cancels_drag_and_db_new_record_re
type_chars(view, "Live row title", window, cx);
assert!(view.doc_rev > rev_before);
assert_eq!(view.block_text(&row_id).unwrap(), "Live row title");
body_after_add
})
.unwrap()
});
hw2.request_frame();
app2.update(|cx| {
win2.update(cx, |view, window, cx| {
let layout1 = view.flow_layout().unwrap();
let db_after = layout1.block(&db_id).unwrap();
assert!(
@@ -233,8 +247,13 @@ fn edgeless_copy_cut_paste_note_shape_frame_edgeless_text_and_atomic_delete_sole
app.update(|cx| {
win.update(cx, |view, window, cx| {
view.set_mode(crate::PlaygroundMode::Edgeless, window, cx);
let _ = view.render(window, cx);
})
.unwrap();
});
hw.request_frame();
let shape_id = app.update(|cx| {
win.update(cx, |view, window, cx| {
let shape_id = view
.edgeless
.authoring
@@ -274,8 +293,14 @@ fn edgeless_copy_cut_paste_note_shape_frame_edgeless_text_and_atomic_delete_sole
count_after > count_before + 2,
"pasting Note+Shape+Frame+EdgelessText must materialize spatial blocks as well as surface elements"
);
shape_id
})
.unwrap()
});
hw.request_frame();
let _ = view.render(window, cx);
app.update(|cx| {
win.update(cx, |view, window, cx| {
assert!(view.edgeless_begin_inline_edit(&shape_id, window, cx));
view.edgeless
.authoring
@@ -311,6 +336,110 @@ fn edgeless_copy_cut_paste_note_shape_frame_edgeless_text_and_atomic_delete_sole
"Ctrl+Backspace on Linux/Windows must delete full word, got {label_after:?}"
);
view.edgeless_commit_inline_edit(window, cx);
// Astra R2 regression: Frame `prop:childElementIds` with `unselected-original: false`
// must NOT flip to `true` or retain uncloned canvas IDs on copy/paste, and deleting
// the pasted Frame must leave `unselected-original` intact on the canvas.
let mut unit_map = std::collections::HashMap::new();
unit_map.insert("selected-child".to_string(), "cloned-child".to_string());
let remapped = crate::edgeless::paste_convert::remap_group_children(
&serde_json::json!({
"selected-child": true,
"unselected-original": false,
"uncloned-true": true
}),
&unit_map,
);
assert_eq!(
remapped,
y_octo::SessionValue::Map(vec![(
"cloned-child".to_string(),
y_octo::SessionValue::Any(y_octo::Any::True),
)]),
"remap_group_children must drop false entries and uncloned IDs"
);
let page_id = view.page_id.clone().unwrap();
{
let page = view.state.workspace.page_mut(&page_id).unwrap();
page.structural_edit(5_000, |page| {
let block = y_octo::TypeTarget::Path(
y_octo::TypePath::root("blocks").key("showcase-frame"),
);
match page
.inner()
.get_map_value(&block, "prop:childElementIds")
.unwrap()
{
Some(y_octo::SessionReadValue::Map(map_id)) => {
let target = y_octo::TypeTarget::Identity(map_id);
page.inner_mut()
.map_set(
&target,
shape_id.clone(),
y_octo::SessionValue::Any(y_octo::Any::False),
)
.unwrap();
}
_ => {
page.inner_mut()
.map_set(
&block,
"prop:childElementIds".into(),
y_octo::SessionValue::Map(vec![(
shape_id.clone(),
y_octo::SessionValue::Any(y_octo::Any::False),
)]),
)
.unwrap();
}
}
Ok(())
})
.unwrap();
}
view.refresh_document();
})
.unwrap();
});
hw.request_frame();
app.update(|cx| {
win.update(cx, |view, window, cx| {
let frames_before: std::collections::BTreeSet<String> = view
.page_snapshot()
.unwrap()
.root
.as_ref()
.unwrap()
.walk()
.filter(|b| b.flavour == "affine:frame")
.map(|b| b.id.clone())
.collect();
view.edgeless.authoring.selection =
["showcase-frame".to_string()].into_iter().collect();
assert!(view.edgeless_copy_selection(false, cx));
let frame_clip = cx.read_from_clipboard().expect("frame clipboard");
assert!(view.paste_edgeless_clipboard_item(&frame_clip, window, cx));
let pasted_frame_id = view
.page_snapshot()
.unwrap()
.root
.as_ref()
.unwrap()
.walk()
.find(|b| b.flavour == "affine:frame" && !frames_before.contains(&b.id))
.expect("pasted frame")
.id
.clone();
let to_delete: std::collections::BTreeSet<String> =
[pasted_frame_id.clone()].into_iter().collect();
view.edgeless_delete_ids(&to_delete, cx);
let snap_post_del = view.page_snapshot().unwrap();
assert!(
crate::edgeless::find_surface_element(&snap_post_del, &shape_id).is_some(),
"deleting pasted Frame must NOT cascade-delete unselected-original ({shape_id})"
);
})
.unwrap();
});
@@ -1,5 +1,4 @@
//! Mobile `KeyboardToolbar`, long-press ICU word selection, embedded PDF paging,
//! table cell editing, and embedded doc navigation handlers for `PlaygroundView`.
//! Mobile `KeyboardToolbar`, touch word selection, PDF paging, table cell & link navigation.
mod actions;
mod database;
@@ -706,8 +705,7 @@ impl PlaygroundView {
self.navigate_back(Some(window), cx)
}
/// Navigate to a linked document inside the current workspace when present, or show a
/// gentle toast if the target page does not exist locally. Always records `last_opened_embed_doc`.
/// Navigate to a linked document in the current workspace (or show a toast if absent).
pub fn open_linked_doc(
&mut self,
page_id: &str,
@@ -768,6 +766,7 @@ impl PlaygroundView {
Some(cx),
);
self.editor = Default::default();
self.saved_page_selection = None;
self.overlays.reset();
self.reading_anchor = None;
self.flow = crate::block_flow::BlockFlow::new();