forked from qt-creator/qt-creator
Make "Edit/Advanced/Clean_Whitespace work on the current
selection (if there is one)
This commit is contained in:
@@ -301,13 +301,15 @@ void BaseTextDocument::setSyntaxHighlighter(QSyntaxHighlighter *highlighter)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BaseTextDocument::cleanWhitespace()
|
void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
|
||||||
{
|
{
|
||||||
QTextCursor cursor(m_document);
|
bool hasSelection = cursor.hasSelection();
|
||||||
cursor.beginEditBlock();
|
QTextCursor copyCursor = cursor;
|
||||||
cleanWhitespace(cursor, true, true);
|
copyCursor.beginEditBlock();
|
||||||
ensureFinalNewLine(cursor);
|
cleanWhitespace(copyCursor, true, true);
|
||||||
cursor.endEditBlock();
|
if (!hasSelection)
|
||||||
|
ensureFinalNewLine(copyCursor);
|
||||||
|
copyCursor.endEditBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool cleanIndentation, bool inEntireDocument)
|
void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool cleanIndentation, bool inEntireDocument)
|
||||||
@@ -315,8 +317,12 @@ void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool cleanIndentatio
|
|||||||
|
|
||||||
TextEditDocumentLayout *documentLayout = qobject_cast<TextEditDocumentLayout*>(m_document->documentLayout());
|
TextEditDocumentLayout *documentLayout = qobject_cast<TextEditDocumentLayout*>(m_document->documentLayout());
|
||||||
|
|
||||||
QTextBlock block = m_document->firstBlock();
|
QTextBlock block = m_document->findBlock(cursor.selectionStart());
|
||||||
while (block.isValid()) {
|
QTextBlock end;
|
||||||
|
if (cursor.hasSelection())
|
||||||
|
end = m_document->findBlock(cursor.selectionEnd()-1).next();
|
||||||
|
|
||||||
|
while (block.isValid() && block != end) {
|
||||||
|
|
||||||
if (inEntireDocument || block.revision() > documentLayout->lastSaveRevision) {
|
if (inEntireDocument || block.revision() > documentLayout->lastSaveRevision) {
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public:
|
|||||||
|
|
||||||
void reload(QTextCodec *codec);
|
void reload(QTextCodec *codec);
|
||||||
|
|
||||||
void cleanWhitespace();
|
void cleanWhitespace(const QTextCursor &cursor);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void titleChanged(QString title);
|
void titleChanged(QString title);
|
||||||
|
|||||||
@@ -833,7 +833,7 @@ void BaseTextEditor::moveLineUpDown(bool up)
|
|||||||
|
|
||||||
void BaseTextEditor::cleanWhitespace()
|
void BaseTextEditor::cleanWhitespace()
|
||||||
{
|
{
|
||||||
d->m_document->cleanWhitespace();
|
d->m_document->cleanWhitespace(textCursor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
||||||
|
|||||||
Reference in New Issue
Block a user