Compare commits

...
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 b86e9eeb84 fix(ui-egui): a key's edit pass no longer clears the settled pages (#9941)
A pass that places no page (the edit pass a key triggers) matched the empty
shown pages and reset settled_pages to empty, so that pass asked for unsized
pictures and the next pass's exact-pixel pictures were rendered again on a
worker plus an extra frame (~33 ms CPU, ~4.7 ms main thread per key). Only
settle when at least one page was placed; zoom, resize and scroll still
settle to their exact pixels.


Claude-Session: https://claude.ai/code/session_01FypgCXNomWeGUu3duixKdm

Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-12-06 23:02:09 +00:00
autocraft-bot[bot] ad5537f31c Merge pull request #9924 2026-12-06 20:15:42 +00:00
RickiNano ad162b1591 #9390: Resolving a thread saves only that thread's comment drafts
Resolve wrote the open comment edit and the selected thread's reply draft
whichever thread was being resolved, so a script resolving thread A while
the user typed a reply in thread B posted B's unfinished reply. Both the
window path and the parked-document path now save only drafts in the
discussion the resolve takes.
2026-12-06 21:12:15 +01:00
7 changed files with 105 additions and 20 deletions
+7 -6
View File
@@ -157,13 +157,14 @@ impl WordApp {
self.execute_command(id, params, false)
}
/// Resolving a comment saves the text typed in its open edit first and flushes any reply
/// draft, but only after checking that the resolve target is valid (#9389). If saving the
/// open edit is refused, the comment stays unresolved and the draft is kept.
/// Resolving a comment saves the text typed in an open edit of its thread first and flushes
/// the thread's reply draft, but only after checking that the resolve target is valid (#9389).
/// Drafts in other threads stay drafts (#9390). If saving the open edit is refused, the
/// comment stays unresolved and the draft is kept.
fn save_comment_drafts_before_resolve(&mut self, params: &Value) -> Result<(), String> {
if wordcraft_engine::cmd::review::resolve_comment_target(&self.session, params).is_ok() {
panes::commit_open_comment_edit(self)?;
let _ = panes::flush_reply_draft(self);
if let Ok(target) = wordcraft_engine::cmd::review::resolve_comment_target(&self.session, params) {
panes::commit_open_comment_edit(self, target)?;
let _ = panes::flush_resolved_reply_draft(self, target);
}
Ok(())
}
+3 -1
View File
@@ -1065,7 +1065,9 @@ fn show_pages(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: Rec
// The same places two passes running: the view is at rest, and these are the places pictures are made for.
let placed = |pages: &[PlacedPage]| pages.iter().map(|p| (p.page, p.rect)).collect::<Vec<_>>();
let now = placed(&out.pages);
if now == placed(&app.canvas.shown.pages) && now != app.canvas.settled_pages {
// A pass that placed no page (a key's edit pass) is not a rest: clearing the places would make the pictures
// that pass asks for the unsized ones, and the next pass's sized ones render all over again.
if !now.is_empty() && now == placed(&app.canvas.shown.pages) && now != app.canvas.settled_pages {
app.canvas.settled_pages = now;
// The pictures of the places just settled are made on the next pass.
ui.ctx().request_repaint();
+24
View File
@@ -117,6 +117,30 @@ fn resolving_an_addressed_comment_saves_its_parked_drafts() {
assert!(!a.document_has_comment_drafts(first));
}
/// A control command resolving one parked thread leaves that document's drafts in another thread alone (#9390).
#[test]
fn resolving_an_addressed_comment_leaves_another_threads_parked_drafts() {
let mut a = app();
let (first, second) = two_documents(&mut a);
assert_eq!(exec(&mut a, "view.switchWindows", json!({"id": first}))["ok"], true);
let resolved = exec(&mut a, "review.newComment", json!({"text": "Resolved comment"}))["result"]["id"].as_u64().expect("a comment was added");
let other = exec(&mut a, "review.newComment", json!({"text": "Other comment"}))["result"]["id"].as_u64().expect("a comment was added");
crate::panes::set_comment_draft(&mut a, other.try_into().unwrap(), "Edited comment".into());
a.canvas.comments.selected = Selection::single(ThreadId(other));
a.canvas.comments.reply = "Half a reply".into();
assert_eq!(exec(&mut a, "view.switchWindows", json!({"id": second}))["ok"], true);
let r = send(&mut a, "engine.execute", json!({"command": "review.resolveComment", "params": {"id": resolved}, "doc": first}));
assert_eq!(r["ok"], true, "{r}");
let r = send(&mut a, "engine.execute", json!({"command": "review.comments", "doc": first}));
let comments = r["result"].as_array().expect("the parked document's comments");
assert_eq!(comments.len(), 2, "no reply was posted: {r}");
let other = comments.iter().find(|c| c["id"] == other).expect("the other comment");
assert_eq!(other["text"], "Other comment");
assert_ne!(other["resolved"], true);
assert!(a.document_has_comment_drafts(first));
}
/// The existing parked Resolve preflight saves new edits on open comments. A draft whose
/// comment became resolved through parked Undo waits for Reopen, without touching the window's document.
#[test]
+4 -2
View File
@@ -252,8 +252,10 @@ fn handle_in(app: &mut WordApp, doc: u64, method: &str, p: &Value) -> Reply {
/// Apply the same draft identity rules when the addressed document isn't on screen.
fn run_parked_command(session: &mut Session, parked: Option<&mut Parked>, command: &str, params: &Value) -> CmdResult {
let Some(parked) = parked else { return session.run(command, params) };
if command == "review.resolveComment" && wordcraft_engine::cmd::review::resolve_comment_target(session, params).is_ok() {
crate::panes::flush_parked_comment_drafts(session, &mut parked.comments, &mut parked.comment_draft_id);
if command == "review.resolveComment"
&& let Ok(target) = wordcraft_engine::cmd::review::resolve_comment_target(session, params)
{
crate::panes::flush_parked_comment_drafts(session, &mut parked.comments, &mut parked.comment_draft_id, target);
}
let result = session.run(command, params);
crate::panes::reconcile_comment_draft(&session.doc, &mut parked.comments, &mut parked.comment_draft_id);
+1 -1
View File
@@ -22,7 +22,7 @@ mod state;
use comments::comments;
pub(crate) use comments::{
after_comment_command, bind_balloon_comment_draft, commit_comment, commit_open_comment_edit, commit_reply, flush_comment_drafts,
flush_parked_comment_drafts, flush_reply_draft, has_comment_drafts, reconcile_active_comment_draft, reconcile_comment_draft,
flush_parked_comment_drafts, flush_resolved_reply_draft, has_comment_drafts, reconcile_active_comment_draft, reconcile_comment_draft,
resolved_comment_draft, set_comment_draft, state_has_drafts,
};
use host::Content;
+37 -10
View File
@@ -246,15 +246,31 @@ pub(crate) fn commit_comment(app: &mut WordApp, id: u32) -> Result<(), String> {
Ok(())
}
/// Write an editable draft before Resolve. A draft already waiting for Reopen must not
/// block Reopen itself or a different thread's Resolve.
pub(crate) fn commit_open_comment_edit(app: &mut WordApp) -> Result<(), String> {
if resolved_comment_draft(app).is_some() {
/// Write an editable draft before Resolve of comment `target`. A draft already waiting for Reopen must not
/// block Reopen itself or a different thread's Resolve, and a draft in another thread stays a draft (#9390).
pub(crate) fn commit_open_comment_edit(app: &mut WordApp, target: u32) -> Result<(), String> {
if resolved_comment_draft(app).is_some() || app.canvas.comment_draft_id.is_some_and(|id| !same_discussion(&app.session.doc, id, target)) {
return Ok(());
}
flush_edit_draft(app)
}
/// Whether comments `a` and `b` are in one discussion: `review.resolveComment` on either resolves both.
fn same_discussion(doc: &Document, a: u32, b: u32) -> bool {
let root = |id: u32| {
let mut root = id;
let mut seen = std::collections::BTreeSet::new();
while seen.insert(root) {
match doc.comments.get(&root).and_then(|c| c.parent).filter(|p| doc.comments.contains_key(p)) {
Some(parent) => root = parent,
None => break,
}
}
root
};
root(a) == root(b)
}
fn edit_params(doc: &Document, id: u32, text: &str) -> Result<Option<Value>, String> {
let Some(comment) = doc.comments.get(&id) else { return Ok(None) };
if text == doc.plain_text(StoryRef::Part(comment.part)) {
@@ -356,23 +372,34 @@ fn flush_edit_draft(app: &mut WordApp) -> Result<(), String> {
app.canvas.comment_draft_id.map_or(Ok(()), |id| commit_comment(app, id))
}
pub(crate) fn flush_reply_draft(app: &mut WordApp) -> Result<(), String> {
fn flush_reply_draft(app: &mut WordApp) -> Result<(), String> {
let selected = drafts(app).selected.lead.as_ref().and_then(|t| u32::try_from(t.0).ok());
selected.map_or(Ok(()), |id| commit_reply(app, id))
}
/// Write a parked document's drafts while its session is temporarily addressed by the control
/// channel. Like a resolve in the window, try both drafts and keep any the document refuses.
pub(crate) fn flush_parked_comment_drafts(session: &mut Session, state: &mut CommentsPanelState, draft_id: &mut Option<u32>) {
/// Post the reply draft before Resolve of comment `target`, when the reply is to that discussion (#9390).
pub(crate) fn flush_resolved_reply_draft(app: &mut WordApp, target: u32) -> Result<(), String> {
let selected = drafts(app).selected.lead.as_ref().and_then(|t| u32::try_from(t.0).ok());
selected.filter(|id| same_discussion(&app.session.doc, *id, target)).map_or(Ok(()), |id| commit_reply(app, id))
}
/// Write a parked document's drafts in the discussion of comment `target` before the control channel
/// resolves it. Like a resolve in the window, try both drafts, keep any the document refuses and
/// leave other threads' drafts alone (#9390).
pub(crate) fn flush_parked_comment_drafts(session: &mut Session, state: &mut CommentsPanelState, draft_id: &mut Option<u32>, target: u32) {
reconcile_comment_draft(&session.doc, state, draft_id);
if let (Some(id), Some((_, _, text))) = (*draft_id, &state.editing) {
if let (Some(id), Some((_, _, text))) = (*draft_id, &state.editing)
&& same_discussion(&session.doc, id, target)
{
let params = edit_params(&session.doc, id, text);
if params.is_ok_and(|params| params.is_none_or(|params| session.run("review.editComment", &params).is_ok())) {
state.editing = None;
*draft_id = None;
}
}
if let Some(id) = state.selected.lead.as_ref().and_then(|t| u32::try_from(t.0).ok()) {
if let Some(id) = state.selected.lead.as_ref().and_then(|t| u32::try_from(t.0).ok())
&& same_discussion(&session.doc, id, target)
{
let params = reply_params(&session.doc, id, &state.reply);
if params.is_none_or(|params| session.run("review.reply", &params).is_ok()) {
state.reply.clear();
+29
View File
@@ -534,6 +534,35 @@ mod comment_wrapping {
assert!(!crate::panes::has_comment_drafts(h.state()));
}
/// #9390: a script resolving one thread writes only that thread's drafts. A comment edit and a half-typed reply
/// in another thread stay drafts.
#[test]
fn resolving_a_thread_leaves_another_threads_drafts_alone() {
use craft::behavior::Selection;
use craft::review::ThreadId;
use serde_json::json;
use wordcraft_doc::StoryRef;
const SECOND: &str = "Second comment.";
let mut h = pane(&["First comment.".to_owned(), SECOND.to_owned()]);
let ids: Vec<u32> = h.state().session.doc.comments.keys().copied().collect();
let field = field_lines(&h, "Comment", SECOND).0.center();
click_at(&mut h, field);
press_key(&mut h, egui::Key::End);
type_text(&mut h, " Typed.");
let app = h.state_mut();
app.canvas.comments.selected = Selection::single(ThreadId(u64::from(ids[1])));
app.canvas.comments.reply = "Half a reply".into();
app.execute("review.resolveComment", json!({"id": ids[0]})).unwrap();
let doc = &app.session.doc;
assert!(doc.comments[&ids[0]].resolved);
assert_eq!(doc.plain_text(StoryRef::Part(doc.comments[&ids[1]].part)), SECOND);
assert!(doc.comments.values().all(|c| c.parent != Some(ids[1])), "no reply was posted to the other thread");
assert!(app.canvas.comments.editing.is_some());
assert_eq!(app.canvas.comments.reply, "Half a reply");
}
/// #9389: a refused `review.resolveComment` (missing comment at caret, bad id, or unknown id)
/// must not commit pending comment drafts or push undo steps.
#[test]