-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert merge entries dialog to JavaFX (#4410)
* Convert to JavaFX * Fix diff display * Colorize diff * Fix build and implement review feedback * Move test file to tests * Fix exception * Maybe now... * Fix NPE * Remove obsolete language
- Loading branch information
1 parent
4cc775c
commit 274fed4
Showing
19 changed files
with
668 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/main/java/org/jabref/gui/actions/MergeEntriesAction.java
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/main/java/org/jabref/gui/mergeentries/DiffHighlighting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.jabref.gui.mergeentries; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javafx.scene.text.Text; | ||
|
||
import difflib.Delta; | ||
import difflib.DiffUtils; | ||
|
||
public class DiffHighlighting { | ||
|
||
private DiffHighlighting() { | ||
} | ||
|
||
public static List<Text> generateDiffHighlighting(String baseString, String modifiedString, String separator) { | ||
List<String> stringList = Arrays.asList(baseString.split(separator)); | ||
List<Text> result = stringList.stream().map(DiffHighlighting::forUnchanged).collect(Collectors.toList()); | ||
List<Delta<String>> deltaList = DiffUtils.diff(stringList, Arrays.asList(modifiedString.split(separator))).getDeltas(); | ||
Collections.reverse(deltaList); | ||
for (Delta<String> delta : deltaList) { | ||
int startPos = delta.getOriginal().getPosition(); | ||
List<String> lines = delta.getOriginal().getLines(); | ||
int offset = 0; | ||
switch (delta.getType()) { | ||
case CHANGE: | ||
for (String line : lines) { | ||
result.set(startPos + offset, forRemoved(line + separator)); | ||
offset++; | ||
} | ||
result.set(startPos + offset - 1, forRemoved(stringList.get((startPos + offset) - 1) + separator)); | ||
result.add(startPos + offset, forAdded(String.join(separator, delta.getRevised().getLines()))); | ||
break; | ||
case DELETE: | ||
for (String line : lines) { | ||
result.set(startPos + offset, forRemoved(line + separator)); | ||
offset++; | ||
} | ||
break; | ||
case INSERT: | ||
result.add(delta.getOriginal().getPosition(), forAdded(String.join(separator, delta.getRevised().getLines()))); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public static Text forChanged(String text) { | ||
Text node = new Text(text); | ||
node.getStyleClass().add("text-changed"); | ||
return node; | ||
} | ||
|
||
public static Text forUnchanged(String text) { | ||
Text node = new Text(text); | ||
node.getStyleClass().add("text-unchanged"); | ||
return node; | ||
} | ||
|
||
public static Text forAdded(String text) { | ||
Text node = new Text(text); | ||
node.getStyleClass().add("text-added"); | ||
return node; | ||
} | ||
|
||
public static Text forRemoved(String text) { | ||
Text node = new Text(text); | ||
node.getStyleClass().add("text-removed"); | ||
return node; | ||
} | ||
|
||
public static List<Text> generateSymmetricHighlighting(String baseString, String modifiedString, String separator) { | ||
List<String> stringList = Arrays.asList(baseString.split(separator)); | ||
List<Text> result = stringList.stream().map(text -> DiffHighlighting.forUnchanged(text + separator)).collect(Collectors.toList()); | ||
List<Delta<String>> deltaList = DiffUtils.diff(stringList, Arrays.asList(modifiedString.split(separator))).getDeltas(); | ||
Collections.reverse(deltaList); | ||
for (Delta<String> delta : deltaList) { | ||
int startPos = delta.getOriginal().getPosition(); | ||
List<String> lines = delta.getOriginal().getLines(); | ||
int offset = 0; | ||
switch (delta.getType()) { | ||
case CHANGE: | ||
for (String line : lines) { | ||
result.set(startPos + offset, forChanged(line + separator)); | ||
offset++; | ||
} | ||
break; | ||
case DELETE: | ||
for (String line : lines) { | ||
result.set(startPos + offset, forAdded(line + separator)); | ||
offset++; | ||
} | ||
break; | ||
case INSERT: | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/jabref/gui/mergeentries/MergeEntries.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.text-changed { | ||
-fx-fill: darkgreen; | ||
} | ||
|
||
.text-unchanged { | ||
|
||
} | ||
|
||
.text-added { | ||
-fx-fill: blue; | ||
} | ||
|
||
.text-removed { | ||
-fx-fill: red; | ||
} |
Oops, something went wrong.