WMDE-Fisch has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/405700 )

Change subject: [WIP] Associate new lines with upper paragraph
......................................................................

[WIP] Associate new lines with upper paragraph

This changes the way lines are split initially for the table view.
When an empty new line is found, the new line char will be added
as part of the upper line/paragraph and the split is done afterwards.

This will make most diffs look more intuitve.

ToDo:
- Make removing an empty line visible
- Fix line number counting

Bug: T184531
Change-Id: I412c153e4ea61599bac457e3c3f2a2e6cded2cd9
---
M TableDiff.cpp
M TableDiff.h
M Wikidiff2.h
M tests/001.phpt
M tests/007.phpt
M tests/008.phpt
6 files changed, 84 insertions(+), 84 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/php/wikidiff2 
refs/changes/00/405700/1

diff --git a/TableDiff.cpp b/TableDiff.cpp
index 964f1c8..a30ebfd 100644
--- a/TableDiff.cpp
+++ b/TableDiff.cpp
@@ -2,6 +2,28 @@
 #include "Wikidiff2.h"
 #include "TableDiff.h"
 
+void TableDiff::explodeLines(const String & text, StringVector &lines)
+{
+       String::const_iterator ptr = text.begin();
+       while (ptr != text.end()) {
+               String::const_iterator ptr2 = std::find(ptr, text.end(), '\n');
+               String::const_iterator ptr3 = std::next(ptr2);
+
+               // Treat empty new lines as part of the paragraph above
+               if ( *ptr3 == '\n' ) {
+                       ++ptr2;
+                       lines.push_back(String(ptr, std::next(ptr3)));
+               } else {
+                       lines.push_back(String(ptr, ptr2));
+               }
+
+               ptr = ptr2;
+               if (ptr != text.end()) {
+                       ++ptr;
+               }
+       }
+}
+
 void TableDiff::printAdd(const String & line)
 {
        result += "<tr>\n"
diff --git a/TableDiff.h b/TableDiff.h
index 9ec560d..5fc4053 100644
--- a/TableDiff.h
+++ b/TableDiff.h
@@ -14,6 +14,8 @@
                void printContext(const String& input);
 
                void printWordDiffSide(WordDiff& worddiff, bool added);
+
+               void explodeLines(const String & text, StringVector &lines);
 };
 
 #endif
diff --git a/Wikidiff2.h b/Wikidiff2.h
index 185bfb6..cb8b554 100644
--- a/Wikidiff2.h
+++ b/Wikidiff2.h
@@ -16,7 +16,7 @@
 #include <set>
 #include <memory>
 
-#define WIKIDIFF2_VERSION_STRING               "1.5.4"
+#define WIKIDIFF2_VERSION_STRING               "1.5.5"
 
 class Wikidiff2 {
        public:
@@ -68,7 +68,7 @@
                void printText(const String & input);
                void debugPrintWordDiff(WordDiff & worddiff);
 
-               void explodeLines(const String & text, StringVector &lines);
+               virtual void explodeLines(const String & text, StringVector 
&lines);
 
                bool printMovedLineDiff(StringDiff & linediff, int opIndex, int 
opLine, int maxMovedLines);
 };
diff --git a/tests/001.phpt b/tests/001.phpt
index 716d470..ab4f1fd 100644
--- a/tests/001.phpt
+++ b/tests/001.phpt
@@ -126,15 +126,13 @@
 </tr>
 <tr>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>== Added line ==</div></td>
+  <td class="diff-context"><div>== Added line ==
+
+</div></td>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>== Added line ==</div></td>
-</tr>
-<tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
+  <td class="diff-context"><div>== Added line ==
+
+</div></td>
 </tr>
 <tr>
   <td colspan="2" class="diff-empty">&#160;</td>
@@ -143,15 +141,13 @@
 </tr>
 <tr>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>== Removed line ==</div></td>
+  <td class="diff-context"><div>== Removed line ==
+
+</div></td>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>== Removed line ==</div></td>
-</tr>
-<tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
+  <td class="diff-context"><div>== Removed line ==
+
+</div></td>
 </tr>
 <tr>
   <td class="diff-marker">−</td>
@@ -386,13 +382,11 @@
 </tr>
 <tr>
   <td class="diff-marker">−</td>
-  <td class="diff-deletedline"><div>blah blah blah <del class="diffchange 
diffchange-inline">1</del></div></td>
+  <td class="diff-deletedline"><div>blah blah blah <del class="diffchange 
diffchange-inline">1</del>
+
+</div></td>
   <td class="diff-marker">+</td>
-  <td class="diff-addedline"><div>blah blah blah <ins class="diffchange 
diffchange-inline">2</ins></div></td>
-</tr>
-<tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
+  <td class="diff-addedline"><div>blah blah blah <ins class="diffchange 
diffchange-inline">2</ins>
+
+</div></td>
 </tr>
diff --git a/tests/007.phpt b/tests/007.phpt
index f37fe16..40b44fb 100644
--- a/tests/007.phpt
+++ b/tests/007.phpt
@@ -43,72 +43,60 @@
   <td colspan="2" class="diff-lineno"><!--LINE 1--></td>
 </tr>
 <tr>
-  <td class="diff-marker"><a class="mw-diff-movedpara-left" 
href="#movedpara_6_1_rhs">&#x26AB;</a></td>
-  <td class="diff-deletedline"><div><a name="movedpara_0_0_lhs"></a>Substance, 
in the truest<del class="diffchange diffchange-inline"> and primary</del> and 
most definite sense of the word, is that which is neither predicable of a 
subject nor present in a subject; for instance, the individual man or horse. 
But in a secondary sense those things are called substances within which, as 
species, the primary substances are included; also those which, as genera, 
include the species. For instance, the individual man is included in the 
species 'man', and the genus to which the species belongs is 'animal'; these, 
therefore—that is to say, the species 'man' and the genus 'animal,-are termed 
secondary substances.</div></td>
-  <td colspan="2" class="diff-empty">&#160;</td>
-</tr>
-<tr>
-  <td class="diff-marker">−</td>
-  <td class="diff-deletedline"></td>
+  <td class="diff-marker"><a class="mw-diff-movedpara-left" 
href="#movedpara_7_0_rhs">&#x26AB;</a></td>
+  <td class="diff-deletedline"><div><a name="movedpara_0_0_lhs"></a>Substance, 
in the truest<del class="diffchange diffchange-inline"> and primary</del> and 
most definite sense of the word, is that which is neither predicable of a 
subject nor present in a subject; for instance, the individual man or horse. 
But in a secondary sense those things are called substances within which, as 
species, the primary substances are included; also those which, as genera, 
include the species. For instance, the individual man is included in the 
species 'man', and the genus to which the species belongs is 'animal'; these, 
therefore—that is to say, the species 'man' and the genus 'animal,-are termed 
secondary substances.<del class="diffchange diffchange-inline">
+
+</del></div></td>
   <td colspan="2" class="diff-empty">&#160;</td>
 </tr>
 <tr>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>It is plain from what has been said that both 
the name and the definition of the predicate must be predicable of the subject. 
For instance, 'man' is predicated of the individual man. Now in this case the 
name of the species 'man' is applied to the individual, for we use the term 
'man' in describing the individual; and the definition of 'man' will also be 
predicated of the individual man, for the individual man is both man and 
animal. Thus, both the name and the definition of the species are predicable of 
the individual.</div></td>
+  <td class="diff-context"><div>It is plain from what has been said that both 
the name and the definition of the predicate must be predicable of the subject. 
For instance, 'man' is predicated of the individual man. Now in this case the 
name of the species 'man' is applied to the individual, for we use the term 
'man' in describing the individual; and the definition of 'man' will also be 
predicated of the individual man, for the individual man is both man and 
animal. Thus, both the name and the definition of the species are predicable of 
the individual.
+
+</div></td>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>It is plain from what has been said that both 
the name and the definition of the predicate must be predicable of the subject. 
For instance, 'man' is predicated of the individual man. Now in this case the 
name of the species 'man' is applied to the individual, for we use the term 
'man' in describing the individual; and the definition of 'man' will also be 
predicated of the individual man, for the individual man is both man and 
animal. Thus, both the name and the definition of the species are predicable of 
the individual.</div></td>
+  <td class="diff-context"><div>It is plain from what has been said that both 
the name and the definition of the predicate must be predicable of the subject. 
For instance, 'man' is predicated of the individual man. Now in this case the 
name of the species 'man' is applied to the individual, for we use the term 
'man' in describing the individual; and the definition of 'man' will also be 
predicated of the individual man, for the individual man is both man and 
animal. Thus, both the name and the definition of the species are predicable of 
the individual.
+
+</div></td>
 </tr>
 <tr>
   <td colspan="2" class="diff-empty">&#160;</td>
-  <td class="diff-marker">+</td>
-  <td class="diff-addedline"></td>
-</tr>
-<tr>
-  <td colspan="2" class="diff-empty">&#160;</td>
-  <td class="diff-marker"><a class="mw-diff-movedpara-right" 
href="#movedpara_4_1_lhs">&#x26AB;</a></td>
-  <td class="diff-addedline"><div><a name="movedpara_2_1_rhs"></a>Everything 
except primary substances is either predicable of a primary substance or 
present in a primary substance. This becomes evident by reference to particular 
instances which occur. 'Animal' is predicated of the species 'man', therefore 
of the individual man, for if there were no individual man of whom it could be 
predicated, it could not be predicated of the species 'man' at all. Again, 
colour is present in body, therefore in individual bodies, for if there were no 
individual body in which it was present, it could not be present in body at 
all. Thus everything except primary substances is either predicated of primary 
substances, or is present in them, and if these last did not exist, it would be 
impossible for anything else to exist<ins class="diffchange 
diffchange-inline">. Never underestimate lawns</ins>.</div></td>
+  <td class="diff-marker"><a class="mw-diff-movedpara-right" 
href="#movedpara_4_0_lhs">&#x26AB;</a></td>
+  <td class="diff-addedline"><div><a name="movedpara_2_0_rhs"></a>Everything 
except primary substances is either predicable of a primary substance or 
present in a primary substance. This becomes evident by reference to particular 
instances which occur. 'Animal' is predicated of the species 'man', therefore 
of the individual man, for if there were no individual man of whom it could be 
predicated, it could not be predicated of the species 'man' at all. Again, 
colour is present in body, therefore in individual bodies, for if there were no 
individual body in which it was present, it could not be present in body at 
all. Thus everything except primary substances is either predicated of primary 
substances, or is present in them, and if these last did not exist, it would be 
impossible for anything else to exist<ins class="diffchange 
diffchange-inline">. Never underestimate lawns</ins>.
+
+</div></td>
 </tr>
 <tr>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
+  <td class="diff-context"><div>With regard, on the other hand, to those 
things which are present in a subject, it is generally the case that neither 
their name nor their definition is predicable of that in which they are 
present. Though, however, the definition is never predicable, there is nothing 
in certain cases to prevent the name being used. For instance, 'white' being 
present in a body is predicated of that in which it is present, for a body is 
called white: the definition, however, of the colour 'white' is never 
predicable of the body.
+
+</div></td>
   <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
+  <td class="diff-context"><div>With regard, on the other hand, to those 
things which are present in a subject, it is generally the case that neither 
their name nor their definition is predicable of that in which they are 
present. Though, however, the definition is never predicable, there is nothing 
in certain cases to prevent the name being used. For instance, 'white' being 
present in a body is predicated of that in which it is present, for a body is 
called white: the definition, however, of the colour 'white' is never 
predicable of the body.
+
+</div></td>
 </tr>
 <tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>With regard, on the other hand, to those 
things which are present in a subject, it is generally the case that neither 
their name nor their definition is predicable of that in which they are 
present. Though, however, the definition is never predicable, there is nothing 
in certain cases to prevent the name being used. For instance, 'white' being 
present in a body is predicated of that in which it is present, for a body is 
called white: the definition, however, of the colour 'white' is never 
predicable of the body.</div></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>With regard, on the other hand, to those 
things which are present in a subject, it is generally the case that neither 
their name nor their definition is predicable of that in which they are 
present. Though, however, the definition is never predicable, there is nothing 
in certain cases to prevent the name being used. For instance, 'white' being 
present in a body is predicated of that in which it is present, for a body is 
called white: the definition, however, of the colour 'white' is never 
predicable of the body.</div></td>
-</tr>
-<tr>
-  <td class="diff-marker">−</td>
-  <td class="diff-deletedline"></td>
+  <td class="diff-marker"><a class="mw-diff-movedpara-left" 
href="#movedpara_2_0_rhs">&#x26AB;</a></td>
+  <td class="diff-deletedline"><div><a name="movedpara_4_0_lhs"></a>Everything 
except primary substances is either predicable of a primary substance or 
present in a primary substance. This becomes evident by reference to particular 
instances which occur. 'Animal' is predicated of the species 'man', therefore 
of the individual man, for if there were no individual man of whom it could be 
predicated, it could not be predicated of the species 'man' at all. Again, 
colour is present in body, therefore in individual bodies, for if there were no 
individual body in which it was present, it could not be present in body at 
all. Thus everything except primary substances is either predicated of primary 
substances, or is present in them, and if these last did not exist, it would be 
impossible for anything else to exist.
+
+</div></td>
   <td colspan="2" class="diff-empty">&#160;</td>
 </tr>
 <tr>
-  <td class="diff-marker"><a class="mw-diff-movedpara-left" 
href="#movedpara_2_1_rhs">&#x26AB;</a></td>
-  <td class="diff-deletedline"><div><a name="movedpara_4_1_lhs"></a>Everything 
except primary substances is either predicable of a primary substance or 
present in a primary substance. This becomes evident by reference to particular 
instances which occur. 'Animal' is predicated of the species 'man', therefore 
of the individual man, for if there were no individual man of whom it could be 
predicated, it could not be predicated of the species 'man' at all. Again, 
colour is present in body, therefore in individual bodies, for if there were no 
individual body in which it was present, it could not be present in body at 
all. Thus everything except primary substances is either predicated of primary 
substances, or is present in them, and if these last did not exist, it would be 
impossible for anything else to exist.</div></td>
   <td colspan="2" class="diff-empty">&#160;</td>
+  <td class="diff-marker"><a class="mw-diff-movedpara-right" 
href="#movedpara_6_0_lhs">&#x26AB;</a></td>
+  <td class="diff-addedline"><div><a name="movedpara_5_0_rhs"></a>Lawns are 
very important. Never underestimate lawns. Never underestimate the power of hot 
rollers for your hair and eyelash curlers for your eyelashes. You can never 
underestimate the stupidity of the general public.<ins class="diffchange 
diffchange-inline">
+
+</ins></div></td>
 </tr>
 <tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
-</tr>
-<tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>Lawns are very important. Never underestimate 
lawns. Never underestimate the power of hot rollers for your hair and eyelash 
curlers for your eyelashes. You can never underestimate the stupidity of the 
general public.</div></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"><div>Lawns are very important. Never underestimate 
lawns. Never underestimate the power of hot rollers for your hair and eyelash 
curlers for your eyelashes. You can never underestimate the stupidity of the 
general public.</div></td>
-</tr>
-<tr>
+  <td class="diff-marker"><a class="mw-diff-movedpara-left" 
href="#movedpara_5_0_rhs">&#x26AB;</a></td>
+  <td class="diff-deletedline"><div><a name="movedpara_6_0_lhs"></a>Lawns are 
very important. Never underestimate lawns. Never underestimate the power of hot 
rollers for your hair and eyelash curlers for your eyelashes. You can never 
underestimate the stupidity of the general public.</div></td>
   <td colspan="2" class="diff-empty">&#160;</td>
-  <td class="diff-marker">+</td>
-  <td class="diff-addedline"></td>
 </tr>
 <tr>
   <td colspan="2" class="diff-empty">&#160;</td>
   <td class="diff-marker"><a class="mw-diff-movedpara-right" 
href="#movedpara_0_0_lhs">&#x26AB;</a></td>
-  <td class="diff-addedline"><div><a name="movedpara_6_1_rhs"></a>Substance, 
in the truest and most definite sense of the word, is that which is neither 
predicable of a subject nor present in a subject; for instance, the individual 
man or horse. But in a secondary sense those things are called substances 
within which, as species, the primary substances are included; also those 
which, as genera, include the species. For instance, the individual man is 
included in the species 'man', and the genus to which the species belongs is 
'animal'; these, therefore—that is to say, the species 'man' and the genus 
'animal,-are termed secondary substances.</div></td>
-</tr>
\ No newline at end of file
+  <td class="diff-addedline"><div><a name="movedpara_7_0_rhs"></a>Substance, 
in the truest and most definite sense of the word, is that which is neither 
predicable of a subject nor present in a subject; for instance, the individual 
man or horse. But in a secondary sense those things are called substances 
within which, as species, the primary substances are included; also those 
which, as genera, include the species. For instance, the individual man is 
included in the species 'man', and the genus to which the species belongs is 
'animal'; these, therefore—that is to say, the species 'man' and the genus 
'animal,-are termed secondary substances.</div></td>
+</tr>
diff --git a/tests/008.phpt b/tests/008.phpt
index f1322c9..3ec4bab 100644
--- a/tests/008.phpt
+++ b/tests/008.phpt
@@ -32,23 +32,17 @@
 </tr>
 <tr>
   <td class="diff-marker">−</td>
-  <td class="diff-deletedline"><div>AAAAA AAAAA <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del></div></td>
+  <td class="diff-deletedline"><div>AAAAA AAAAA <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del>
+
+</div></td>
   <td class="diff-marker">+</td>
-  <td class="diff-addedline"><div>AAAAA AAAAA <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins></div></td>
-</tr>
-<tr>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
-  <td class="diff-marker">&#160;</td>
-  <td class="diff-context"></td>
+  <td class="diff-addedline"><div>AAAAA AAAAA <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins>
+
+</div></td>
 </tr>
 <tr>
   <td class="diff-marker">−</td>
-  <td class="diff-deletedline"><div>AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA 
AAAAA AAAAA AAAAA</div></td>
-  <td colspan="2" class="diff-empty">&#160;</td>
-</tr>
-<tr>
-  <td colspan="2" class="diff-empty">&#160;</td>
+  <td class="diff-deletedline"><div>AAAAA <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del> <del class="diffchange 
diffchange-inline">AAAAA</del></div></td>
   <td class="diff-marker">+</td>
-  <td class="diff-addedline"><div>AAAAA BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB 
BBBBB BBBBB BBBBB</div></td>
+  <td class="diff-addedline"><div>AAAAA <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins> <ins class="diffchange 
diffchange-inline">BBBBB</ins></div></td>
 </tr>

-- 
To view, visit https://gerrit.wikimedia.org/r/405700
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I412c153e4ea61599bac457e3c3f2a2e6cded2cd9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/php/wikidiff2
Gerrit-Branch: master
Gerrit-Owner: WMDE-Fisch <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to