Commit dc40d764 authored by mae's avatar mae
Browse files

small refactoring to avoid dependency on a current qt fix

parent b6ec2853
...@@ -4624,18 +4624,10 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source) ...@@ -4624,18 +4624,10 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source)
|| text.endsWith(QChar::ParagraphSeparator) || text.endsWith(QChar::ParagraphSeparator)
|| text.endsWith(QLatin1Char('\r'))); || text.endsWith(QLatin1Char('\r')));
QTextCursor unnecessaryWhitespace; if (hasFinalNewline) // since we'll add a final newline, preserve current line's indentation
if (hasFinalNewline) {
// since we'll add a final newline, preserve current line's indentation
cursor.setPosition(cursor.block().position()); cursor.setPosition(cursor.block().position());
} else {
unnecessaryWhitespace = cursor;
int pos = cursor.position();
// construct the selection in a way that it will not expand when the cursor position moves
unnecessaryWhitespace.movePosition(QTextCursor::StartOfBlock);
unnecessaryWhitespace.setPosition(pos, QTextCursor::KeepAnchor);
}
int cursorPosition = cursor.position();
cursor.insertText(text); cursor.insertText(text);
int reindentBlockEnd = cursor.blockNumber() - (hasFinalNewline?1:0); int reindentBlockEnd = cursor.blockNumber() - (hasFinalNewline?1:0);
...@@ -4643,8 +4635,12 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source) ...@@ -4643,8 +4635,12 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source)
if (reindentBlockStart < reindentBlockEnd if (reindentBlockStart < reindentBlockEnd
|| (reindentBlockStart == reindentBlockEnd || (reindentBlockStart == reindentBlockEnd
&& (!insertAtBeginningOfLine || hasFinalNewline))) { && (!insertAtBeginningOfLine || hasFinalNewline))) {
if (insertAtBeginningOfLine && !hasFinalNewline) if (insertAtBeginningOfLine && !hasFinalNewline) {
QTextCursor unnecessaryWhitespace = cursor;
unnecessaryWhitespace.setPosition(cursorPosition);
unnecessaryWhitespace.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
unnecessaryWhitespace.removeSelectedText(); unnecessaryWhitespace.removeSelectedText();
}
QTextCursor c = cursor; QTextCursor c = cursor;
c.setPosition(cursor.document()->findBlockByNumber(reindentBlockStart).position()); c.setPosition(cursor.document()->findBlockByNumber(reindentBlockStart).position());
c.setPosition(cursor.document()->findBlockByNumber(reindentBlockEnd).position(), c.setPosition(cursor.document()->findBlockByNumber(reindentBlockEnd).position(),
......
Supports Markdown
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