Sublime Forum

Highlight edited lines in minimap and editor

#1

Other minimap implementations (like the one in Microsoft Visual Studio) indicate lines that have been edited (in this case, yellow for edited lines that are unsaved and green for lines edited in the current session which have been saved). When scrolling through a source file, this is incredibly useful for finding recent edits. For example:

The darker area shows (always - not just on mouseover) the currently-displayed lines. This has already been requested here: https://forum.sublimetext.com/t/persistent-highlight-on-minimap/13460/3&hilit=minimap#p61708. The white line shows the current edit position, which is also very useful.

On the left, green and yellow indicate edited lines (saved or unsaved respectively).

I’d love to see the Sublime minimap extended to include these features.

Ideally, the green/yellow markers should also appear in the left margin of the editor itself too - but this is probably a different feature request.

1 Like

#2

i use this code for similar functionality. its hacked together from some pieces taken from this forum so yeah

[code]class HighlightchangedCommand(sublime_plugin.EventListener):
def on_modified(self, view):

	fname = view.file_name();

	if not fname:
		return

	try:
		a = codecs.open(fname, "r", "utf-8").read().splitlines()
		b = view.substr(sublime.Region(0, view.size())).splitlines()
	except UnicodeDecodeError:
		sublime.status_message("Diff only works with UTF-8 files")
		return
	except FileNotFoundError:
		return
	adate = time.ctime(os.stat(fname).st_mtime)
	bdate = time.ctime()

	difftxt = ""
	regions_r = ];
	regions_i = ];
	regions_d = ];

	s = difflib.SequenceMatcher(None, a, b)
	for tag, _, _, j1, j2 in s.get_opcodes():
		if tag=="replace" : 
			for l in range(j1,j2):
				p = view.text_point(l,0)
				regions_r.append(sublime.Region(p,p))
		elif tag=="insert" :
			for l in range(j1,j2):
				p = view.text_point(l,0)
				regions_i.append(sublime.Region(p,p))
		elif tag=="delete" :
			for l in range(j1,j2+1):
				p = view.text_point(l,0)
				regions_d.append(sublime.Region(p,p))

	view.add_regions("changed",  regions_r, "markup.changed.diff",  "Packages/User/replace.png", sublime.HIDDEN | sublime.DRAW_EMPTY)
	view.add_regions("inserted", regions_i, "markup.inserted.diff", "Packages/User/insert.png",  sublime.HIDDEN | sublime.DRAW_EMPTY)
	view.add_regions("deleted",  regions_d, "markup.deleted.diff",  "Packages/User/delete.png",  sublime.HIDDEN | sublime.DRAW_EMPTY)

def is_enabled(self):
	return self.view.is_dirty() and self.view.file_name() != None[/code]

this will only add icons in the gutter, but i think with some changes to add_region flags you can get them showing on minimap

0 Likes

#3

Hi Valerij_, where do you put that script you have pasted here? Thanks

0 Likes

#4

just as a new plugin. note that the first two lines are outside the codeblock, dunno what the forum software did there

0 Likes