From 05ae8f2fa8a7047fec49d0378a7570036d8bd2c7 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 28 Oct 2024 16:34:28 +0100 Subject: [PATCH] CppEditor: Enable formatting for "apply signature changes" action So that the changes done by our internal rewriter get properly formatted afterwards by ClangFormat (if enabled). Fixes: QTCREATORBUG-31104 Change-Id: I4066ef56a765a8f2c2542b4f9220f1857d013624 Reviewed-by: David Schulz --- src/plugins/cppeditor/cppfunctiondecldeflink.cpp | 7 ++++++- src/plugins/texteditor/refactoringchanges.cpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp index c6abbcc36a5..4fad2e652e2 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp @@ -271,7 +271,12 @@ void FunctionDeclDefLink::apply(CppEditorWidget *editor, bool jumpToMatch) const int jumpTarget = newTargetFile->position(targetFunction->line(), targetFunction->column()); newTargetFile->setOpenEditor(true, jumpTarget); } - newTargetFile->apply(changes(snapshot, targetStart)); + ChangeSet changeSet = changes(snapshot, targetStart); + for (ChangeSet::EditOp &op : changeSet.operationList()) { + if (op.type() == ChangeSet::EditOp::Replace) + op.setFormat1(true); + } + newTargetFile->apply(changeSet); } else { ToolTip::show(editor->toolTipPosition(linkSelection), Tr::tr("Target file was changed, could not apply changes")); diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 2025d7bbf13..017474fe66d 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -357,6 +357,7 @@ void RefactoringFile::doFormatting() indenterOwner.reset(factory ? factory->createIndenter(document) : new PlainTextIndenter(document)); indenter = indenterOwner.get(); + indenter->setFileName(filePath()); tabSettings = TabSettings::settingsForFile(filePath()); } QTC_ASSERT(document, return);