Beautifier: Fix text selection for the Uncrustify

Extension of the selection of the text to full lines
does not work correctly if the selection is performed
from the top to the bottom.

Change-Id: I13a1bf9d6e92ebbbfd4f8190fb626dd3aca74686
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Viktor Kireev
2017-10-03 19:17:02 +03:00
parent 7643b2ccdc
commit 02b5426b8e

View File

@@ -138,9 +138,12 @@ void Uncrustify::formatSelectedText()
if (tc.hasSelection()) { if (tc.hasSelection()) {
// Extend selection to full lines // Extend selection to full lines
const int posSelectionEnd = tc.selectionEnd(); const int posSelectionEnd = tc.selectionEnd();
tc.setPosition(tc.selectionStart());
tc.movePosition(QTextCursor::StartOfLine); tc.movePosition(QTextCursor::StartOfLine);
const int startPos = tc.position(); const int startPos = tc.position();
tc.setPosition(posSelectionEnd); tc.setPosition(posSelectionEnd);
// Don't extend the selection if the cursor is at the start of the line
if (tc.positionInBlock() > 0)
tc.movePosition(QTextCursor::EndOfLine); tc.movePosition(QTextCursor::EndOfLine);
const int endPos = tc.position(); const int endPos = tc.position();
m_beautifierPlugin->formatCurrentFile(command(cfgFileName, true), startPos, endPos); m_beautifierPlugin->formatCurrentFile(command(cfgFileName, true), startPos, endPos);