Sublime Forum

Possible to put line highlights?

#1

I am using this plugin here to mark the changes lines, it adds a dot, but I was hoping to highlight the line in the editor and the minimap. Is this possible? Can you please point me in right direction. First time plugin writer here (no to python as well).

import sublime, sublime_plugin
import types

class ClearChangesCommand(sublime_plugin.EventListener):
	def on_post_save(self, view):
		view.erase_regions('unsaved')

class HighlightUnsavedCommand(sublime_plugin.EventListener):
	def on_modified(self, view):
		
		unsaved = view.get_regions('unsaved') + [view.line(s) for s in view.sel()]

		if not isinstance(view.file_name(), types.NoneType):
			
			with open(view.file_name(), 'r') as f:
					read_data = unicode(f.read())

			for sel in view.sel():
				if read_data[view.line(sel).begin():view.line(sel).end()] == view.substr(view.line(sel)):
					unsaved:] = [x for x in unsaved if x != view.line(sel)]

			view.add_regions("unsaved", unsaved, "mark", "dot", sublime.HIDDEN | sublime.PERSISTENT)

I got this code from this topic here: Hightlight changed row

0 Likes

#2

Only regions are draw on the minimap, not icon.
As you hide it using the sublime.HIDDEN flag, it’s not displayed in either view nor minimap.

There’s no solution except removing sublime.HIDDEN or replacing it with something else like sublime.DRAW_NO_FILL (sublimetext.com/docs/3/api_reference.html).

Note that there’s already a handful of plugin that does what you want.
And last time I checked (was rather long times ago), the ones that use regions to track modified lines had some issues with (soft)-undo.

0 Likes