Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Snippets don't auto indent #2242

Closed
Goldie643 opened this issue May 23, 2018 · 4 comments
Closed

Snippets don't auto indent #2242

Goldie643 opened this issue May 23, 2018 · 4 comments

Comments

@Goldie643
Copy link

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

@oni-bot
Copy link

oni-bot bot commented May 23, 2018

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.

@CrossR
Copy link
Member

CrossR commented May 23, 2018

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.

this._position = cursorPosition
const [prefix, suffix] = splitLineAtPosition(currentLine, cursorPosition.character)
this._prefix = prefix
this._suffix = suffix
const snippetLines = this._snippet.getLines()
const lastIndex = snippetLines.length - 1
snippetLines[0] = this._prefix + snippetLines[0]
snippetLines[lastIndex] = snippetLines[lastIndex] + this._suffix
await this._buffer.setLines(cursorPosition.line, cursorPosition.line + 1, snippetLines)

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

@CrossR CrossR added the bug label May 23, 2018
@akinsho
Copy link
Member

akinsho commented May 24, 2018

@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?

@CrossR
Copy link
Member

CrossR commented Jul 3, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants