mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 13:01:29 +00:00
Fit the landed changes together
The forms editor's test draft sets the focus's obj and list, which main added, and the focus scripts look up the focused field with focused_field so a same-name twin is read as main reads it.
This commit is contained in:
1 parent
2af11131ef
commit
3774c3312a
2 files changed
+7
-5
No files matched your search
@@ -789,14 +789,14 @@ impl PdfCraftApp {
|
||||
}
|
||||
let left = std::mem::replace(&mut view.forms.focused, now.clone());
|
||||
let id = view.id;
|
||||
let edited = now.as_ref().map(|(name, _)| name.clone());
|
||||
let edited = view.forms.focus.clone();
|
||||
use pdfcraft_engine::js::FieldFocus;
|
||||
for ((name, widget), focus) in [left.map(|l| (l, FieldFocus::Exit)), now.map(|n| (n, FieldFocus::Enter))].into_iter().flatten() {
|
||||
// The edited field's value before this script, to tell its untouched draft from typing:
|
||||
// the exit of the field left may have changed it already, and the draft with it.
|
||||
let before: Option<(String, Vec<String>)> = edited
|
||||
.as_ref()
|
||||
.and_then(|e| self.session.get(id)?.form.iter().find(|f| &f.name == e).map(|f| (crate::forms_ui::draft_text(f), f.value.clone())));
|
||||
let before: Option<(String, Vec<String>)> = edited.as_ref().and_then(|e| {
|
||||
crate::forms_ui::focused_field(e, &self.session.get(id)?.form).map(|f| (crate::forms_ui::draft_text(f), f.value.clone()))
|
||||
});
|
||||
match self.session.field_focus(id, &name, widget, focus) {
|
||||
Ok(changed) => {
|
||||
if changed
|
||||
@@ -806,7 +806,7 @@ impl PdfCraftApp {
|
||||
view.document_changed(&info);
|
||||
if let Some(before) = &before
|
||||
&& let Some(draft) = view.forms.focus.as_mut()
|
||||
&& let Some(f) = self.session.get(id).and_then(|d| d.form.iter().find(|f| f.name == draft.name))
|
||||
&& let Some(f) = self.session.get(id).and_then(|d| crate::forms_ui::focused_field(draft, &d.form))
|
||||
{
|
||||
crate::forms_ui::refresh_draft(draft, (&before.0, &before.1), (crate::forms_ui::draft_text(f), &f.value));
|
||||
}
|
||||
|
||||
@@ -1404,6 +1404,7 @@ mod tests {
|
||||
fn draft(value: &[&str]) -> Focus {
|
||||
Focus {
|
||||
name: "hint".into(),
|
||||
obj: None,
|
||||
widget: 0,
|
||||
text: value.first().map(|s| s.to_string()).unwrap_or_default(),
|
||||
picked: value.iter().map(|s| s.to_string()).collect(),
|
||||
@@ -1413,6 +1414,7 @@ mod tests {
|
||||
calendar: None,
|
||||
calendar_rect: None,
|
||||
calendar_text: None,
|
||||
list: ChoiceList::default(),
|
||||
had_focus: false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user