Commit 99435d5f authored by mae's avatar mae
Browse files

Make "Edit/Advanced/Clean_Whitespace work on the current

selection (if there is one)
parent 16e7f0c1
......@@ -301,13 +301,15 @@ void BaseTextDocument::setSyntaxHighlighter(QSyntaxHighlighter *highlighter)
void BaseTextDocument::cleanWhitespace()
void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
{
QTextCursor cursor(m_document);
cursor.beginEditBlock();
cleanWhitespace(cursor, true, true);
ensureFinalNewLine(cursor);
cursor.endEditBlock();
bool hasSelection = cursor.hasSelection();
QTextCursor copyCursor = cursor;
copyCursor.beginEditBlock();
cleanWhitespace(copyCursor, true, true);
if (!hasSelection)
ensureFinalNewLine(copyCursor);
copyCursor.endEditBlock();
}
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());
QTextBlock block = m_document->firstBlock();
while (block.isValid()) {
QTextBlock block = m_document->findBlock(cursor.selectionStart());
QTextBlock end;
if (cursor.hasSelection())
end = m_document->findBlock(cursor.selectionEnd()-1).next();
while (block.isValid() && block != end) {
if (inEntireDocument || block.revision() > documentLayout->lastSaveRevision) {
......
......@@ -110,7 +110,7 @@ public:
void reload(QTextCodec *codec);
void cleanWhitespace();
void cleanWhitespace(const QTextCursor &cursor);
signals:
void titleChanged(QString title);
......
......@@ -833,7 +833,7 @@ void BaseTextEditor::moveLineUpDown(bool up)
void BaseTextEditor::cleanWhitespace()
{
d->m_document->cleanWhitespace();
d->m_document->cleanWhitespace(textCursor());
}
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment