If empty lines follow each other it makes sense to use
the empty comment as dummy text for all but the last one of them.
This prevents increasing indentation lengths after if (foo) when
there are multiple new empty lines inserted.
Change-Id: I4c948161b674b3af0a131bfb85e7a45a80ed3fb0
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Sometimes the curly brace also requires indentation.
These are the cases when it comes directly after the
comma, for example inside the initializer list.
Lets handle such cases in the similar way we do it for
the closing parenthesis.
Change-Id: Ia0d25fa08f7224567dd41dd17f9757d9d8b27362
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
The text to fill the empty line mostly depends not on the
fact of being inside parenthesis or not but rather on the
last preceding meaningful character.
Let's check for this character and sometimes for the following
one to better understand the current context and pick the
proper dummy text.
With this behavior improvement we can better indent empty lines
inside initializer lists with empty lines inside.
Change-Id: Id2f27454ef56dfdf8c15b5efb14c4d09242908a9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Improve detection of the cases when the empty line is inside
the parenthesis to get more proper indentation.
Change-Id: I4aa37c29b17bedcd0e4a781d12c7066e818a07f3
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Check that extra whitespace does not prevent the indentation
and that indentation is the same for the consecutive empty lines.
Change-Id: I04aa12c4cd31aaf07daf9320c98d2eea7afcc9a8
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Sort includes only in modes when all replacements are
used (manual indentation with "Format instead of indent" selected
and saving with "Format on save" activated).
Change-Id: I73dfa1d3211760269fe7d33a141f4d831ff65c15
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Insert dummy text into empty lines also for the electic characters
not to remove empty lines when only indentation is intended.
Fixes: QTCREATORBUG-22050
Change-Id: Ife5374459feb510a0587880a6772c90a2d68d70e
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
In the concept that behavior seemed fine but in practive it
looks quite strange.
Add comma to the dummy text inserted into the empty line to have
a proper indentation for the following empty lines.
Change-Id: I770af02a475e6489bdc8f44d9f84eb3c5e7398d7
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Fix the insetred text position for such cases.
In the 'smart indentation mode" do not indent empty lines above
the current one but apply the formatting for them instead.
Change-Id: I4cfe7f9778bac5e311aa339e2fcfc717f436cb20
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Amends dcf763c7ee.
Change the logic in empty lines modification to properly
indent all empty lines.
Change-Id: Id945cf66915dfd192216660543594a7905426761
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Do not indent lines separately but call reformat only
once and then extract the proper replacements.
Remove some redundant code in process.
Change-Id: If3a0419fef9fb2ec5422d11343fdc3414f5751b7
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Check the context related stuff and remove the restriction
to format after the stream operator.
Change-Id: Iaa2d32c9bffe7a0eeb7e8ade39f109b529e1eab0
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
'reformat' function in LibFormat accepts mutilple ranges.
Let's provide the ranges for the same file together when
formatting on save and formatting after fix-its.
Change-Id: I27789da83a1efc27beb57acf238508a191562bb9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Allows not to cut the file and removes extra logic.
To achieve that do "smart" formatting in one go by adding a trick
with comment to keep the last line break and provide the proper indent
for the current line together with formatting the code above.
Disable adding namespace comments because it causes one extra
formatting pass (not for the manual formatting).
Change-Id: I8f644129606238c5438e636f56e6097ab149aa0c
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
In some cases indenting/formatting after special characters can
break the code. Let's try to avoid such corner cases.
Change-Id: I8918bc460af31d696e49f60e0ea85f34e9ff5664
Fixes: QTCREATORBUG-21474
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
With the extra option "Format while typing" checked try to format
text before the current position without breaking the current input.
To accomplish that we make proper choices which replacements to apply.
The advantage of this change is to decrease the need to manually
format code which is just written.
Some minor bugs are fixed during the testing of this change.
Change-Id: Ibed569042e6c46a881e7a83b1882cf2bb23b3626
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Sometimes it's imnportant where the cursor currently is
to properly format the code without affecting the current line.
Change-Id: I8b1fb11d2303adb5f960c7cb80a0ed2e6e45010f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Ctrl+I with the new check will reformat the selected code or
the current line instead.
Change-Id: Ia5a72c4a09621034d0dfe463f669fe1ca36b0b5f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Adding '.' or ',' very ofter makes the statement invalid.
Do not force the formatting in such cases.
Change-Id: I7e58e5af6eed065a3bc0df29698aececa579feed
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
We do not build texteditor files in unit-tests so some tricks
were required to make ClangFormatIndenter available.
First simple unit-test proofs it builds and runs.
Change-Id: I81d5ea099bd27fd1c1ed8b5b7877299dcc62a67f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>