mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 13:19:58 +00:00
fix(ui): All tools ▸ Edit a PDF turns on Edit text & images at once (#4605)
This commit is contained in:
@@ -61,6 +61,21 @@ impl PdfCraftApp {
|
||||
pub(crate) fn select_tool(&mut self, id: &'static str) {
|
||||
// The tool's panel shows, not the expanded All tools view over it.
|
||||
self.all_tools_full = false;
|
||||
// Edit a PDF turns on Edit text & images at once, as the Edit tab does (`enter_mode`), so
|
||||
// the page is editable without a second click. Leaving it for another tool from All tools
|
||||
// puts editing down again; under the Edit tab the workspace keeps it, as before. Read mode
|
||||
// hides the quick toolbar and keeps every tool down (`enter_mode`), so the control
|
||||
// channel's `tool edit` there leaves editing off.
|
||||
if id == "edit" {
|
||||
if self.mode != Mode::Read {
|
||||
self.quick_tool = QuickTool::EditText;
|
||||
}
|
||||
} else if self.mode != Mode::Edit
|
||||
&& self.left == LeftPanel::Tool("edit")
|
||||
&& matches!(self.quick_tool, QuickTool::EditText | QuickTool::AddText)
|
||||
{
|
||||
self.put_down_edit_text();
|
||||
}
|
||||
self.left = LeftPanel::Tool(id);
|
||||
self.reveal_tools();
|
||||
if let Some(view) = self.active.and_then(|i| self.views.get_mut(i)) {
|
||||
|
||||
@@ -5487,6 +5487,30 @@ fn paragraph_edges_and_frames_are_caught_without_aiming_for_the_hairline() {
|
||||
assert!(h.query_all_by_label_contains("object selected").next().is_none(), "and doesn't take the box");
|
||||
}
|
||||
|
||||
/// Leaving All tools ▸ Edit a PDF for another tool applies the paragraph still open, as leaving
|
||||
/// the Edit tab does, rather than dropping what was typed (review on #4605).
|
||||
#[test]
|
||||
fn another_tool_from_edit_a_pdf_applies_the_open_paragraph() {
|
||||
use pdfcraft_ui_egui::{Mode, QuickTool};
|
||||
let mut h = harness(1, |_| {});
|
||||
h.state_mut().set_option("tool", "edit").unwrap();
|
||||
h.run_steps(2);
|
||||
assert_ne!(h.state().mode, Mode::Edit, "Edit a PDF from All tools, not the Edit tab");
|
||||
assert_eq!(h.state().quick_tool, QuickTool::EditText);
|
||||
let id = h.state().views[0].id;
|
||||
let b = h.state().session.get(id).unwrap().text_blocks(0)[0].clone();
|
||||
let r = h.state().views[0].page_screen_rect(0).expect("on screen");
|
||||
let k = r.width() / 200.0;
|
||||
click_at(&mut h, egui::pos2(r.left() + ((b.rect[0] + b.rect[2]) / 2.0) as f32 * k, r.top() + (300.0 - (b.rect[1] + b.rect[3]) / 2.0) as f32 * k));
|
||||
assert_eq!(h.state().views[0].line_editor.as_ref().map(|e| e.text.as_str()), Some("Page 1"), "the paragraph is open for typing");
|
||||
h.state_mut().views[0].line_editor.as_mut().unwrap().text = "Page one".into();
|
||||
h.state_mut().set_option("tool", "organize").unwrap();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().views[0].line_editor.is_none());
|
||||
assert_eq!(h.state().quick_tool, QuickTool::Select);
|
||||
assert_eq!(h.state().session.get(id).unwrap().text_blocks(0)[0].text, "Page one", "the typed text was applied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_open_paragraph_moves_by_its_frame_and_by_the_arrow_keys() {
|
||||
let mut h = harness(2, |_| {});
|
||||
|
||||
@@ -489,6 +489,39 @@ fn read_mode_hides_the_quick_toolbar() {
|
||||
h.get_by_label("Select (V)");
|
||||
}
|
||||
|
||||
/// All tools ▸ Edit a PDF turns on Edit text & images at once, as the Edit tab does, so the page
|
||||
/// is editable without clicking Edit again. Another tool from there puts editing down.
|
||||
#[test]
|
||||
fn edit_a_pdf_from_all_tools_turns_on_editing() {
|
||||
use pdfcraft_ui_egui::{Mode, QuickTool};
|
||||
let mut h = harness(|app| app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
|
||||
assert_eq!(h.state().mode, Mode::AllTools);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::Select);
|
||||
h.get_by_label("Edit a PDF").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().mode, Mode::AllTools, "the workspace stays All tools, with its way back");
|
||||
assert_eq!(h.state().quick_tool, QuickTool::EditText, "Edit text & images is on at once");
|
||||
h.state_mut().set_option("tool", "organize").unwrap();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::Select, "another tool puts editing down");
|
||||
// In the Edit workspace, another tool from its panel leaves editing on, as before.
|
||||
h.state_mut().set_option("mode", "edit").unwrap();
|
||||
h.state_mut().set_option("tool", "edit").unwrap();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::EditText);
|
||||
h.state_mut().set_option("tool", "organize").unwrap();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::EditText);
|
||||
// Read mode hides the quick toolbar and keeps the tools down, so the control channel's
|
||||
// `tool edit` there leaves editing off (review on #4605).
|
||||
h.state_mut().run_command("view.read_mode");
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().mode, Mode::Read);
|
||||
h.state_mut().set_option("tool", "edit").unwrap();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::Select, "no editing tool in Read mode");
|
||||
}
|
||||
|
||||
/// Opening a document with Read as the default mode puts down the tool in use, as entering Read
|
||||
/// mode from the mode bar does: the hidden toolbar would leave no way to see or change it.
|
||||
#[test]
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user