New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotations selection range #1139
Comments
This does look suspicious. cc @scholtzan, thoughts? |
One thing to note here is that carets are also represented as annotations. So if we'd send an empty list of annotations in the first The |
Okay, so I confused Would you like me to make a PR adding:
And followup question: Would it make sense to differentiate between carets and selections? I think it would be more logical with an annotation with type Also, should new frontends ignore the "cursor" property of lines? And only put caret at annotation with |
One thing to keep in mind is that every change in the frontend protocol will break existing clients. Maybe @cmyr has some thoughts about renaming the methods? |
Hi everyone. This following gif is taken from the vim-multi-cursor readme and we can see different colors for the caret and the selection. If the two data are mixed into a single annotation, this kind of thing would became really difficult. |
I'm not totally convinced. The abstraction of treating the caret as a length-zero selection is useful in other ways, and separating carets and selections increases overhead in other areas. The caret is always going to require special care when drawing. The case above is no different; when drawing the text, you will have to check if the line contains a caret and then invert the text color if necessary. So basically: I think this is a question of differences in display. A 'caret' is just one end of a selection region. A selection region can be empty. 🤷♂️ |
I'm also with @cmyr. I think a simple API change to accommodate just the adding carets case would suffice. |
When I started developing a tiny frontend for Xi, I did not find it very logical that a I would find it much more logical if annotations contains anything that isn't text (e.g. selections, find, cursors, etc) I'm currently using the following code to "extract" carets and test if a "real" selection has been made: class View:
# [...]
@property
def carets(self):
cursors = []
for line in self.lines:
if line['valid'] and "cursor" in line:
for x in line["cursor"]:
cursors.append((line["ln"], x))
return cursors
@property
def has_selection(self):
for annotation in self.annotations:
if annotation["type"] == "selection":
for r in annotation["ranges"]:
if r[0] != r[2] or r[1] != r[3]:
return True
return False If we made a distinction between carets and selections, then the above logic would be much more simple, but if this is at the expense of Xi performance / codebase, then clearly that's a bad choice. (This topic clearly have the potential for bikeshedding, so if anybody with a lot of insight into the Xi code can say "probably not gonna happen", then I think the solution for now must be to update the frontend doc a bit) |
This could work indeed but in this case the frontends needs to know at with end the cursor is and I don't think this information is available today. |
historically we've bundled selections up in the styles system, and we provided information about carets alongside that as a convenience. With annotations, we have a concept of a 'payload'; it may be the case that we want to include caret-related stuff in the payload of selection annotations. |
A few questions about annotations:
Wouldn't it make most sense if "annotations" in the very first "update"-RPC response was an empty list (instead of a selection of nothing?)
I think the AnnotationRange is wrong when using
add_selection_below
, e.g.:Create a file with:
Now send events:
move_right_and_modify_selection
,move_right_and_modify_selection
,add_selection_below
and the annotation range will be:But I think that should be (i.e. all of first line + half of second line):
Relevant RPC output:
The text was updated successfully, but these errors were encountered: