Sublime Forum

Highlight changed rows

#1

Hi there,

probably you know the plugin “Marking Changed Rows” which displays a dot in front of each line when the line is modified. I try to expand this plugin such that it displays the modified rows in red, and as soon as the document is saved, the red marks are switched to green ones. The green marks are persistent as long as the document is open. As soon as it is reloaded, all the marks shall be discarded. The plugin should do something like this:

I come pretty close to my goal, but there is the problem that if new lines are inserted on top of saved lines, the green marks stay where they are, but in fact they should move downwards as well. Example:

Edit line 10, it gets a red marker. Then save. The marker is switched to green. My plugin does manage this behaviour as desired. Now insert a new line, say at line 1. The green dot stays where it is, but the text which previously was at line 10 is now at line 11, and so should be the green dot :slightly_smiling: any ideas how I could do that?

Visual Studio or Notepad++ have some similar feature like that. I like it because if I have opened a document and make changes, I can easily track the lines where I did modify things without having to check the version control first.

Here’s my plugin Code: http://pastebin.com/VRZAisWq
(some of it copied from Marking Changed Rows)

1 Like

#2

Awesome Idea :+1:

I have it mostly functional. So Far it keeps track of all [ modified | saved ] lines accurately, but I’m having an issue with any regions below the current modified line getting shifted. I’ll post the code once I wrap it up for the night ( probably in the early to late AM ). Hopefully I’ll have worked out the issue by then.

0 Likes

#3

So it took me a bit… longer than I expected. But it works!


VIDEO DEMO:


REPOSITORY:

#@ GitHub


FIX:

I think the issue you were running into was related to self.changed_lines = []. I believe that in extracting the region/line/row, the data becomes static & the regions no longer correspond to the data after the document is modified. This can be resolved by accessing the region object directly.

Here are the methods I implemented for that particular issue:
#on_modified
#get_NamedRegions

0 Likes

#4

That’s great! Are you gonna turn it into a package, at all?

0 Likes

#5

I’m working on a few things before submitting it to PackageControl, but you should be able to install it via Command Palette/Add Repository. Let me know how it works & if you run into any issues or have any suggestions.

I might submit it if I can wrap most of this stuff up in another session or 2:

• fix add current line on save
• fix error if save before modify
* fix "fill" icon

• add style independent icons

• re-implement FILE management
		• add independent document settings

• improve region management
		• replace saved regions with modified if edited ( works intermittently )
		• ignore lines which only contain whitespace
		• concatenate contiguous regions ( INCLUDE_WHITESPACE = [True|False] )

Something I’d like to do ( at some point ) is implement a stored reference of the file you’re working on. This would allow much greater accuracy of diffing ( including modifications that are executed programatically ), but would pretty much require a substantial re-write & scratch-made methods for parsing the regions.

It would also allow for character diffing rather than line diffing. That might be possible with the standard functions, but I’ll have to look into it.

0 Likes

#6

Does it works correctly with (Soft)Undo command and inserting/deleting lines ?
I like to have this feature but all plugins (including mine) I tried have serious issues with the mentioned actions.

0 Likes

#7

Soft undo seems to work pretty well. I didn’t know about that command until just now, super useful!

Inserting lines with ctrl+enter & ctrl+shift+enter works as well.


Since it works by checking selected lines, there are a few issues with programmatic commands:

  • copy & paste will only mark the final line of the pasted region
  • duplicate line has the same effect
  • I have a plugin in the works that toggles specific comment regions throughout the document from a single line to multiple lines with padding. Changes are not marked.

As mentioned in my previous post, I think the only workaround would be to run a full diff test of the document for every modification.

I’ll see if I can work something out.


:heavy_plus_sign: :heavy_plus_sign: :heavy_plus_sign:

My current idea is to keep 2 arrays for each open document:

originalDocument[ all text lines ]
currentDocument[ all text lines ]


currentDocument would be updated on each modification ( progressive diffing )

originalDocument would remain unchanged, and be used for regressive diffing ( @ undo )

Each line of the active document would be diffed accordingly.


:question: :question: :question:

Anyone have any thoughts on this method? Potential alternatives?

Also, I can’t think of a way to account for deletions off the top of my head. It seems tricky since traditional diff utilities usually show both documents and can add a whitespace region to show deletions. Any ideas for keeping track of deletions in a live document?

0 Likes

Retrieving inserted and deleted text
#8

@nesbit

Are you still working on your diff plugin?

 
 

You might be interested in this thread, some progress has been made on detecting changes:
##Retrieving inserted and deleted text

0 Likes

#9

Hi @fico

Currently not but I am unhappy with my existing solution and as soon as I have some spare time I want to continue my work. Why do you ask? do you have an idea? :slightly_smiling:

0 Likes

#10

@nesbit

I’m not sure what you’ve implemented since your original post, but the LineDiff plugin I posted a while back and the thread I mentioned in my last post have a good amount of examples you might find useful when you’re ready to continue.

0 Likes