helix
helix copied to clipboard
When editing HTML automatically inserted tabs are broken.
Summary
I have set the editor to adapt indentation, when adding new lines. Whenever I edit HTML, the amount of indents grow exponentially.
Reproduction Steps
I am using default settings, on an M1 Mac. This happens every time I edit HTML files.
Helix log
~/.cache/helix/helix.log
2022-04-23T10:10:19.719 helix_view::theme [WARN] Theme: malformed hexcode: foreground
2022-04-23T10:10:19.720 helix_view::theme [WARN] Theme: invalid style attribute: Modifiers
2022-04-23T10:10:19.720 helix_view::theme [WARN] Theme: malformed hexcode: pink
2022-04-23T12:39:03.949 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,948 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'autopep8': No module named 'pycodestyle'\n"
2022-04-23T12:39:03.953 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,953 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'mccabe': No module named 'mccabe'\n"
2022-04-23T12:39:03.954 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,954 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'pycodestyle': No module named 'pycodestyle'\n"
2022-04-23T12:39:03.954 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,954 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'pydocstyle': No module named 'pydocstyle'\n"
2022-04-23T12:39:03.955 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,955 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'pyflakes': No module named 'pyflakes'\n"
2022-04-23T12:39:03.955 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,955 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'pylint': No module named 'pylint'\n"
2022-04-23T12:39:03.956 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,956 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'rope_completion': No module named 'rope'\n"
2022-04-23T12:39:03.956 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,956 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'rope_rename': No module named 'rope'\n"
2022-04-23T12:39:03.956 helix_lsp::transport [ERROR] err <- "2022-04-23 12:39:03,956 CEST - WARNING - pylsp.config.config - Failed to load pylsp entry point 'yapf': No module named 'yapf'\n"
2022-04-23T13:00:24.987 helix_view::editor [ERROR] Failed to initialize the LSP for `text.html.basic` { LSP not defined }
Platform
Mac
Terminal Emulator
Warp, iTerm2
Helix Version
helix 22.03 (d4e45fd4)
I tried inserting the following code into a script element directly from the OS clipboard:
var wavesurfer = WaveSurfer.create({
container: document.querySelector('#waveform'),
waveColor: '#A8DBA8',
progressColor: '#3B8686',
backend: 'MediaElement',
plugins: [
WaveSurfer.regions.create({
regionsMinLength: 2,
regions: [
{
start: 1,
end: 3,
loop: false,
color: 'hsla(400, 100%, 30%, 0.5)'
}, {
start: 5,
end: 7,
loop: false,
color: 'hsla(200, 50%, 70%, 0.4)',
minLength: 1,
maxLength: 5,
}
],
dragSelection: {
slop: 5
}
})
]
});
This resulted in a freeze, after the cursor had moved to a column number around ~1500000.
For the pasting part, you must paste with space-p
instead of Cmd-v
: https://github.com/helix-editor/helix/issues/1021#issuecomment-963353157
Then Cmd-v
breaks the editor when pasting snippets like the one above. When I press enter, it still adds a weird amount of indentation, and keeps increasing this amount for each repetition.
Then
Cmd-v
breaks the editor when pasting snippets like the one above
Yes. This is a known issue. I'll make a tracking issue for it.
When I press enter, it still adds a weird amount of indentation, and keeps increasing this amount for each repetition.
This is outside of pasting - just with regular editing, right? The indentation mechanism was fully reworked after the 22.03 release. You can try it out by building from source, awaiting nightly releases (#358), or awaiting the next release (May, https://github.com/helix-editor/helix/wiki/FAQ#when-will-the-next-release-be)
This is general problem outside of pasting as well - though I only experience this behavior when handling HTML, - in Python files things are fine. Will try to upgrade to a new version of Helix, thank you.
this is because there is no indent.scm file for html yet
not sure if it the same thing, but I have this:
code taken from https://www.getzola.org/documentation/getting-started/overview/
note: I did :fmt command a few times
I'm experiencing similar issues with other languages, too, like markdown.
@adsick this looks like you pasted through the terminal (which treats the input as if the user typed each character), right? If that's the case, use space p / space P to paste it correctly within helix.
@CptPotato thanks, didn't know that. But still :fmt
should do it's job regardless.
:format
(:fmt
) calls out to the language server for formatting, so it will only work if you have the HTML language server installed
I've encountered this same issue but when editing a Markdown document, so I don't think it's HTML specific.
In this image, everything was entered manually, and the only time I pressed Tab was for the first indented line. After that, successive lines had exponentially more indentation.
I think I've worked out the cause, though I haven't looked through the code. Helix seems to calculate the current line's indentation level with a fixed number of spaces. In HTML and Markdown, it appears to be 2 spaces, but I also reproduced the behaviour in Kotlin, where it seems to be 4 spaces. It then indents the new line by that amount, but using the correct indent-style
setting. So if indent-style
is any value other than the one Helix assumed while looking at the current line, the indentation changes.
Quick diagram:
Is there a way to disable automatic indentation for HTML until this is fixed?
Helix seems to calculate the current line's indentation level with a fixed number of spaces. In HTML and Markdown, it appears to be 2 spaces,
That seems to be true somehow, as the exponential line growth doesn't happen with indent-style 2
. Anything higher than 2 does it. It doesn't happen with indent-style t
. I've seen this also happen in Vue SFC files, which I believe reuses the HTML logic, making the indentation problem affect the script and style sections as well.
Is there a way to disable automatic indentation for HTML until this is fixed?
I'm afraid not. Per-language editor settings seem to be quite limited at the moment (you can only set indent-style
and editor.auto-pairs
?), so the only workaround would be to use 2 spaces or hard tabs in your html files.