diff --git a/avogadro/qtplugins/editor/editor.cpp b/avogadro/qtplugins/editor/editor.cpp index f133dd746c..f76eae113b 100644 --- a/avogadro/qtplugins/editor/editor.cpp +++ b/avogadro/qtplugins/editor/editor.cpp @@ -73,7 +73,8 @@ Editor::Editor(QObject* parent_) m_activateAction->setToolTip( tr("Draw Tool \t(%1)\n\n" "Left Mouse: \tClick and Drag to create Atoms and Bond\n" - "Right Mouse: \tDelete Atom").arg(shortcut)); + "Right Mouse: \tDelete Atom") + .arg(shortcut)); setIcon(); reset(); } @@ -421,9 +422,9 @@ void Editor::atomRightClick(QMouseEvent* e) Core::Array bondedAtoms; if (m_toolWidget->adjustHydrogens()) { // before we remove the atom, we need to delete any H atoms - // that are bonded to it + // that are bonded to it -- unless it's a hydrogen atom itself RWAtom atom = m_molecule->atom(m_clickedObject.index); - if (atom.isValid()) { + if (atom.isValid() && atom.atomicNumber() != Core::Hydrogen) { // get the list of bonded atoms Core::Array atomBonds = m_molecule->bonds(atom); for (const RWBond& bond : atomBonds) { @@ -453,8 +454,17 @@ void Editor::atomRightClick(QMouseEvent* e) void Editor::bondRightClick(QMouseEvent* e) { e->accept(); - m_molecule->removeBond(m_clickedObject.index); - m_molecule->emitChanged(Molecule::Bonds | Molecule::Removed); + // see if we need to adjust hydrogens + if (m_toolWidget->adjustHydrogens()) { + RWBond bond = m_molecule->bond(m_clickedObject.index); + RWAtom atom1 = bond.atom1(); + RWAtom atom2 = bond.atom2(); + m_molecule->removeBond(m_clickedObject.index); + QtGui::HydrogenTools::adjustHydrogens(atom1); + QtGui::HydrogenTools::adjustHydrogens(atom2); + } + m_molecule->emitChanged(Molecule::Atoms | Molecule::Bonds | + Molecule::Removed); } int expectedBondOrder(RWAtom atom1, RWAtom atom2)