winmerge icon indicating copy to clipboard operation
winmerge copied to clipboard

Substitution filters and PrediffLineFIlter.sct plugin not working

Open tumatanquang opened this issue 2 years ago • 20 comments

I am using version 2.16.30 (x64-PerUser). I want to ignore parts of the line so I wrote the rules according to two comments #597525 and #303958: These are rules in PrediffLineFIlter.sct: image P/s: I have correctly edited the desired file extension: image These are rules in Substitution Filters: image However, all of them do not work (red frame part): image I tried to disable 1 of 2 then tried again but the results were still similar. Something is not right here? Why does it not ignore the part of the line based on the rules that I have made?

tumatanquang avatar Jul 17 '23 05:07 tumatanquang

Unfortunately, "Replace with" doesn't allow you to specify a regular expression. If you change the settings of the PrediffLineFilter plugin as follows, will it work? image

sdottaka avatar Jul 17 '23 09:07 sdottaka

Unfortunately, "Replace with" doesn't allow you to specify a regular expression. If you change the settings of the PrediffLineFilter plugin as follows, will it work? image

No, it doesn't work either! image

tumatanquang avatar Jul 17 '23 13:07 tumatanquang

To reproduce the problem, we need to at least know all the characters to the left and right of the line. Could you put all the characters on the left and right of that one line here?

sdottaka avatar Jul 17 '23 13:07 sdottaka

To reproduce the problem, we need to at least know all the characters to the left and right of the line. Could you put all the characters on the left and right of that one line here?

Left line: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: Macro.bytMaxHintWidth = (byte)(Macro.SCREEN_WIDTH / 16 - 2); I also tried to disable Use RegExp but it did not work. image

tumatanquang avatar Jul 17 '23 13:07 tumatanquang

I think the below regex will do the trick.

~~Find what: (([^(]+) >> Macro.BW_(\d+))~~ Find what: \(([^(]+) >> Macro\.BW_(\d+)\) Replace with: $1 / $2

image

sdottaka avatar Jul 17 '23 21:07 sdottaka

I think the below regex will do the trick.

Find what: (([^(]+) >> Macro.BW_(\d+)) Replace with: $1 / $2

image

It does not work: image I tried escaped dot but it was the same, did not work: image

tumatanquang avatar Jul 18 '23 04:07 tumatanquang

I'm sorry. It appears that the backslashes disappeared due to the rules of markdown. How about changing it to the following?

Find what: \(([^(]+) >> Macro\.BW_(\d+)\) Replace with: $1 / $2

sdottaka avatar Jul 18 '23 11:07 sdottaka

I'm sorry. It appears that the backslashes disappeared due to the rules of markdown. How about changing it to the following?

Find what: \(([^(]+) >> Macro\.BW_(\d+)\) Replace with: $1 / $2

Yes, it worked in specific cases: Left line: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: Macro.bytMaxHintWidth = (byte)(Macro.SCREEN_WIDTH / 16 - 2);

  • But according to the information I have provided at first comment, Find what will have to be ignored with two values of Replace with. For example:

Macro.BW_16 will only identical with 2 values are: / 16 or >> 4 And will NOT be identical to other values with the above two values. The above regex rules can only match the first value (/ 16).

  • In other cases, it will not work. For example:

Left line: new byte[]{(byte)(_x + Param.getInstance().CAMERAX >> Macro.BW_16), (byte)(_y + Param.getInstance().CAMERAY >> Macro.BW_16)}; Right line: new byte[]{(byte)((_x + Param.getInstance().CAMERAX) / 16), (byte)((_y + Param.getInstance().CAMERAY) / 16)}; P/s: Only differ in >> Macro.BW_16 and/ 16 but also do not ignore it.

tumatanquang avatar Jul 18 '23 15:07 tumatanquang

Unfortunately, it's hard to get those patterns to work.

If you can tolerate the side effect of ignoring the difference between "(" and ")" then something like the following will work.

image

sdottaka avatar Jul 18 '23 22:07 sdottaka

Unfortunately, it's hard to get those patterns to work.

If you can tolerate the side effect of ignoring the difference between "(" and ")" then something like the following will work.

image

Certainly, I don't care about ignoring the difference between "(" and ")", but maybe you are misunderstood my point. Examples of the case of ignoring and not ignoring:

Find what: >> Macro.BW_16 Replace with: / 16 => will ignore Replace with: >> 4 => will ignore Replace with: / 4 OR >> 8 (and other value) => will NOT ignore

Examples of identical and non-identical cases that I would like:

Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: (Macro.SCREEN_WIDTH / 16 - 2); => Will identical. Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: ((Macro.SCREEN_WIDTH >> 4) - 2); => Will identical. Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: (Macro.SCREEN_WIDTH / 8 - 2); => Will NOT identical. Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: ((Macro.SCREEN_WIDTH >> 8) - 2); => Will NOT identical.

Your 4th – 7th regex rule is misinterpreting what I meant. And all those rules won't work in cases where the front of that line contains something:

Left line: return new byte[]{(byte)(_x + Param.getInstance().CAMERAX >> Macro.BW_16), (byte)(_y + Param.getInstance().CAMERAY >> Macro.BW_16)}; Right line: byte[] _xy = new byte[]{(byte)((_x + Param.getInstance().CAMERAX) / 16), (byte)((_y + Param.getInstance().CAMERAY) / 16)};

tumatanquang avatar Jul 19 '23 05:07 tumatanquang

Perhaps I am misunderstanding, but I think it is to be expected that the following differences are not ignored.

Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: (Macro.SCREEN_WIDTH / 8 - 2); => Will NOT identical.

If the Right line is (Macro.SCREEN_WIDTH / 16 - 2); I can see that the difference would be ignored, but since it is 8 and not 16, the result seems correct.

Left line: ((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: ((Macro.SCREEN_WIDTH >> 8) - 2); => Will NOT identical.

Similarly, if the Right line were (Macro.SCREEN_WIDTH >> 4 - 2); I can see that the difference would be ignored, but since it is 8 and not 4, the result seems correct.

Left line: return new byte[]{(byte)(_x + Param.getInstance().CAMERAX >> Macro.BW_16), (byte)(_y + Param.getInstance().CAMERAY >> Macro.BW_16 )}; } Right line: byte[] _xy = new byte[]{(byte)((_x + Param.getInstance().CAMERAX) / 16), (byte)((_y + Param.getInstance().CAMERAY) / 16)};

Unfortunately, if even a portion of the resultant lines substituted by the substitution filter do not match, the differences in those lines are not ignored. This is a limitation of the current substitution filter: if "byte[] _xy = " at the beginning of the Right line is "return" then the difference will be ignored.

sdottaka avatar Jul 19 '23 11:07 sdottaka

Perhaps I am misunderstanding, but I think it is to be expected that the following differences are not ignored.

If the Right line is (Macro.SCREEN_WIDTH / 16 - 2); I can see that the difference would be ignored, but since it is 8 and not 16, the result seems correct.

Similarly, if the Right line were (Macro.SCREEN_WIDTH >> 4 - 2); I can see that the difference would be ignored, but since it is 8 and not 4, the result seems correct.

I mean you misunderstood these syntax: image

Find what is always: >> Macro.BW_X. It will be identical to: >> X or X / 2. Suppose: >> Macro.BW_16 will be identical to >> 4 or identical to / 16 (>> Macro.BW_16 identical [>> 4 || / 16]).

Unfortunately, if even a portion of the resultant lines substituted by the substitution filter do not match, the differences in those lines are not ignored. This is a limitation of the current substitution filter: if "byte[] _xy = " at the beginning of the Right line is "return" then the difference will be ignored.

I mean: It doesn't matter to me whether byte[] _xy = and return are ignored or not. But >> Macro.BW_16 and / 16 was not ignored in this case: image

tumatanquang avatar Jul 19 '23 12:07 tumatanquang

I mean: It doesn't matter to me whether byte[] _xy = and return are ignored or not. But >> Macro.BW_16 and / 16 was not ignored in this case:

I understand that you want to ignore the difference between ">> Macro.BW_16" and "/16", but unfortunately the current Substitution filters only apply per line. If the difference between "byte[] _xy" and "return" is resolved, the difference on that line will be ignored.

sdottaka avatar Jul 20 '23 11:07 sdottaka

I mean: It doesn't matter to me whether byte[] _xy = and return are ignored or not. But >> Macro.BW_16 and / 16 was not ignored in this case:

I understand that you want to ignore the difference between ">> Macro.BW_16" and "/16", but unfortunately the current Substitution filters only apply per line. If the difference between "byte[] _xy" and "return" is resolved, the difference on that line will be ignored.

Yes. However, both the Substitution Filters and PrediffLineFilter.sct plugin are not working correctly. Now I just want it to ignore (not highlight) when encountering the cases that I have specified (>> Macro.BW_X). It doesn't matter if it ignores other cases that have changes in the same line or not.

tumatanquang avatar Jul 20 '23 12:07 tumatanquang

@sdottaka I have created a Find what and Replace with table to indicate my desired behavior: For each value in the Find what column, if it has been changed to the corresponding value in the Replace with column, the tool will igore (not highlight) those changes. image

tumatanquang avatar Jul 20 '23 15:07 tumatanquang

Unfortunately, the 5th to 8th definitions will not work. This is because these definitions are applied sequentially from the top, but "Macro.BW_*" has already been replaced with "/ *" by the 1st to 4th definitions. Therefore, when applying the 5th to 8th definitions, "Macro.BW_" no longer exists.

sdottaka avatar Jul 20 '23 23:07 sdottaka

Unfortunately, the 5th to 8th definitions will not work. This is because these definitions are applied sequentially from the top, but "Macro.BW_*" has already been replaced with "/ *" by the 1st to 4th definitions. Therefore, when applying the 5th to 8th definitions, "Macro.BW_" no longer exists.

It seems that this is a highlight error that has occurred. As far as I understand, the PrediffLineFilter.sct plugin will replace the Find what value with the corresponding value in Replace with. In the example case you provided: Left line: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); Right line: Macro.bytMaxHintWidth = (byte)(Macro.SCREEN_WIDTH / 16 - 2); The left line will be replaced with: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH / 16) - 2); If so, the tool should only highlight left line as follows: Macro.bytMaxHintWidth = (byte)((Macro.SCREEN_WIDTH >> Macro.BW_16) - 2); But in reality, it has ignored all the changes from the PrediffLineFilter.sct plugin and highlighted the changes as if there were no changes from the PrediffLineFilter.sct plugin.

tumatanquang avatar Jul 21 '23 10:07 tumatanquang

Isn't it because there is a definition that ignores "(" and ")" like the following? Also, I think my wording is bad, so I'll say it again, Substitution filters such as PrediffLineFilter.sct are only applied line by line. Even if two lines are almost identical after being substituted by the Substitution filters, all inline differences will be highlighted if there are any remaining differences within the line.

image

sdottaka avatar Jul 21 '23 12:07 sdottaka

Isn't it because there is a definition that ignores "(" and ")" like the following? Also, I think my wording is bad, so I'll say it again, Substitution filters such as PrediffLineFilter.sct are only applied line by line. Even if two lines are almost identical after being substituted by the Substitution filters, all inline differences will be highlighted if there are any remaining differences within the line.

I apologize, because I explain it is confusing. I used Beyond Compare software. That software has the Replacements feature, I have set the rules I want. I want WinMerge to do the same thing:

  • The part I want WinMerge to ignore (DO NOT highlight): The blue background on lines 1 and 2.
  • The part I want WinMerge to NOT ignore (highlight): The red background.
  • The current situation I encounter on WinMerge: Line 3.

image

P/s: The right-hand side of line 3 has been edited by me using photo editing software to change the value to / 16.

tumatanquang avatar Jul 21 '23 16:07 tumatanquang

I understand that you want it to behave like the image above, but with the current WinMerge Substitution filters feature, you can't get results like the one above. I understand this issuse is an enhancement request.

sdottaka avatar Jul 22 '23 01:07 sdottaka