Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation level is calculated incorrectly for lines mixing tabs and spaces #6262

Closed
pascalkuthe opened this issue Mar 11, 2023 · 2 comments · Fixed by #6278
Closed

Indentation level is calculated incorrectly for lines mixing tabs and spaces #6262

pascalkuthe opened this issue Mar 11, 2023 · 2 comments · Fixed by #6278
Labels
C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR

Comments

@pascalkuthe
Copy link
Member

Indentation of existing lines is calculated with (helix_core::indent):

pub fn indent_level_for_line(line: RopeSlice, tab_width: usize, indent_width: usize) -> usize {
    let mut len = 0;
    for ch in line.chars() {
        match ch {
            '\t' => len += tab_width,
            ' ' => len += 1,
            _ => break,
        }
    }

    len / indent_width
}

This works for lines that are purely indented with spaces or tabs (so almost always) but in the edge-case that a lines is indented with a mix of tabs and spaces (for some ungodly reason) then the result is incorrect because the width of a tab differs in that case. The fix is simple: use helix_core::graphemes::tab_width to calculate the tab width instead in the function mentioned above.

CC @Triton171 (in case I missed something)

@pascalkuthe pascalkuthe added C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR labels Mar 11, 2023
@Proful
Copy link

Proful commented Mar 11, 2023

I faced this issue recently. Had to convert tab to spaces manually.

@pascalkuthe
Copy link
Member Author

the fix is quite easy I basically desribed exactly what to do so if you are interested in this it should be quite easy for you to open a PR.

stabor705 added a commit to stabor705/helix that referenced this issue Mar 12, 2023
jpttrssn pushed a commit to jpttrssn/helix that referenced this issue Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants