Hi, In the following C code the last 'else' is indented incorrectly: int f() { if (1) if (1) f(); else f(); else <-- Should be one indentation level lower The same is true for JavaScript (and hence QML): function f() { if (true) if (true) f(); else f(); else Other languages were not tested.
With braces it works as expected. int f() { if (1) { if (1) f(); else f(); } else { f(); } }
Confirmed using latest released packages. Updating version to indicate. Tested using Arch linux packages (KDE frameworks 5.58.0, Qt 5.12.3, Kwrite 19.04.1).
The first "if" must use curly braces because the nested if is intended to be executed as a block, IIUC... (mind you, I only know C++, not C).
(In reply to Ahmad Samir from comment #3) > The first "if" must use curly braces because the nested if is intended to be > executed as a block, IIUC... (mind you, I only know C++, not C). That is not correct. The nested conditional construct without explicitly marking off the block scope with {} is valid in both C and C++.
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/259
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/266
Fixed with 5.91
Git commit f1b94f2f8367a07e4ed4b8e33f6061383b3aa44f by Christoph Cullmann, on behalf of Waqar Ahmed. Committed on 23/01/2022 at 18:31. Pushed by waqar into branch 'master'. Handle single statement condition blocks better See test case for full detail of what is fixed. Essentially it is that if you have something like: ``` if (true) doWork(); ``` and the cursor is on the semicolon, pressing enter should decrease indent level to that of the `if` statement. A +8 -0 autotests/input/indent/cstyle/385472/expected A +3 -0 autotests/input/indent/cstyle/385472/input.js A +7 -0 autotests/input/indent/cstyle/385472/origin M +34 -1 src/script/data/indentation/cstyle.js https://invent.kde.org/frameworks/ktexteditor/commit/f1b94f2f8367a07e4ed4b8e33f6061383b3aa44f