+13

Display/highlight/indicate changed parts of file in gutter

Steven Lu 12 years ago updated by FichteFoll 12 years ago 4
This is a feature in many IDEs such as Eclipse and Visual Studio, which I believe can be quite useful in a general purpose text editor. 

Along the gutter (next to the line numbers) a colored line is displayed across the lines which have been modified (and unsaved). Often there are multiple levels of this that show different "levels" of modification (unsaved changes, saved but not committed to VCS). 
This is very easy to implement in a basic way by using features already present in the editor (indicators), so this can be done as a plugin also. But it's not quite ideal because we don't want to use a circle (the circle would also conflict with other plugins I have like sublimeclang) we want a space-saving 1 or 2 pixel colored line for this.
+1
Here's a small plugin I did, you just need an icon on Packages/User/icons/linechange.png :

import sublime
import sublime_plugin


class EnsureClearChangedMarks(sublime_plugin.EventListener):
    def on_modified(self, view):
        icon = "../User/icons/linechange"
        mark = view.get_regions("changed")
        for s in view.sel():
            mark.append(s)

        view.erase_regions("changed")
        view.add_regions("changed", mark, "mark", icon, sublime.HIDDEN | sublime.PERSISTENT | sublime.DRAW_OUTLINED)

    def on_post_save(self, view):
        view.erase_regions("changed")
Works great. Here is what the icon I just created: http://i.imgur.com/ROXfh.png

Only problem is with pasting multiple lines but well, can't have everything I guess. I probably won't need it anyway, I like the "Show Unsafed Changes..." command.
I can't say this works "great" at all, it does not reflect actual changed state of a line at all... I would edit something, save, and the edit marker is still there! Also typing a line and hitting enter has it move the marker down, it isn't present on the line I just wrote. 

Also it interferes with other existing markers from other plugins... it basically just draws over them. I used a 2x10 pixel image and it just stretches over the whole square. 
Yeah, the marker moves when you press enter. But since that's the way these regions work there is apparently no other way besides diffing the whole file with the saved version every time you modify it (or with a delay of like 2 seconds). At least I can't think of any.
And the interfering with other plugin's marks (other regions with a gutter mark) is also unavoidable.

This is as far as you can reasonably get with a plugin, the rest would require changes on the side of ST itself.

I for once don't need such a functionality but maybe there are others.