Hi,

I rethought the logic of stripLeadingSpaces() and came to the conclusion that it is not a good idea to remove the spaces in change tracking mode: imagine that your co-author inserts a par break that you don't like. If you revert his par break (revert = reject change, not undo!), you would like to see the spaces restored.

I changed stripLeadingSpaces accordingly (see attached patch) but unfortunately I ran into two problems that look like painting/update problems.

By switching CT on and off, create a one-line document that looks like this:

hello<deleted space><space>world

Now, in CT mode, press return after "hello". The expected output is:

hello
<deleted space><deleted space>world

However, this is what I get on screen:

hello
<deleted space><space>world

In other words, the deletion of the second space is not shown on screen.

Even worse, if I move the cursor up (to first line) and down (back to second line), LyX crashes!

I can't imagine that my fix is responsible for this crash. Abdel, do you have any idea of what goes wrong?

Michael
Index: src/paragraph.h
===================================================================
--- src/paragraph.h     (Revision 16671)
+++ src/paragraph.h     (Arbeitskopie)
@@ -346,7 +346,7 @@
        int getPositionOfInset(InsetBase const * inset) const;
 
        /// Returns the number of line breaks and white-space stripped at the 
start
-       int stripLeadingSpaces();
+       int stripLeadingSpaces(bool trackChanges);
 
        /// return true if we allow multiple spaces
        bool isFreeSpacing() const;
Index: src/text2.C
===================================================================
--- src/text2.C (Revision 16671)
+++ src/text2.C (Arbeitskopie)
@@ -1231,7 +1231,7 @@
                return true;
        }
 
-       if (oldpar.stripLeadingSpaces())
+       if (oldpar.stripLeadingSpaces(cur.buffer().params().trackChanges))
                need_anchor_change = true;
 
        return false;
Index: src/CutAndPaste.C
===================================================================
--- src/CutAndPaste.C   (Revision 16671)
+++ src/CutAndPaste.C   (Arbeitskopie)
@@ -270,7 +270,7 @@
                        pars[last_paste].makeSameLayout(pars[last_paste + 1]);
                        mergeParagraph(buffer.params(), pars, last_paste);
                } else {
-                       pars[last_paste + 1].stripLeadingSpaces();
+                       pars[last_paste + 
1].stripLeadingSpaces(buffer.params().trackChanges);
                        ++last_paste;
                }
        }
@@ -309,7 +309,7 @@
                    (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 
1]))) {
                        pos_type const thissize = pars[pit].size();
                        if (doclear)
-                               pars[pit + 1].stripLeadingSpaces();
+                               pars[pit + 
1].stripLeadingSpaces(params.trackChanges);
                        mergeParagraph(params, pars, pit);
                        --endpit;
                        if (pit == endpit)
@@ -539,7 +539,7 @@
 
                // sometimes necessary
                if (doclear)
-                       text->paragraphs()[begpit].stripLeadingSpaces();
+                       
text->paragraphs()[begpit].stripLeadingSpaces(bp.trackChanges);
 
                // cutSelection can invalidate the cursor so we need to set
                // it anew. (Lgb)
Index: src/paragraph.C
===================================================================
--- src/paragraph.C     (Revision 16671)
+++ src/paragraph.C     (Arbeitskopie)
@@ -560,19 +560,22 @@
 }
 
 
-int Paragraph::stripLeadingSpaces()
+int Paragraph::stripLeadingSpaces(bool trackChanges)
 {
        if (isFreeSpacing())
                return 0;
 
-       int i = 0;
-       while (!empty() && (isNewline(0) || isLineSeparator(0))
-               && !isDeleted(0)) {
-               eraseChar(0, false); // no change tracking here
-               ++i;
+       int pos = 0;
+       int count = 0;
+
+       while (pos < size() && (isNewline(pos) || isLineSeparator(pos))) {
+               if (eraseChar(pos, trackChanges))
+                       ++count;
+               else
+                       ++pos;
        }
 
-       return i;
+       return count;
 }
 
 

Reply via email to