Bug 340212 - Incorrect indentation after beginning of line when using soft-tabs
Summary: Incorrect indentation after beginning of line when using soft-tabs
Status: RESOLVED FIXED
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-21 21:08 UTC by Michael
Modified: 2014-11-18 18:55 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2014-10-21 21:08:44 UTC
Pressing tab to indent after non-leading-whitespace characters in a line causes incorrect alignment, at least when using soft tabs.

Reproducible: Always

Steps to Reproduce:
1. Select "Spaces" indentation mode.  For reference, I'm also using Indentation=4, Tab Width=8, but the behavior is seen even when both are set to the same value.
2. Type some lines you expect to be aligned:  (special keystrokes in {})
{\t}int{\t}{\t}x;{\n}{\t}string{\t}y;{\n}{\t}bool{\t}z;{\n}


Actual Results:  
(Tab Width) spaces are inserted at the current position:

    int                x;
    string        y;
    bool        z;


Expected Results:  
(Indentation Width) - (Cursor Position) % (Indentation Width) spaces should be inserted:

    int     x;
    string  y;
    bool    z;


Using KTextEditor 5.3.0, built from source; also appears with KTextEditor from git master.

KWrite 4.14.1 behaves better in that the second column is at least aligned, but still not correct (IMO), in that it aligns to 8 spaces after the initial leading whitespace, even if 4 is configured for the Indentation Width.
Comment 1 Christoph Cullmann 2014-11-18 18:55:23 UTC
Git commit 204fed7b8f5aaaa8b8d4516664b8720f6c2b8315 by Christoph Cullmann.
Committed on 18/11/2014 at 18:54.
Pushed by cullmann into branch 'master'.

Fix bug #340212: incorrect soft-tabs alignment after beginning-of-line

Fix for incorrect soft-tabs alignment after beginning-of-line, by taking the current cursor position into account when expanding tabs to spaces.

This also now uses the indentation width rather than the tab width, as I see "Tab Width" as being the actual width of the \t character, and "Indentation width" as being the next alignment position for virtual indentation.  This more closely matches other editors (e.g. vim) which have similar indentation control.

Patch by Michael Hansen
REVIEW: 120760

M  +23   -7    src/document/katedocument.cpp
M  +6    -1    src/document/katedocument.h

http://commits.kde.org/ktexteditor/204fed7b8f5aaaa8b8d4516664b8720f6c2b8315