forked from qt-creator/qt-creator
Beautifier: ClangFormat: Format current syntactic entity for no selection
In case there was no selection, the action "Format Selected Text" could format the whole file (option) as a fallback. However, there is also the use case of formatting the syntactic entity under the cursor. Introducing another separate action for this feels wrong, so remove the fallback instead since there is already an action handling this. Change-Id: Ia73f6074433e706bb4c2d375ad5b84dd59bc93a3 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Lorenz Haas <lorenz.haas@histomatics.de>
This commit is contained in:
@@ -83,11 +83,11 @@ bool ClangFormat::initialize()
|
||||
menu->addAction(cmd);
|
||||
connect(m_formatFile, &QAction::triggered, this, &ClangFormat::formatFile);
|
||||
|
||||
m_formatRange = new QAction(BeautifierPlugin::msgFormatSelectedText(), this);
|
||||
m_formatRange = new QAction(BeautifierPlugin::msgFormatAtCursor(), this);
|
||||
cmd = Core::ActionManager::registerAction(m_formatRange,
|
||||
Constants::ClangFormat::ACTION_FORMATSELECTED);
|
||||
Constants::ClangFormat::ACTION_FORMATATCURSOR);
|
||||
menu->addAction(cmd);
|
||||
connect(m_formatRange, &QAction::triggered, this, &ClangFormat::formatSelectedText);
|
||||
connect(m_formatRange, &QAction::triggered, this, &ClangFormat::formatAtCursor);
|
||||
|
||||
m_disableFormattingSelectedText
|
||||
= new QAction(BeautifierPlugin::msgDisableFormattingSelectedText(), this);
|
||||
@@ -122,7 +122,7 @@ void ClangFormat::formatFile()
|
||||
m_beautifierPlugin->formatCurrentFile(command());
|
||||
}
|
||||
|
||||
void ClangFormat::formatSelectedText()
|
||||
void ClangFormat::formatAtCursor()
|
||||
{
|
||||
const TextEditor::TextEditorWidget *widget
|
||||
= TextEditor::TextEditorWidget::currentTextEditorWidget();
|
||||
@@ -134,8 +134,14 @@ void ClangFormat::formatSelectedText()
|
||||
const int offset = tc.selectionStart();
|
||||
const int length = tc.selectionEnd() - offset;
|
||||
m_beautifierPlugin->formatCurrentFile(command(offset, length));
|
||||
} else if (m_settings->formatEntireFileFallback()) {
|
||||
formatFile();
|
||||
} else {
|
||||
// Pretend that the current line was selected.
|
||||
// Note that clang-format will extend the range to the next bigger
|
||||
// syntactic construct if needed.
|
||||
const QTextBlock block = tc.block();
|
||||
const int offset = block.position();
|
||||
const int length = block.length();
|
||||
m_beautifierPlugin->formatCurrentFile(command(offset, length));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user