jabref icon indicating copy to clipboard operation
jabref copied to clipboard

Duplicate Manager - Show Diff - Highlight characters --> highlights wrong characters

Open ThiloteE opened this issue 3 years ago • 1 comments

JabRef 5.8 commit 0b580790d7a323ccdb445b8a8a6e8dd4d5917e69

How to reproduce:

Have two entries with groups:

A) groups = {test1, test2, test3}, B) groups = {test1, test4, test2, test3},

Reality: grafik

Expected: grafik

ThiloteE avatar Aug 13 '22 19:08 ThiloteE

This can be done by changing the default diff separator to the groups separator , when highlighting groups differences. This can be useful for highlighting keywords and files differences too.

https://github.com/JabRef/jabref/blob/bd77d7336fde1c4618f2e67dcf2ef22ceb1cda77/src/main/java/org/jabref/gui/mergeentries/newmergedialog/diffhighlighter/DiffHighlighter.java#L38-L40

HoussemNasri avatar Aug 14 '22 15:08 HoussemNasri

Hi I think I can fix this issue, could you assign this issue to me?

Anqiii-hub avatar Oct 16 '22 03:10 Anqiii-hub

Thank you :-)

As a general advice for newcomers: check out https://github.com/JabRef/jabref/blob/main/CONTRIBUTING.md for a start. Also, https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace is worth having a look at. Feel free to ask if you have any questions here on GitHub or also at JabRef's Gitter chat.

Try to open a (draft) pull request early on, so that people can see you are working on the issue and so that they can see the direction the pull request is heading towards. This way, you will likely receive valuable feedback.

ThiloteE avatar Oct 16 '22 08:10 ThiloteE

@HoussemNasri Did you mean this preference?

grafik

I think the diff separator should probably always be similar to what the user has set in this preference

ThiloteE avatar Oct 16 '22 08:10 ThiloteE

No, they are totally different. The diff highlighter separator can be either a space or an empty string. It's used for splitting the text before comparison. For example for diffing abcd w and ebdd sa, we can split the texts by space and compare them: abcd vs ebdd and w vs sa, or we can compare them character by character (split by an empty string): a vs e, b vs b, etc.

HoussemNasri avatar Oct 16 '22 12:10 HoussemNasri

This can be done by changing the default diff separator to the groups separator , when highlighting groups differences. This can be useful for highlighting keywords and files differences too.

https://github.com/JabRef/jabref/blob/bd77d7336fde1c4618f2e67dcf2ef22ceb1cda77/src/main/java/org/jabref/gui/mergeentries/newmergedialog/diffhighlighter/DiffHighlighter.java#L38-L40

Hi @ThiloteE,

  • I followed the above method and created a pull request. Could you please review my codes? I made the following changes:

  • When calling showDiff method, I first check if the field is "Groups", if the field is Groups, I use "," as a seperator. I didn't change the seperator of other field. And the result shows as follows: Screen Shot 2022-10-23 at 8 34 29 pm

  • However, this method has its shortcoming, it only works when the user chooses to use "," to seperate different groups. Otherwise, the results will be like the following: Screen Shot 2022-10-23 at 8 36 02 pm

  • To solve this bug, I also choose to check if the leftValue or rightValue contains(","), if neither of the value contains(","), I choose to still use "" as the seperator. The results is like the following, kind of solving the issue. Screen Shot 2022-10-23 at 8 52 17 pm

  • @HoussemNasri said the seperator can also be used in the field "Keywords", however I think it‘s unnecessary. As the issue only occurs when each word has the same part (i.e "test"), the keywords field unlikely to have many words containing the same part.

  • However, I know this method doesn't solve the whold issue. I also tried if I could seperate the field value with "," first and then separate with ""; or use other methods in the com.github.difflib.DiffUtils (the library we use). Both of these two methods seem to need to change a lot of places and I failed. If you have any other suggestions, plz let me know.

Anqiii-hub avatar Oct 23 '22 10:10 Anqiii-hub

Hi @ThiloteE and @HoussemNasri , I found myself failed a lot of styleCheck, should I create another pull request or just reset git history and push again on the same pull request? thank you 😊

Anqiii-hub avatar Oct 24 '22 08:10 Anqiii-hub

I think you can simply create another commit to your pull request by pushing towards the same branch

ThiloteE avatar Oct 24 '22 09:10 ThiloteE