]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
* output_plaintext.C: cosmetics in comment: line length cannot be < 0
[lyx.git] / src / text.C
index 611365fc554a9f7592f55cbbb13c685fe05b9b19..86110e88118276ce3d467fd89a3ff4c8715ad55b 100644 (file)
@@ -53,6 +53,7 @@
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
+#include "frontends/Selection.h"
 
 #include "insets/insettext.h"
 #include "insets/insetbibitem.h"
@@ -641,8 +642,10 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
                        pars_[next_par].applyLayout(tclass.defaultLayout());
        }
 
-       while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
-               pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges);
+       while (!pars_[next_par].empty() && pars_[next_par].isNewline(0)) {
+               if (!pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges))
+                       break; // the character couldn't be deleted physically due to change tracking
+       }
 
        ParIterator current_it(cur);
        ParIterator last_it(cur);
@@ -826,6 +829,7 @@ void LyXText::selectWord(LCursor & cur, word_location loc)
        cur.resetAnchor();
        setCursor(cur, to.pit(), to.pos());
        cur.setSelection();
+       theSelection().haveSelection(cur.selection());
 }
 
 
@@ -860,18 +864,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 +905,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);
 }
 
 
@@ -1544,7 +1562,7 @@ docstring LyXText::currentState(LCursor & cur)
        odocstringstream os;
 
        if (buf.params().trackChanges)
-               os << "[C] ";
+               os << _("[Change Tracking] ");
 
        Change change = par.lookupChange(cur.pos());
 
@@ -1661,45 +1679,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());
@@ -1735,7 +1714,6 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
 
        bool bound = false;
        int xx = x;
-       int right_margin = tm.rightMargin(pm);
        pos_type const pos = row.pos() 
                + tm.getColumnNearX(pit, row, xx, bound);
 
@@ -1746,7 +1724,8 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
                << endl;
 
        setCursor(cur, pit, pos, true, bound);
-       return;
+       // remember new position.
+       cur.setTargetX();
 }