Re: [code] [textadept] Updated File Diff Module

From: Gabriel Dubatti <gdubatti.att.gmail.com>
Date: Sat, 25 Feb 2017 15:54:32 -0300

Hi Mitchell,

El 25/02/17 a las 12:42, Mitchell escribió:
> Hi Gabriel,
>
> On Sat, 25 Feb 2017, Gabriel Dubatti wrote:
>
>> Hi Mitchell,
>>
>>
>> El 25/02/17 a las 02:11, Mitchell escribió:
>>> Hi Gabriel,
>>>
>>> On Thu, 23 Feb 2017, Mitchell wrote:
>>>
>>>> Hi Gabriel,
>>>>
>>>> On Thu, 23 Feb 2017, Gabriel Dubatti wrote:
>>>>
>>>>> Hi Mitchell,
>>>>>
>>>>> When you add / remove lines at the top of one file, the other
>>>>> can't align properly because annotations are always shown below
>>>>> text lines.
>>>>>
>>>>> The following image shows what happens after adding 3 blank lines
>>>>> at the top (NOT OK) and after the first line (OK):
>>>>>
>>>>> error
>>>>>
>>>>> Any idea on how to solve this?
>>>>
>>>> This is a bug. I don't think there's a workaround. Thanks for the
>>>> report and the helpful image.
>>>
>>> Actually, I misread your analysis. Sorry about that (it has been a
>>> very long week). You are correct, and this appears to be a
>>> limitation with the implementation. I'm not sure how to solve this
>>> :( I'm open to suggestions.
>>>
>>> Cheers,
>>> Mitchell
>> I think there are 2 options to mitigate this limitation:
>> 1) move the annotations from line "0" to line 1 (in this case only
>> the first line will be shown out of place)
>> 2) force to show the first line as a modification (I'm not sure
>> how this will look until testing)
>>
>> BTW, I'm currently working on a C version of the file/string diff
>> algorithm (that doesn't require lots of strings creation/destruction
>> like the current C++ version):
>> https://github.com/gabdub/ta-tweaks/blob/master/tatoolbar/src/ta_filediff.c
>> (work in progress alert)
>>
>> I'll try to test this options and see what I get and let you know.
>
> Thanks for taking the initiative. I look forward to seeing any
> solution you can come up with, as I don't have much time to try and
> fix this edge case.
>
> Cheers,
> Mitchell

At least for me, the option (1) don't look bad at all.

See the pictures:

OK case: 3 lines added under line #1

Special case I: "line #0" spaces moved to line #1.

Special case II: line #0 and line #1 spaces must be added.

Here's the code I'm currently using.

   --show the missing lines using annotations
   local nlin0= 0
   r= filediff.getdiff( 1, 3 ) --buffer#1, 3=get blank lines list
   for i=1,#r,2 do
     local lin= r[i]
     local n= r[i+1]
     if lin == 0 then
       nlin0= n --can't put annotations in line #0, move them to line 1
     else
       if lin == 1 then
         n= n + nlin0 --join line 0 and line 1 spaces
         nlin0= 0
       end
       buffer1.annotation_text[lin-1] = string.rep('\n', n-1)
     end
   end
   --add pending line 0 spaces
   if nlin0 > 0 then buffer1.annotation_text[0] = string.rep('\n',
nlin0-1) end

   --the same for buffer #2

-------------------------------

Hope it helps.

Best wishes,
Gabriel

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sat 25 Feb 2017 - 13:54:32 EST

This archive was generated by hypermail 2.2.0 : Sun 26 Feb 2017 - 06:27:16 EST