2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "tabsettings.h"
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
#include <utils/settingsutils.h>
|
|
|
|
|
|
2009-01-23 18:21:36 +01:00
|
|
|
#include <QtCore/QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
|
#include <QtGui/QTextDocument>
|
|
|
|
|
|
2011-05-10 15:19:38 +02:00
|
|
|
static const char spacesForTabsKey[] = "SpacesForTabs";
|
|
|
|
|
static const char autoSpacesForTabsKey[] = "AutoSpacesForTabs";
|
|
|
|
|
static const char smartBackspaceKey[] = "SmartBackspace";
|
|
|
|
|
static const char autoIndentKey[] = "AutoIndent";
|
|
|
|
|
static const char tabSizeKey[] = "TabSize";
|
|
|
|
|
static const char indentSizeKey[] = "IndentSize";
|
|
|
|
|
static const char indentBracesKey[] = "IndentBraces";
|
|
|
|
|
static const char doubleIndentBlocksKey[] = "DoubleIndentBlocks";
|
|
|
|
|
static const char tabKeyBehaviorKey[] = "TabKeyBehavior";
|
|
|
|
|
static const char groupPostfix[] = "TabSettings";
|
|
|
|
|
static const char paddingModeKey[] = "PaddingMode";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
TabSettings::TabSettings() :
|
|
|
|
|
m_spacesForTabs(true),
|
2009-10-03 23:15:17 +05:30
|
|
|
m_autoSpacesForTabs(false),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_autoIndent(true),
|
|
|
|
|
m_smartBackspace(false),
|
|
|
|
|
m_tabSize(8),
|
2009-05-18 12:21:30 -05:00
|
|
|
m_indentSize(4),
|
2009-10-27 13:34:48 -04:00
|
|
|
m_indentBraces(false),
|
2010-04-01 04:25:32 +04:00
|
|
|
m_doubleIndentBlocks(false),
|
2010-09-13 12:36:18 +02:00
|
|
|
m_tabKeyBehavior(TabNeverIndents),
|
2010-09-14 12:39:36 +02:00
|
|
|
m_continuationAlignBehavior(ContinuationAlignWithSpaces)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabSettings::toSettings(const QString &category, QSettings *s) const
|
|
|
|
|
{
|
2011-02-01 14:13:54 +01:00
|
|
|
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabSettings::fromSettings(const QString &category, const QSettings *s)
|
|
|
|
|
{
|
|
|
|
|
*this = TabSettings(); // Assign defaults
|
2011-02-01 14:13:54 +01:00
|
|
|
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void TabSettings::toMap(const QString &prefix, QVariantMap *map) const
|
|
|
|
|
{
|
|
|
|
|
map->insert(prefix + QLatin1String(spacesForTabsKey), m_spacesForTabs);
|
|
|
|
|
map->insert(prefix + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs);
|
|
|
|
|
map->insert(prefix + QLatin1String(autoIndentKey), m_autoIndent);
|
|
|
|
|
map->insert(prefix + QLatin1String(smartBackspaceKey), m_smartBackspace);
|
|
|
|
|
map->insert(prefix + QLatin1String(tabSizeKey), m_tabSize);
|
|
|
|
|
map->insert(prefix + QLatin1String(indentSizeKey), m_indentSize);
|
|
|
|
|
map->insert(prefix + QLatin1String(indentBracesKey), m_indentBraces);
|
|
|
|
|
map->insert(prefix + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks);
|
|
|
|
|
map->insert(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
|
|
|
|
|
map->insert(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 14:13:54 +01:00
|
|
|
void TabSettings::fromMap(const QString &prefix, const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_spacesForTabs =
|
|
|
|
|
map.value(prefix + QLatin1String(spacesForTabsKey), m_spacesForTabs).toBool();
|
|
|
|
|
m_autoSpacesForTabs =
|
|
|
|
|
map.value(prefix + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs).toBool();
|
|
|
|
|
m_autoIndent = map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool();
|
|
|
|
|
m_smartBackspace =
|
|
|
|
|
map.value(prefix + QLatin1String(smartBackspaceKey), m_smartBackspace).toBool();
|
|
|
|
|
m_tabSize = map.value(prefix + QLatin1String(tabSizeKey), m_tabSize).toInt();
|
|
|
|
|
m_indentSize = map.value(prefix + QLatin1String(indentSizeKey), m_indentSize).toInt();
|
|
|
|
|
m_indentBraces = map.value(prefix + QLatin1String(indentBracesKey), m_indentBraces).toBool();
|
|
|
|
|
m_doubleIndentBlocks =
|
|
|
|
|
map.value(prefix + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks).toBool();
|
|
|
|
|
m_tabKeyBehavior = (TabKeyBehavior)
|
|
|
|
|
map.value(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
|
|
|
|
|
m_continuationAlignBehavior = (ContinuationAlignBehavior)
|
|
|
|
|
map.value(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior).toInt();
|
|
|
|
|
}
|
2009-09-29 12:44:00 +02:00
|
|
|
|
|
|
|
|
bool TabSettings::cursorIsAtBeginningOfLine(const QTextCursor &cursor) const
|
|
|
|
|
{
|
|
|
|
|
QString text = cursor.block().text();
|
|
|
|
|
int fns = firstNonSpace(text);
|
|
|
|
|
return (cursor.position() - cursor.block().position() <= fns);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int TabSettings::lineIndentPosition(const QString &text) const
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < text.size()) {
|
|
|
|
|
if (!text.at(i).isSpace())
|
|
|
|
|
break;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
int column = columnAt(text, i);
|
|
|
|
|
return i - (column % m_indentSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TabSettings::firstNonSpace(const QString &text) const
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < text.size()) {
|
|
|
|
|
if (!text.at(i).isSpace())
|
|
|
|
|
return i;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-09 13:55:11 +02:00
|
|
|
QString TabSettings::indentationString(const QString &text) const
|
|
|
|
|
{
|
|
|
|
|
return text.left(firstNonSpace(text));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-09-09 16:16:46 +02:00
|
|
|
int TabSettings::indentationColumn(const QString &text) const
|
|
|
|
|
{
|
|
|
|
|
return columnAt(text, firstNonSpace(text));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-02 15:21:36 +02:00
|
|
|
int TabSettings::maximumPadding(const QString &text) const
|
|
|
|
|
{
|
2010-07-07 11:13:24 +02:00
|
|
|
int fns = firstNonSpace(text);
|
2010-07-02 15:21:36 +02:00
|
|
|
int i = fns;
|
|
|
|
|
while (i > 0) {
|
|
|
|
|
if (text.at(i-1) != QLatin1Char(' '))
|
|
|
|
|
break;
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
return fns - i;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-09 16:16:46 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int TabSettings::trailingWhitespaces(const QString &text) const
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < text.size()) {
|
|
|
|
|
if (!text.at(text.size()-1-i).isSpace())
|
|
|
|
|
return i;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-31 15:26:45 +05:30
|
|
|
bool TabSettings::isIndentationClean(const QTextBlock &block) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
int spaceCount = 0;
|
2009-10-31 15:26:45 +05:30
|
|
|
QString text = block.text();
|
|
|
|
|
bool spacesForTabs = guessSpacesForTabs(block);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (i < text.size()) {
|
|
|
|
|
QChar c = text.at(i);
|
|
|
|
|
if (!c.isSpace())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (c == QLatin1Char(' ')) {
|
|
|
|
|
++spaceCount;
|
2009-10-31 15:26:45 +05:30
|
|
|
if (!spacesForTabs && spaceCount == m_tabSize)
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
} else if (c == QLatin1Char('\t')) {
|
2009-10-31 15:26:45 +05:30
|
|
|
if (spacesForTabs || spaceCount != m_indentSize)
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
spaceCount = 0;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-18 12:21:30 -05:00
|
|
|
bool TabSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition) const
|
|
|
|
|
{
|
|
|
|
|
if (m_tabKeyBehavior == TabNeverIndents)
|
|
|
|
|
return false;
|
|
|
|
|
QTextCursor tc = cursor;
|
|
|
|
|
if (suggestedPosition)
|
|
|
|
|
*suggestedPosition = tc.position(); // At least suggest original position
|
|
|
|
|
tc.movePosition(QTextCursor::StartOfLine);
|
|
|
|
|
if (tc.atBlockEnd()) // cursor was on a blank line
|
|
|
|
|
return true;
|
|
|
|
|
if (document->characterAt(tc.position()).isSpace()) {
|
|
|
|
|
tc.movePosition(QTextCursor::WordRight);
|
2010-06-15 10:44:07 +02:00
|
|
|
if (tc.positionInBlock() >= cursor.positionInBlock()) {
|
2009-05-18 12:21:30 -05:00
|
|
|
if (suggestedPosition)
|
|
|
|
|
*suggestedPosition = tc.position(); // Suggest position after whitespace
|
|
|
|
|
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (m_tabKeyBehavior == TabAlwaysIndents);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int TabSettings::columnAt(const QString &text, int position) const
|
|
|
|
|
{
|
|
|
|
|
int column = 0;
|
|
|
|
|
for (int i = 0; i < position; ++i) {
|
|
|
|
|
if (text.at(i) == QLatin1Char('\t'))
|
|
|
|
|
column = column - (column % m_tabSize) + m_tabSize;
|
|
|
|
|
else
|
|
|
|
|
++column;
|
|
|
|
|
}
|
|
|
|
|
return column;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-05 15:01:20 +02:00
|
|
|
int TabSettings::positionAtColumn(const QString &text, int column, int *offset) const
|
|
|
|
|
{
|
|
|
|
|
int col = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < text.size() && col < column) {
|
|
|
|
|
if (text.at(i) == QLatin1Char('\t'))
|
|
|
|
|
col = col - (col % m_tabSize) + m_tabSize;
|
|
|
|
|
else
|
|
|
|
|
++col;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
if (offset)
|
|
|
|
|
*offset = column - col;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int TabSettings::spacesLeftFromPosition(const QString &text, int position) const
|
|
|
|
|
{
|
|
|
|
|
int i = position;
|
|
|
|
|
while (i > 0) {
|
|
|
|
|
if (!text.at(i-1).isSpace())
|
|
|
|
|
break;
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
return position - i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TabSettings::indentedColumn(int column, bool doIndent) const
|
|
|
|
|
{
|
|
|
|
|
int aligned = (column / m_indentSize) * m_indentSize;
|
|
|
|
|
if (doIndent)
|
|
|
|
|
return aligned + m_indentSize;
|
|
|
|
|
if (aligned < column)
|
|
|
|
|
return aligned;
|
|
|
|
|
return qMax(0, aligned - m_indentSize);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 16:08:25 +01:00
|
|
|
bool TabSettings::guessSpacesForTabs(const QTextBlock &_block) const
|
|
|
|
|
{
|
2009-10-31 15:49:42 +05:30
|
|
|
if (m_spacesForTabs && m_autoSpacesForTabs && _block.isValid()) {
|
2010-02-08 16:08:25 +01:00
|
|
|
const QTextDocument *doc = _block.document();
|
2009-10-31 15:29:30 +05:30
|
|
|
QVector<QTextBlock> currentBlocks(2, _block); // [0] looks back; [1] looks forward
|
|
|
|
|
int maxLookAround = 100;
|
|
|
|
|
while (maxLookAround-- > 0) {
|
2009-12-21 15:08:48 +05:30
|
|
|
if (currentBlocks.at(0).isValid())
|
|
|
|
|
currentBlocks[0] = currentBlocks.at(0).previous();
|
|
|
|
|
if (currentBlocks.at(1).isValid())
|
|
|
|
|
currentBlocks[1] = currentBlocks.at(1).next();
|
2009-10-31 15:29:30 +05:30
|
|
|
bool done = true;
|
2010-02-08 16:08:25 +01:00
|
|
|
foreach (const QTextBlock &block, currentBlocks) {
|
2009-10-31 15:29:30 +05:30
|
|
|
if (block.isValid())
|
|
|
|
|
done = false;
|
2010-02-08 16:08:25 +01:00
|
|
|
if (!block.isValid() || block.length() == 0)
|
2009-10-31 15:29:30 +05:30
|
|
|
continue;
|
2010-02-08 16:08:25 +01:00
|
|
|
const QChar firstChar = doc->characterAt(block.position());
|
2009-10-31 15:29:30 +05:30
|
|
|
if (firstChar == QLatin1Char(' ')) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (firstChar == QLatin1Char('\t')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-03 23:15:17 +05:30
|
|
|
}
|
2009-10-31 15:29:30 +05:30
|
|
|
if (done)
|
|
|
|
|
break;
|
2009-10-03 23:15:17 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return m_spacesForTabs;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 16:08:25 +01:00
|
|
|
QString TabSettings::indentationString(int startColumn, int targetColumn, const QTextBlock &block) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
targetColumn = qMax(startColumn, targetColumn);
|
2009-10-03 23:15:17 +05:30
|
|
|
if (guessSpacesForTabs(block))
|
2008-12-02 12:01:29 +01:00
|
|
|
return QString(targetColumn - startColumn, QLatin1Char(' '));
|
|
|
|
|
|
|
|
|
|
QString s;
|
|
|
|
|
int alignedStart = startColumn - (startColumn % m_tabSize) + m_tabSize;
|
|
|
|
|
if (alignedStart > startColumn && alignedStart <= targetColumn) {
|
|
|
|
|
s += QLatin1Char('\t');
|
|
|
|
|
startColumn = alignedStart;
|
|
|
|
|
}
|
|
|
|
|
if (int columns = targetColumn - startColumn) {
|
|
|
|
|
int tabs = columns / m_tabSize;
|
|
|
|
|
s += QString(tabs, QLatin1Char('\t'));
|
|
|
|
|
s += QString(columns - tabs * m_tabSize, QLatin1Char(' '));
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-02 15:21:36 +02:00
|
|
|
void TabSettings::indentLine(QTextBlock block, int newIndent, int padding) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
const QString text = block.text();
|
|
|
|
|
const int oldBlockLength = text.size();
|
|
|
|
|
|
2010-09-14 12:39:36 +02:00
|
|
|
if (m_continuationAlignBehavior == NoContinuationAlign) {
|
2010-09-13 12:36:18 +02:00
|
|
|
newIndent -= padding;
|
|
|
|
|
padding = 0;
|
2010-09-14 12:39:36 +02:00
|
|
|
} else if (m_continuationAlignBehavior == ContinuationAlignWithIndent) {
|
2010-09-13 12:36:18 +02:00
|
|
|
padding = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Quickly check whether indenting is required.
|
2009-09-09 16:16:46 +02:00
|
|
|
if (indentationColumn(text) == newIndent)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
2010-07-02 15:21:36 +02:00
|
|
|
QString indentString;
|
|
|
|
|
|
2010-09-13 12:36:18 +02:00
|
|
|
if (!m_spacesForTabs) {
|
2010-07-02 15:21:36 +02:00
|
|
|
// user likes tabs for spaces and uses tabs for indentation, preserve padding
|
|
|
|
|
indentString = indentationString(0, newIndent - padding, block);
|
|
|
|
|
indentString += QString(padding, QLatin1Char(' '));
|
|
|
|
|
} else {
|
|
|
|
|
indentString = indentationString(0, newIndent, block);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-29 12:44:00 +02:00
|
|
|
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;
|
|
|
|
|
|
2010-07-02 15:21:36 +02:00
|
|
|
QString indentString;
|
|
|
|
|
if (!m_spacesForTabs && m_tabSize == m_indentSize) {
|
|
|
|
|
// user likes tabs for spaces and uses tabs for indentation, preserve padding
|
|
|
|
|
int padding = qMin(maximumPadding(text), newIndent);
|
|
|
|
|
indentString = indentationString(0, newIndent - padding, block);
|
|
|
|
|
indentString += QString(padding, QLatin1Char(' '));
|
|
|
|
|
} else {
|
|
|
|
|
indentString = indentationString(0, newIndent, block);
|
|
|
|
|
}
|
2009-09-29 12:44:00 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool TabSettings::equals(const TabSettings &ts) const
|
|
|
|
|
{
|
|
|
|
|
return m_spacesForTabs == ts.m_spacesForTabs
|
2009-10-04 00:26:21 +05:30
|
|
|
&& m_autoSpacesForTabs == ts.m_autoSpacesForTabs
|
2008-12-02 12:01:29 +01:00
|
|
|
&& m_autoIndent == ts.m_autoIndent
|
|
|
|
|
&& m_smartBackspace == ts.m_smartBackspace
|
|
|
|
|
&& m_tabSize == ts.m_tabSize
|
2009-05-18 12:21:30 -05:00
|
|
|
&& m_indentSize == ts.m_indentSize
|
2009-10-27 13:34:48 -04:00
|
|
|
&& m_indentBraces == ts.m_indentBraces
|
2010-04-01 04:25:32 +04:00
|
|
|
&& m_doubleIndentBlocks == ts.m_doubleIndentBlocks
|
2010-09-13 12:36:18 +02:00
|
|
|
&& m_tabKeyBehavior == ts.m_tabKeyBehavior
|
2010-09-14 12:39:36 +02:00
|
|
|
&& m_continuationAlignBehavior == ts.m_continuationAlignBehavior;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|