PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge PR #4111: fix(edit): Delete removes the selected paragraph or objects in Edit text
aionggf9f08017f091
diff --cc crates/ui-egui/src/object_ui.rsindex 1b090b373,04e37feee..b68fe352a--- a/crates/ui-egui/src/object_ui.rs+++ b/crates/ui-egui/src/object_ui.rs@@@ -415,3 -455,62 +455,40 @@@ pub(crate) fn move_error(error: &pdfcra_ => tl!("These objects could not be moved. Select them again and try a smaller move.").into(),}}++ #[cfg(test)]+ mod tests {+ use super::*;+- #[test]- fn selection_labels_and_refusals_are_translated_in_every_catalog() {- for language in crate::i18n::LANGUAGES.iter().filter(|l| !l.source.is_empty()) {- let lang = crate::i18n::Lang::from_code(language.code).unwrap();- for label in [- "Drag the selection to move it. Esc clears the selection.",- "Shift-click to select several objects. Drag empty space to select an area.",- "Select at most 1000 objects at a time.",- "Finish or discard the text being edited before selecting several objects.",- "Move object",- "Move objects",- "Vertical text cannot be moved with this selection.",- "Text used as a clipping path cannot be moved with this selection.",- "These objects could not be moved. Select them again and try a smaller move.",- "This page contains objects that cannot be selected together.",- ] {- assert_ne!(crate::i18n::tr(lang, label), label, "{}: {label}", language.code);- }- assert_ne!(crate::i18n::trn(lang, 2, "{n} object selected", "{n} objects selected"), "2 objects selected", "{}", language.code);- }- }-+ fn t(kind: ObjectKind, index: usize) -> ObjectTarget {+ ObjectTarget { kind, index }+ }++ /// Deleting renumbers what follows in the same inventory, so the batch takes each inventory+ /// from its last item to its first, and added content (outside the source inventories) last.+ #[test]+ fn several_objects_delete_last_first_in_one_step() {+ let targets = vec![t(ObjectKind::Added, 0), t(ObjectKind::Text, 1), t(ObjectKind::Image, 0), t(ObjectKind::Text, 3), t(ObjectKind::Added, 2)];+ let Some(Edit::Batch { label, edits }) = delete_edit(0, targets) else { panic!("several objects make one batch") };+ assert_eq!(label, "Delete content");+ let order: Vec<(char, usize)> = edits+ .iter()+ .map(|e| match e {+ Edit::EditTextBlock { block, text, .. } => {+ assert!(text.is_empty());+ ('t', *block)+ }+ Edit::EditPageImage { index, change: pdfcraft_engine::ImageEdit::Delete, .. } => ('i', *index),+ Edit::DeleteContent { index, .. } => ('a', *index),+ other => panic!("unexpected {}", other.label().wording),+ })+ .collect();+ assert_eq!(order, [('t', 3), ('t', 1), ('i', 0), ('a', 2), ('a', 0)]);+ }++ #[test]+ fn one_object_deletes_with_its_own_edit_and_none_with_nothing() {+ assert!(matches!(delete_edit(2, vec![t(ObjectKind::Image, 4)]), Some(Edit::EditPageImage { page: 2, index: 4, .. })));+ assert!(delete_edit(0, Vec::new()).is_none());+ }+ }