]> 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 10990823ba07992af8ec468a70949c9004b043c3..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());
 
@@ -1706,6 +1724,8 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
                << endl;
 
        setCursor(cur, pit, pos, true, bound);
+       // remember new position.
+       cur.setTargetX();
 }