Bug 442468

Summary: Running a formatter as external tool prevents usage of Ctrl+Z
Product: [Applications] kate Reporter: Derek Christ <christ.derek>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: christoph, waqar.17a
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Derek Christ 2021-09-15 09:19:32 UTC
SUMMARY
Running a formatter as an external tool has the ability to save the current file, apply the tool, and reloading it afterwards.
For formatting this works great but the reloading of the file wipes the Ctrl+Z buffer and its no longer possible to revert stuff that happened before the formatting. 

STEPS TO REPRODUCE
1. Make some changes to a file
2. Run the clang-format formatter tool on the whole file
3. Reverting changes before the formatting with Ctrl+Z is no longer possible.

OBSERVED RESULT
Ctrl+Z does nothing, because the file was reloaded.

EXPECTED RESULT
It should still be possible to revert old changes.
Other code editors I know of just revert the whole formatting when the user presses Ctrl+Z right after formatting. All other changes before that are also revertable.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20210913
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.85.0
Qt Version: 5.15.2
Comment 1 Waqar Ahmed 2022-01-09 20:10:40 UTC
You can change the external tool to not reload the document and change the command to output the text to stdout. Then choose the "replace text" option..

What that will do is replace the document's text with the text provided by your formatter. This seems to not work with every formatter as some for matters tend to include other stuff but with clang format it will work.

Reopen if you find it doesn't work.