sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Need inline phantoms to be able to position themselves to the right of the existing region (`sublime.LAYOUT_INLINE_RIGHT`)

Open rwols opened this issue 4 years ago • 2 comments

Problem description

When using an inline phantom (sublime.LAYOUT_INLINE), it's ambiguous where the phantom should position itself for a region that is already filled with characters/text.

aaaa
 ^^ the phantom region (1,3), where should it position itself? let's say the content is XX.

aXXaaa
   ^^ the phantom with content XX positions itself to the LEFT of the (1,3) region

However there are definitely cases where an inline phantom would need to be positioned to the right of the existing region. Think type hints.

Preferred solution

A new flag sublime.LAYOUT_INLINE_RIGHT that positions the phantom to the RIGHT of the region.

Alternatives

Hack around with empty regions. This is not optimal because ST dutifully moves that empty region under buffer mutations, resulting in undesirable behavior.

Additional Information (optional)

https://github.com/sublimelsp/LSP/issues/2038 https://github.com/sublimelsp/LSP/issues/1746

rwols avatar Jul 03 '21 11:07 rwols

There are a few other issues mostly related to using phantoms for displaying ghost text (for example to show inline suggestions for GitHub Copilot).

The biggest one is that there is no way to stabilize the cursor as it jumps when a phantom is displayed in the cusror position.
There is a workaround with adding a block phantom the cursor but unfortunately, it is not stable.
So it would be really great if this sublime.LAYOUT_INLINE_RIGHT guarantees that the cursor always stays from the left of the inserted phantom.

Also, there is always some space between the inserted phantom and the text, so if you try to emulate something like ghost text or inline completion that extra space makes it not so nice.

Ideally, that space should be configured somehow, or at least, there should be an option to avoid that extra space at all(for example it could be the default behaviour for the sublime.LAYOUT_INLINE_RIGHT flag)

timfjord avatar Jul 28 '22 11:07 timfjord

In relation to what was written above, here is some visual presentation.

The video below shows two issues:

  1. Text typed just before the phantom doesn't push it forward.
  2. Once the python gets re-created (by the LSP server in this case) due to some changes, the cursor can no longer be positioned to the left of the phantom.

https://user-images.githubusercontent.com/153197/185708359-fd96734c-d417-4deb-a605-969b5ac14314.mov

Here is VSCode for comparison.

https://user-images.githubusercontent.com/153197/185708757-bf89dbfa-c460-4a74-bb5b-57a86694c59b.mov

rchl avatar Aug 19 '22 21:08 rchl