Skip to content

Commit

Permalink
Ensure the hydrogen counts are consisted across undo/redo - since by …
Browse files Browse the repository at this point in the history
…default the hydrogen counts are wiped/restored and we do the edits forwards/backwards we need to make sure the hydrogen count is correct on both the undo/redo. We can fudge this by add the change hcount edit before and after the adjust bond orders.
  • Loading branch information
johnmay committed Jan 24, 2025
1 parent ecd21a0 commit 81c462c
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,12 @@ else if (b.getOrder() == Order.DOUBLE)
String description = tautomer
? "Tautomer 1," + (path.size() + 1) + "-shift"
: "Alternative Kekule From";
AdjustBondOrdersEdit adjustBondOrders = new AdjustBondOrdersEdit(changedBonds,
Collections.emptyMap(),
"Change Bond Orders",
this);

CompoundEdit edit = new CompoundEdit(description);
edit.add(new AdjustBondOrdersEdit(changedBonds,
Collections.emptyMap(),
"Change Bond Orders",
this));
if (tautomer) {
// tautomers need their hydrogen count changed, note update atoms
// can get in the way here but seems to work okay on O,S,N,P
Expand All @@ -885,8 +886,15 @@ else if (b.getOrder() == Order.DOUBLE)
changedAtoms.put(endAtom, new Integer[]{endAtom.getImplicitHydrogenCount()+1,
endAtom.getImplicitHydrogenCount()});
}
// we need to set the hydrogen counts forward/backwards because
// otherwise the automatic CDK atom typing messes things up
edit.add(new ChangeHydrogenCountEdit(changedAtoms,
"Change Hydrogen Counts"));
edit.add(adjustBondOrders);
edit.add(new ChangeHydrogenCountEdit(changedAtoms,
"Change Hydrogen Counts"));
} else {
edit.add(adjustBondOrders);
}

edit.redo(); // fire the changes
Expand Down

0 comments on commit 81c462c

Please sign in to comment.