Commit 913b1bf0 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

parents 8cc94d10 6d0e9bad
......@@ -1537,28 +1537,43 @@ int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
else
braceDepth= 0;
if (braceDepth > 0) { // we do have an extra brace, let's close it
int pos = cursor.position();
MatchingText matchingText;
const QString textToInsert = matchingText.insertParagraphSeparator(cursor);
cursor.insertText(textToInsert);
cursor.setPosition(pos);
const TabSettings &ts = tabSettings();
if (ts.m_autoIndent) {
cursor.insertBlock();
indent(document(), cursor, QChar::Null);
} else {
QString previousBlockText = cursor.block().text();
cursor.insertBlock();
cursor.insertText(ts.indentationString(previousBlockText));
}
cursor.setPosition(pos);
m_allowSkippingOfBlockEnd = true;
return 1;
if (braceDepth <= 0)
return 0; // braces are all balanced or worse, no need to do anything
// we have an extra brace , let's see if we should close it
/* verify that the next block is not further intended compared to the current block.
This covers the following case:
if (condition) {|
statement;
*/
const TabSettings &ts = tabSettings();
QTextBlock block = cursor.block();
int indentation = ts.indentationColumn(block.text());
if (block.next().isValid()
&& ts.indentationColumn(block.next().text()) > indentation)
return 0;
int pos = cursor.position();
MatchingText matchingText;
const QString textToInsert = matchingText.insertParagraphSeparator(cursor);
cursor.insertText(textToInsert);
cursor.setPosition(pos);
if (ts.m_autoIndent) {
cursor.insertBlock();
indent(document(), cursor, QChar::Null);
} else {
QString previousBlockText = cursor.block().text();
cursor.insertBlock();
cursor.insertText(ts.indentationString(previousBlockText));
}
return 0;
cursor.setPosition(pos);
m_allowSkippingOfBlockEnd = true;
return 1;
}
bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
......
......@@ -4509,11 +4509,12 @@ QMimeData *BaseTextEditor::createMimeDataFromSelection() const
const TabSettings &ts = d->m_document->tabSettings();
bool startOk = ts.cursorIsAtBeginningOfLine(selstart);
bool endOk = (selend.block() != selstart.block() && ts.cursorIsAtBeginningOfLine(selend));
bool multipleBlocks = (selend.block() != selstart.block());
if (startOk && endOk) {
if (startOk && multipleBlocks) {
selstart.movePosition(QTextCursor::StartOfBlock);
selend.movePosition(QTextCursor::StartOfBlock);
if (ts.cursorIsAtBeginningOfLine(selend))
selend.movePosition(QTextCursor::StartOfBlock);
cursor.setPosition(selstart.position());
cursor.setPosition(selend.position(), QTextCursor::KeepAnchor);
text = cursor.selectedText();
......@@ -4583,29 +4584,43 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source)
cursor.beginEditBlock();
if (ts.cursorIsAtBeginningOfLine(cursor)
bool insertAtBeginningOfLine = ts.cursorIsAtBeginningOfLine(cursor);
if (insertAtBeginningOfLine
&& source->hasFormat(QLatin1String("application/vnd.nokia.qtcreator.blocktext"))) {
text = QString::fromUtf8(source->data(QLatin1String("application/vnd.nokia.qtcreator.blocktext")));
if (text.isEmpty())
return;
}
cursor.removeSelectedText();
cursor.removeSelectedText();
int bpos = cursor.block().position();
int pos = cursor.position() - bpos;
int reindentBlockStart = cursor.blockNumber() + (insertAtBeginningOfLine?0:1);
cursor.setPosition(bpos); // since we'll add a final newline, preserve current line's indentation
bool hasFinalNewline = (text.endsWith(QLatin1Char('\n'))
|| text.endsWith(QChar::ParagraphSeparator)
|| text.endsWith(QLatin1Char('\r')));
cursor.insertText(text);
pos = cursor.position();
cursor.setPosition(bpos);
cursor.setPosition(pos, QTextCursor::KeepAnchor);
cursor.setPosition(cursor.position()-1, QTextCursor::KeepAnchor);
reindent(document(), cursor);
cursor.clearSelection();
cursor.setPosition(cursor.position()+1); // skip newline
} else {
cursor.insertText(text);
QTextCursor unnecessaryWhitespace;
if (hasFinalNewline) {
// since we'll add a final newline, preserve current line's indentation
unnecessaryWhitespace = cursor;
unnecessaryWhitespace.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
cursor.setPosition(unnecessaryWhitespace.position());
}
cursor.insertText(text);
int reindentBlockEnd = cursor.blockNumber() - (hasFinalNewline?1:0);
if (reindentBlockStart <= reindentBlockEnd) {
if (insertAtBeginningOfLine && hasFinalNewline)
unnecessaryWhitespace.removeSelectedText();
QTextCursor c = cursor;
c.setPosition(cursor.document()->findBlockByNumber(reindentBlockStart).position());
c.setPosition(cursor.document()->findBlockByNumber(reindentBlockEnd).position(),
QTextCursor::KeepAnchor);
reindent(document(), c);
}
cursor.endEditBlock();
......
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