Patch #3399 2013-01-05 10:31

gentoo90

scintilla: fix changebar false positive at line add/del
Download
3399-scintilla_fix.patch (4.0 KB)
Category
Application::Bugfix
Status
Open
Close date
 
Assigned to
biplab
diff --git a/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.cxx b/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.cxx
index e583fa9..83adfb4 100644
--- a/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.cxx
+++ b/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.cxx
@@ -123,11 +123,15 @@ void LineVector::SetPerLine(PerLine *pl) {
 }
 
 /* CHANGEBAR begin */
-void LineVector::InsertText(int line, int delta, int edition, bool undoing) {
+void LineVector::InsertText(int line, int delta, int edition, bool undoing, bool lineUnchanged) {
 /* CHANGEBAR end */
     starts.InsertText(line, delta);
 /* CHANGEBAR begin */
-    changes.InsertText(line, edition, undoing);
+    // Line stays unchanged if inserted/deleted "something\n" at line start
+    // or "\nsomething" at line end
+    if (!lineUnchanged) {
+        changes.InsertText(line, edition, undoing);
+    }
 /* CHANGEBAR end */
 }
 
@@ -747,6 +751,7 @@ void CellBuffer::RemoveLine(int line, bool undoing) {
 
 /* CHANGEBAR begin */
 void CellBuffer::BasicInsertString(int position, const char *s, int insertLength, bool undoing) {
+    bool atFileEnd = position == substance.Length();
 /* CHANGEBAR end */
     if (insertLength == 0)
         return;
@@ -759,7 +764,10 @@ void CellBuffer::BasicInsertString(int position, const char *s, int insertLength
     bool atLineStart = lv.LineStart(lineInsert-1) == position;
     // Point all the lines after the insertion point further along in the buffer
 /* CHANGEBAR begin */
-    lv.InsertText(lineInsert-1, insertLength, uh.Edition(), undoing);
+    bool atLineEnd = (lv.LineStart(lineInsert) == position+1) || atFileEnd;
+    bool lineUnchanged = (atLineStart && (s[insertLength-1] == '\n')) ||
+        (atLineEnd && (s[0] == '\r' || s[0] == '\n'));
+    lv.InsertText(lineInsert-1, insertLength, uh.Edition(), undoing, lineUnchanged);
 /* CHANGEBAR end */
     char chPrev = substance.ValueAt(position - 1);
     char chAfter = substance.ValueAt(position + insertLength);
@@ -812,13 +820,19 @@ void CellBuffer::BasicDeleteChars(int position, int deleteLength, bool undoing)
         // If whole buffer is being deleted, faster to reinitialise lines data
         // than to delete each line.
         lv.Init();
+/* CHANGEBAR begin */
+        lv.InsertText(0, 0, uh.Edition(), undoing, false);
+/* CHANGEBAR end */
     } else {
         // Have to fix up line positions before doing deletion as looking at text in buffer
         // to work out which lines have been removed
 
         int lineRemove = lv.LineFromPosition(position) + 1;
 /* CHANGEBAR begin */
-        lv.InsertText(lineRemove-1, - (deleteLength), uh.Edition(), undoing);
+        bool atLineEnd = (lv.LineStart(lineRemove) == position+1);
+        char chAfter = substance.ValueAt(position + deleteLength);
+        bool lineUnchanged = (atLineEnd && (chAfter == '\r' || chAfter == '\n'));
+        lv.InsertText(lineRemove-1, - (deleteLength), uh.Edition(), undoing, lineUnchanged);
 /* CHANGEBAR end */
         char chPrev = substance.ValueAt(position - 1);
         char chBefore = chPrev;
@@ -854,7 +868,9 @@ void CellBuffer::BasicDeleteChars(int position, int deleteLength, bool undoing)
         }
         // May have to fix up end if last deletion causes cr to be next to lf
         // or removes one of a crlf pair
-        char chAfter = substance.ValueAt(position + deleteLength);
+/* CHANGEBAR begin */
+        // char chAfter = substance.ValueAt(position + deleteLength);
+/* CHANGEBAR end */
         if (chBefore == '\r' && chAfter == '\n') {
             // Using lineRemove-1 as cr ended line before start of deletion
 /* CHANGEBAR begin */
diff --git a/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.h b/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.h
index 4f92127..e3b3036 100644
--- a/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.h
+++ b/src/sdk/wxscintilla/src/scintilla/src/CellBuffer.h
@@ -67,7 +67,7 @@ public:
     void SetPerLine(PerLine *pl);
 
 /* CHANGEBAR begin */
-    void InsertText(int line, int delta, int edition, bool undoing);
+    void InsertText(int line, int delta, int edition, bool undoing, bool lineUnchanged);
     void InsertLine(int line, int position, bool lineStart, int edition, bool undoing);
 /* CHANGEBAR end */
     void SetLineStart(int line, int position);
gentoo90 2013-01-05 10:34

Also false negative on removing entire text

gentoo90 2013-01-06 10:03

So if we have:

|line 1

s|line 2

s|line 3

|line 4

adding new line will mark previous line as modified

|line 1

m|line 2

m|new line

s|line 3

|line 4

with this patch:

|line 1

s|line 2

m|new line

s|line 3

|line 4

mortenmacfly 2013-09-20 09:44

Biplab: did you find the time to give it a try?