]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
The bug-fix in revision 16531 introduced another bug. This is the right fix. I did...
[lyx.git] / src / text.C
index 2ed8a3ca8589c71b18cfe4110e9f48ae7ad7c177..83eef76405db0bed7778559ffd0ee9a782f68aa6 100644 (file)
@@ -860,18 +860,25 @@ void LyXText::acceptChange(LCursor & cur)
        for (; pit <= et.pit(); ++pit) {
                pos_type left  = (pit == it.pit() ? it.pos() : 0);
                pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
-               pars_[pit].acceptChanges(left, right);
 
-               // merge paragraph if appropriate:
-               // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
-               //    pars_[pit].isDeleted(pars_[pit].size())) {
-               //      setCursorIntern(cur, pit + 1, 0);
-               //      backspacePos0(cur);
-               //}
+               // handle imaginary end-of-par character first
+               if (right == pars_[pit].size() && !pars_[pit].isUnchanged(right)) {
+                       if (pars_[pit].isInserted(right)) {
+                               pars_[pit].setChange(right, Change(Change::UNCHANGED));
+                       } else {
+                               // if (pit + 1 < et.pit()) {
+                               //      setCursorIntern(cur, pit + 1, 0);
+                               //      backspacePos0(cur);
+                               // }
+                       }
+               }
+
+               pars_[pit].acceptChanges(left, right);
        }
        finishUndo();
        cur.clearSelection();
-       setCursorIntern(cur, it.pit(), 0);
+       setCursorIntern(cur, it.pit(), it.pos());
+       cur.updateFlags(Update::Force);
 }
 
 
@@ -894,18 +901,25 @@ void LyXText::rejectChange(LCursor & cur)
        for (; pit <= et.pit(); ++pit) {
                pos_type left  = (pit == it.pit() ? it.pos() : 0);
                pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
-               pars_[pit].rejectChanges(left, right);
 
-               // merge paragraph if appropriate:      
-               // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
-               //    pars_[pit].isInserted(pars_[pit].size())) {
-               //      setCursorIntern(cur, pit + 1, 0);
-               //      backspacePos0(cur);
-               //}
+               // handle imaginary end-of-par character first
+               if (right == pars_[pit].size() && !pars_[pit].isUnchanged(right)) {
+                       if (pars_[pit].isDeleted(right)) {
+                               pars_[pit].setChange(right, Change(Change::UNCHANGED));
+                       } else {
+                               // if (pit + 1 < et.pit()) {
+                               //      setCursorIntern(cur, pit + 1, 0);
+                               //      backspacePos0(cur);
+                               // }
+                       }
+               }
+               
+               pars_[pit].rejectChanges(left, right);
        }
        finishUndo();
        cur.clearSelection();
-       setCursorIntern(cur, it.pit(), 0);
+       setCursorIntern(cur, it.pit(), it.pos());
+       cur.updateFlags(Update::Force);
 }
 
 
@@ -1661,45 +1675,6 @@ docstring LyXText::getPossibleLabel(LCursor & cur) const
 }
 
 
-//pos_type LyXText::x2pos(pit_type pit, int row, int x) const
-//{
-//     int lastx = 0;
-//     int currx = 0;
-//     Paragraph const & par = pars_[pit];
-//     Row const & r = par.rows()[row];
-//     int pos = r.pos();
-//     for (; currx < x && pos < r.endpos(); ++pos) {
-//             lastx = currx;
-//             currx += singleWidth(buffer, par, pos);
-//     }
-//     if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
-//             --pos;
-//     return pos;
-//}
-
-
-pos_type LyXText::x2pos(BufferView const & bv, pit_type pit, int row,
-               int x) const
-{
-       TextMetrics const & tm = bv.textMetrics(this);
-       ParagraphMetrics const & pm = tm.parMetrics(pit);
-       BOOST_ASSERT(!pm.rows().empty());
-       BOOST_ASSERT(row < int(pm.rows().size()));
-       bool bound = false;
-       Row const & r = pm.rows()[row];
-       return r.pos() + tm.getColumnNearX(pit, r, x, bound);
-}
-
-
-//int LyXText::pos2x(pit_type pit, pos_type pos) const
-//{
-//     Paragraph const & par = pars_[pit];
-//     Row const & r = par.rows()[row];
-//     int x = 0;
-//     pos -= r.pos();
-//}
-
-
 void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
 {
        BOOST_ASSERT(this == cur.text());
@@ -1745,7 +1720,6 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
                << endl;
 
        setCursor(cur, pit, pos, true, bound);
-       return;
 }