mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
pipe editing-1: fixes for editing (10 tests)
This commit is contained in:
@@ -967,13 +967,17 @@ fn page_parts_of(
|
||||
return (parts, tabs);
|
||||
}
|
||||
if cx.editing_content {
|
||||
for placed in body.pages {
|
||||
parts.extend(crate::edit_text_ui::picture_parts(session, cx.doc, placed.page, placed, geo));
|
||||
if cx.tool == QuickTool::EditText && cx.can_modify {
|
||||
for placed in body.pages {
|
||||
parts.extend(crate::edit_text_ui::picture_parts(session, cx.doc, placed.page, placed, geo));
|
||||
}
|
||||
}
|
||||
// A picture being cropped holds every press on its page: its paragraphs and added text take none there.
|
||||
let cropping = session.image_selection.as_ref().filter(|s| s.crop.is_some()).map(|s| s.page);
|
||||
for placed in body.pages.iter().filter(|placed| Some(placed.page) != cropping) {
|
||||
parts.extend(crate::edit_text_ui::page_parts(session, cx.doc, placed.page, placed, geo));
|
||||
if cx.can_modify && matches!(cx.tool, QuickTool::EditText | QuickTool::AddText) {
|
||||
parts.extend(crate::edit_text_ui::page_parts(session, cx.doc, placed.page, placed, geo));
|
||||
}
|
||||
}
|
||||
for placed in body.pages.iter().filter(|placed| Some(placed.page) != cropping) {
|
||||
parts.extend(crate::content_ui::page_parts(session, cx.doc, placed.page, placed));
|
||||
@@ -1104,9 +1108,9 @@ fn route_press(
|
||||
QuickTool::Field(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
// Added text, pictures and the objects selected together lie over the comments: a right-click on them
|
||||
// Added text and the objects selected together lie over the comments: a right-click on them
|
||||
// reaches no comment under them and leaves the selection cleared.
|
||||
let over_comments = matches!(owner, Owner::Added { .. } | Owner::Picture { .. } | Owner::Objects { .. } | Owner::Frame { .. });
|
||||
let over_comments = matches!(owner, Owner::Added { .. } | Owner::Objects { .. } | Owner::Frame { .. });
|
||||
if held || tool_takes_it || matches!(press.owner, Owner::Comment { .. }) {
|
||||
comments::context_anchor(&page_cx, &mut session.comments, start.origin);
|
||||
} else if over_comments {
|
||||
@@ -1114,6 +1118,9 @@ fn route_press(
|
||||
session.comments.select(None);
|
||||
} else if let Some(index) = comments::context_target(&page_cx, &mut session.comments, start.origin) {
|
||||
menu_for = Some((page, Owner::Comment { index }));
|
||||
if cx.tool == QuickTool::EditText {
|
||||
crate::edit_text_ui::picture_context(page, None, session);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The page's menu reads what the secondary press went to; a comment is selected for its menu, as a comment's
|
||||
|
||||
@@ -117,7 +117,7 @@ impl CanvasTool for EditTextTool<'_> {
|
||||
return true;
|
||||
}
|
||||
let edit = object_ui::delete(self.session)
|
||||
.or_else(|| crate::edit_text_ui::delete_picture(self.session, self.placed))
|
||||
.or_else(|| crate::edit_text_ui::delete_picture(self.session, self.placed, self.geo.viewport))
|
||||
.or_else(|| crate::content_ui::delete_selected(self.session));
|
||||
self.queue(edit);
|
||||
true
|
||||
|
||||
@@ -854,7 +854,7 @@ pub(crate) fn paragraph_controls(
|
||||
let blocks = page_blocks(session, doc, page);
|
||||
let boxes: Vec<Rect> = blocks.iter().map(|l| paragraph_box(&xf, &doc.info, page, l.rect)).collect();
|
||||
open_waiting(session, doc, page, &blocks, &boxes, geo);
|
||||
outline_closed(ui, body, session, page, &boxes);
|
||||
outline_closed(ui, body, session, page, &boxes, xf.rect.intersect(geo.viewport));
|
||||
draw_move(ui, body, session, page, &boxes, press);
|
||||
let framed =
|
||||
hovered.filter(|(p, _)| *p == page).and_then(|(_, block)| blocks.get(block).zip(boxes.get(block).copied()).map(|(l, b)| (block, l, b)));
|
||||
@@ -907,12 +907,12 @@ fn open_waiting(
|
||||
}
|
||||
|
||||
/// The faint outline of every closed paragraph on `page`, one control with every path.
|
||||
fn outline_closed(ui: &mut egui::Ui, body: &PageBody<'_>, session: &PageSession, page: usize, boxes: &[Rect]) {
|
||||
fn outline_closed(ui: &mut egui::Ui, body: &PageBody<'_>, session: &PageSession, page: usize, boxes: &[Rect], clip: Rect) {
|
||||
let open = session.line_editor.as_ref().filter(|e| e.page == page).map(|e| e.block);
|
||||
let paths: Vec<BezPath> =
|
||||
boxes.iter().enumerate().filter(|(i, _)| Some(*i) != open).take(MAX_OUTLINES).map(|(_, b)| rect_path(doc_rect(&body.view, *b))).collect();
|
||||
if !paths.is_empty() {
|
||||
let _ = SelectionOutline::faint(tl!("Edit text & images").to_string(), &paths).show_at(ui, body.rect);
|
||||
let _ = SelectionOutline::faint(tl!("Edit text & images").to_string(), &paths).show_at(ui, clip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ pub(crate) fn picture_controls(
|
||||
geo: PageGeometry<'_>,
|
||||
) -> Option<Edit> {
|
||||
let mut edit = None;
|
||||
for placed in body.pages {
|
||||
for placed in body.pages.iter().filter(|placed| placed.rect.intersects(geo.viewport)) {
|
||||
let xf = geo.xform_of(placed);
|
||||
let images = doc.page_images(placed.page);
|
||||
let selection = session.image_selection.as_ref().filter(|s| s.page == placed.page && s.index < images.len());
|
||||
@@ -613,9 +613,9 @@ pub(crate) fn picture_press(session: &mut PageSession, doc: &pdfcraft_engine::Do
|
||||
|
||||
/// Delete or Backspace on the selected picture, while its page is shown and it is not being cropped
|
||||
/// or changed.
|
||||
pub(crate) fn delete_picture(session: &mut PageSession, placed: &[PlacedPage]) -> Option<Edit> {
|
||||
pub(crate) fn delete_picture(session: &mut PageSession, placed: &[PlacedPage], viewport: Rect) -> Option<Edit> {
|
||||
let s = session.image_selection.as_ref().filter(|s| s.crop.is_none() && !s.gesturing())?;
|
||||
if !placed.iter().any(|p| p.page == s.page) {
|
||||
if !placed.iter().any(|p| p.page == s.page && p.rect.intersects(viewport)) {
|
||||
return None;
|
||||
}
|
||||
let (page, index) = (s.page, s.index);
|
||||
|
||||
@@ -3880,6 +3880,10 @@ fn two_boxes_animated() -> (Harness<'static, PdfCraftApp>, [egui::Rect; 2]) {
|
||||
fn editor_frame_color(h: &Harness<'static, PdfCraftApp>, r: egui::Rect) -> Option<egui::Color32> {
|
||||
h.output().shapes.iter().find_map(|shape| match &shape.shape {
|
||||
egui::Shape::Rect(rect) if rect.stroke.width == 1.5 && rect.rect.contains(r.center()) => Some(rect.stroke.color),
|
||||
egui::Shape::Path(path) if path.closed && egui::Rect::from_points(&path.points).contains(r.center()) => match &path.stroke.color {
|
||||
egui::epaint::ColorMode::Solid(color) if color.r() == 0x14 && color.g() == 0x73 && color.b() == 0xE6 => Some(*color),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -7999,7 +8003,8 @@ fn a_selected_pictures_keys_wait_for_its_page_to_be_on_screen() {
|
||||
h.state_mut().views[0].view.continuous = false;
|
||||
h.state_mut().views[0].go_to_page(1);
|
||||
h.run_steps(4);
|
||||
assert!(h.state().views[0].page_screen_rect(0).is_none(), "page 1 is off the screen");
|
||||
let viewport = h.state().views[0].viewport_rect();
|
||||
assert!(h.state().views[0].page_screen_rect(0).is_none_or(|r| !r.intersects(viewport)), "page 1 is off the screen");
|
||||
h.key_press(key);
|
||||
h.run_steps(4);
|
||||
let after = h.state().session.get(id).unwrap().page_images(0);
|
||||
|
||||
Reference in New Issue
Block a user