Bug 375529 - Indentation broken if automatic brackets is used
Summary: Indentation broken if automatic brackets is used
Status: RESOLVED FIXED
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: indentation (show other bugs)
Version: 5.58.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-25 06:08 UTC by Alfonso Arbona Gimeno
Modified: 2022-01-27 07:19 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alfonso Arbona Gimeno 2017-01-25 06:08:40 UTC
In c++, with automatic brackets on, indentation set to "C style" and using tabs, when I write something that uses brackets (for example the body of an if-case), the brackets go to wrong positions and the indentation is all bad.

For example (____ means tab, . means space, | is the caret position):

I have something like this:
int main()
{
____while(true)|
}

I press <enter> and go to the next line (as expected with the one extra indentation more than the while line). Then, pressing the '{' key results in this:

int main()
{
____while(true)
.{|}
}

Notice that the indentation is wrong and using a single space instead of a tab. The cursor is inside the brackets, as expected.

If I press <enter> once again, I get this:

int main()
{
____while(true)
.{
____.|
}
}

That is: the first bracket has an space instead of a tab; the body part (where the caret is) has a tab, as expected, but then a single space (instead of a second tab); and the second bracket has no indentation at all.


I'm using kubuntu 16.04 but with a ppa to get stable kde backports and another for kdevelop.
Kate says that it is version 16.04.3, using KDE Frameworks 5.28.0, Qt 5.6.1 (built against 5.6.1), and the xcb windowing system.
KDE Plasma Version is 5.8.5.
Qt Version is 5.6.1.
Comment 1 Karthik Periagaram 2019-05-26 06:12:37 UTC
Confirmed. To trigger this, you only need to set "Indentation using" to tabs. Leave everything else as defaults.

Arch packages (KDE frameworks 5.58.0, Qt 5.12.3, Kwrite version 19.04.1) are newer, so I'll update the version for this bug.

Note: When Indentation is set to use spaces, this behavior does NOT happen.

Example and behavior with indentation using spaces:

Start with,

int main()
{
....while (true)|
}

Press enter

int main()
{
....while (true)
........|
}

Open braces

int main()
{
....while (true)
....{|}
}

Press enter

int main()
{
....while (true)
....{
........|
....}
}
Comment 2 Bug Janitor Service 2022-01-24 08:31:01 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/267
Comment 3 Christoph Cullmann 2022-01-27 07:19:04 UTC
Git commit 29122ad59afeced0296d23fb6153c4f04c008ac1 by Christoph Cullmann, on behalf of Waqar Ahmed.
Committed on 27/01/2022 at 07:11.
Pushed by cullmann into branch 'master'.

When using tabs, use tabs to auto indent
Related: bug 367966

M  +1    -1    src/script/data/indentation/cstyle.js
M  +1    -0    src/utils/kateautoindent.cpp

https://invent.kde.org/frameworks/ktexteditor/commit/29122ad59afeced0296d23fb6153c4f04c008ac1