forked from qt-creator/qt-creator
tune auto-indentation of pasted text
auto-indentation of pasted text now only happens when complete lines including a trailing paragraph separator are copied and pasted. In addition, the reindent() functions ensures that the relative indentation within the pasted block is preserved. This mechanism is now also used for moving lines up/down. Done with thorbjorn
This commit is contained in:
@@ -87,6 +87,14 @@ void TabSettings::fromSettings(const QString &category, const QSettings *s)
|
||||
m_tabKeyBehavior = (TabKeyBehavior)s->value(group + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
|
||||
}
|
||||
|
||||
|
||||
bool TabSettings::cursorIsAtBeginningOfLine(const QTextCursor &cursor) const
|
||||
{
|
||||
QString text = cursor.block().text();
|
||||
int fns = firstNonSpace(text);
|
||||
return (cursor.position() - cursor.block().position() <= fns);
|
||||
}
|
||||
|
||||
int TabSettings::lineIndentPosition(const QString &text) const
|
||||
{
|
||||
int i = 0;
|
||||
@@ -255,6 +263,32 @@ void TabSettings::indentLine(QTextBlock block, int newIndent) const
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
void TabSettings::reindentLine(QTextBlock block, int delta) const
|
||||
{
|
||||
const QString text = block.text();
|
||||
const int oldBlockLength = text.size();
|
||||
|
||||
int oldIndent = indentationColumn(text);
|
||||
int newIndent = qMax(oldIndent + delta, 0);
|
||||
|
||||
if (oldIndent == newIndent)
|
||||
return;
|
||||
|
||||
const QString indentString = indentationString(0, newIndent);
|
||||
newIndent = indentString.length();
|
||||
|
||||
if (oldBlockLength == indentString.length() && text == indentString)
|
||||
return;
|
||||
|
||||
QTextCursor cursor(block);
|
||||
cursor.beginEditBlock();
|
||||
cursor.movePosition(QTextCursor::StartOfBlock);
|
||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, firstNonSpace(text));
|
||||
cursor.removeSelectedText();
|
||||
cursor.insertText(indentString);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
bool TabSettings::equals(const TabSettings &ts) const
|
||||
{
|
||||
return m_spacesForTabs == ts.m_spacesForTabs
|
||||
|
||||
Reference in New Issue
Block a user