oni icon indicating copy to clipboard operation
oni copied to clipboard

Snippets don't auto indent

Open Goldie643 opened this issue 8 years ago • 4 comments

Inserting a snippet on anything but col 1 doesn't preserve indentation beyond first line. Example: Snippet code: image

From col 1: image

From col 5: image

Goldie643 avatar May 23 '18 16:05 Goldie643

Hello and welcome to the Oni repository! Thanks for opening your first issue here. To help us out, please make sure to include as much detail as possible - including screenshots and logs, if possible.

oni-bot avatar May 23 '18 16:05 oni-bot

I can confirm from a quick test in VSCode that it should be auto-indenting the subsequent lines.

The code looks to take the first lines character position into consideration, but then after that just fits the rest of the snippet in with no formatting.

https://github.com/onivim/oni/blob/38566d92489ebce97d82a899a1fda8467eff786c/browser/src/Services/Snippets/SnippetSession.ts#L146-L158

We'd instead want to use the start of the prefix position as the starting point for the rest of the lines.

CrossR avatar May 23 '18 16:05 CrossR

@CrossR we use a package called detectIndent somewhere else for setting lines i think in the BufferManager file so perhaps that could be reused or maybe it isn't actually working correctly as it's I think used in the setLines function and maybe should already be indenting insertions correctly?

akinsho avatar May 24 '18 15:05 akinsho

Added a PR for this now (#2394 ), using detect-indent.

It looks like setLines is just a wrapper for the neovim API function to set lines, it doesn't apply any other logic which is why no indents were being applied. The first lines indent is maintained by using the prefix, and the rest are left untouched.

CrossR avatar Jul 03 '18 23:07 CrossR