Ghost Text Cursor


#1

Hey everybody!

I’m looking for a solution of the following problem. I want to have a “ghost text cursor” which follows the default cursor, but at another position. “Following” means that if the default cursor goes right, the ghost cursor goes right too, etc. But it should only be a decoration, which means if user enters a text, there should be no insertion at the ghost cursors position. So a second cursor is no option, as far as I can see.

Here you have a screenshot of what I mean – the solid line is the default text cursor and the dashed line is the “ghost cursor”.

Any idea?


#2

There’s nothing built-in to the Atom API that would give you this exact functionality. You could, however, use the Cursor.onDidChangePosition event to keep track of when the cursor moves and update the marker your decoration is tied to. This might have a significant impact on typing responsiveness though … so I wouldn’t recommend it without significant performance testing especially if this is only a cosmetic thing.


#3

Ha! You made my day! I experimented with the decoration API, but your answer showed me the right direction!

What I missed to say and what leads to the final answer is, that these ghost cursors are only visible in decorated areas. So I can detect these characters besides which such ghost cursors should appear, so I can decorate them.

Thank you!

Btw: Are you a team member of Atom? You post that much answers here! Great work!


#4

Thank you very much :bow: I’m glad that it is appreciated. Yes, I’m a member of the Atom team. You can find out which organizations I belong to on my GitHub profile, including Atom and Electron, among others.