Inline suggested texts

We’re trying to implement a feature that suggests codes in a similar way as GitHub Copilot, i.e. a multiline plain-text code snippet is “inserted” after the cursor position but it is greyed out and not committed to the doc yet, pending a keyboard action (Tab). What is the right way to implement this?

Did u try CodeMirror Reference Manual?

view/placeholder.ts at main · codemirror/view · GitHub looks like a simple decoration, I’d say copy it for that usecase so it’s not the same css, it doesn’t handle wrapping nor new line characters anyway.

One more option is to insert the text and decorate it with a classname

Should this non-committed text produce line numbers? If so, that might be difficult, because line numbers are based on the document structure, and a widget like that wouldn’t change that. If not, you should be able to add an inline widget with line breaks (and side: 1 so it’s drawn after the cursor).

1 Like