Sublime Forum

Inconsistent Sublime Phantoms Behavior

#1

While developing a sublime plugin, I have noticed inconsistent behavior with phantoms that exist on the last line of a file when using LAYOUT_INLINE.

On the last line of the file, the cursor can move beyond the end of the file appearing after the comment. On any line that is not the last line of the file, cursor position is correctly handled.

I have created a sample plugin (see below) that demonstrates this behavior:

import sublime
import sublime_plugin

views = {}

class Listeners(sublime_plugin.EventListener):
    def on_activated(self, view):
    	if not view.id() in views:
    		views[view.id()] = sublime.PhantomSet(view)

    	phantoms = []

    	lines = view.split_by_newlines(sublime.Region(0, view.size()))
    	for line in range(0, len(lines)):
    		region = view.line(view.text_point(line, 0))
    		phantoms.append(sublime.Phantom(sublime.Region(view.line(region).b, view.line(region).b), '<span style="padding-left: 20px; color: var(--bluish)">MESSAGE</span>', sublime.LAYOUT_INLINE))

    	def callback():
    		views[view.id()].update(phantoms)

    	sublime.set_timeout(callback, 1)
    	pass

    def on_deactivated(self, view):
    	if view.id() in views:
    		views[view.id()].update([])
0 Likes