forked from qt-creator/qt-creator
fakevim: use basetext indentation access instead of the cppeditor based one
This commit is contained in:
@@ -630,7 +630,7 @@ public:
|
|||||||
// Helper functions for indenting/
|
// Helper functions for indenting/
|
||||||
bool isElectricCharacter(QChar c) const;
|
bool isElectricCharacter(QChar c) const;
|
||||||
void indentSelectedText(QChar lastTyped = QChar());
|
void indentSelectedText(QChar lastTyped = QChar());
|
||||||
int indentText(const Range &range, QChar lastTyped = QChar());
|
void indentText(const Range &range, QChar lastTyped = QChar());
|
||||||
void shiftRegionLeft(int repeat = 1);
|
void shiftRegionLeft(int repeat = 1);
|
||||||
void shiftRegionRight(int repeat = 1);
|
void shiftRegionRight(int repeat = 1);
|
||||||
|
|
||||||
@@ -3540,20 +3540,17 @@ void FakeVimHandler::Private::indentSelectedText(QChar typedChar)
|
|||||||
setDotCommand("%1==", endLine - beginLine + 1);
|
setDotCommand("%1==", endLine - beginLine + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FakeVimHandler::Private::indentText(const Range &range, QChar typedChar)
|
void FakeVimHandler::Private::indentText(const Range &range, QChar typedChar)
|
||||||
{
|
{
|
||||||
int beginLine = lineForPosition(range.beginPos);
|
int beginLine = lineForPosition(range.beginPos);
|
||||||
int endLine = lineForPosition(range.endPos);
|
int endLine = lineForPosition(range.endPos);
|
||||||
if (beginLine > endLine)
|
if (beginLine > endLine)
|
||||||
qSwap(beginLine, endLine);
|
qSwap(beginLine, endLine);
|
||||||
|
|
||||||
int amount = 0;
|
// LineForPosition has returned 1-based line numbers.
|
||||||
// lineForPosition has returned 1-based line numbers
|
emit q->indentRegion(beginLine - 1, endLine - 1, typedChar);
|
||||||
emit q->indentRegion(&amount, beginLine - 1, endLine - 1, typedChar);
|
|
||||||
fixMarks(firstPositionInLine(beginLine), amount);
|
|
||||||
if (beginLine != endLine)
|
if (beginLine != endLine)
|
||||||
showBlackMessage("MARKS ARE OFF NOW");
|
showBlackMessage("MARKS ARE OFF NOW");
|
||||||
return amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeVimHandler::Private::isElectricCharacter(QChar c) const
|
bool FakeVimHandler::Private::isElectricCharacter(QChar c) const
|
||||||
@@ -4432,7 +4429,9 @@ void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown)
|
|||||||
|
|
||||||
if (hasConfig(ConfigSmartIndent)) {
|
if (hasConfig(ConfigSmartIndent)) {
|
||||||
Range range(m_tc.block().position(), m_tc.block().position());
|
Range range(m_tc.block().position(), m_tc.block().position());
|
||||||
m_justAutoIndented = indentText(range, QLatin1Char('\n'));
|
const int oldSize = m_tc.block().text().size();
|
||||||
|
indentText(range, QLatin1Char('\n'));
|
||||||
|
m_justAutoIndented = m_tc.block().text().size() - oldSize;
|
||||||
} else {
|
} else {
|
||||||
QTextBlock block = goingDown ? m_tc.block().previous() : m_tc.block().next();
|
QTextBlock block = goingDown ? m_tc.block().previous() : m_tc.block().next();
|
||||||
QString text = block.text();
|
QString text = block.text();
|
||||||
@@ -4702,6 +4701,10 @@ QString FakeVimHandler::tabExpand(int n) const
|
|||||||
return d->tabExpand(n);
|
return d->tabExpand(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::fixMarks(int positionAction, int positionChange)
|
||||||
|
{
|
||||||
|
d->fixMarks(positionAction, positionChange);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace FakeVim
|
} // namespace FakeVim
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ public slots:
|
|||||||
int physicalIndentation(const QString &line) const;
|
int physicalIndentation(const QString &line) const;
|
||||||
int logicalIndentation(const QString &line) const;
|
int logicalIndentation(const QString &line) const;
|
||||||
QString tabExpand(int n) const;
|
QString tabExpand(int n) const;
|
||||||
|
void fixMarks(int positionAction, int positionChange);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void commandBufferChanged(const QString &msg);
|
void commandBufferChanged(const QString &msg);
|
||||||
@@ -113,7 +114,7 @@ signals:
|
|||||||
void writeAllRequested(QString *error);
|
void writeAllRequested(QString *error);
|
||||||
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
|
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
|
||||||
void checkForElectricCharacter(bool *result, QChar c);
|
void checkForElectricCharacter(bool *result, QChar c);
|
||||||
void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar);
|
void indentRegion(int beginLine, int endLine, QChar typedChar);
|
||||||
void completionRequested();
|
void completionRequested();
|
||||||
void windowCommandRequested(int key);
|
void windowCommandRequested(int key);
|
||||||
void findRequested(bool reverse);
|
void findRequested(bool reverse);
|
||||||
|
|||||||
@@ -70,8 +70,6 @@
|
|||||||
|
|
||||||
#include <cpptools/cpptoolsconstants.h>
|
#include <cpptools/cpptoolsconstants.h>
|
||||||
|
|
||||||
#include <indenter.h>
|
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
@@ -508,7 +506,7 @@ private slots:
|
|||||||
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections);
|
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections);
|
||||||
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
|
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
|
||||||
void checkForElectricCharacter(bool *result, QChar c);
|
void checkForElectricCharacter(bool *result, QChar c);
|
||||||
void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar);
|
void indentRegion(int beginLine, int endLine, QChar typedChar);
|
||||||
void handleExCommand(bool *handled, const ExCommand &cmd);
|
void handleExCommand(bool *handled, const ExCommand &cmd);
|
||||||
|
|
||||||
void handleDelayedQuitAll(bool forced);
|
void handleDelayedQuitAll(bool forced);
|
||||||
@@ -837,8 +835,8 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
|
|||||||
this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
|
this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
|
||||||
connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)),
|
connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)),
|
||||||
this, SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)));
|
this, SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)));
|
||||||
connect(handler, SIGNAL(indentRegion(int*,int,int,QChar)),
|
connect(handler, SIGNAL(indentRegion(int,int,QChar)),
|
||||||
this, SLOT(indentRegion(int*,int,int,QChar)));
|
this, SLOT(indentRegion(int,int,QChar)));
|
||||||
connect(handler, SIGNAL(checkForElectricCharacter(bool*,QChar)),
|
connect(handler, SIGNAL(checkForElectricCharacter(bool*,QChar)),
|
||||||
this, SLOT(checkForElectricCharacter(bool*,QChar)));
|
this, SLOT(checkForElectricCharacter(bool*,QChar)));
|
||||||
connect(handler, SIGNAL(completionRequested()),
|
connect(handler, SIGNAL(completionRequested()),
|
||||||
@@ -1047,7 +1045,7 @@ void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine,
|
void FakeVimPluginPrivate::indentRegion(int beginLine, int endLine,
|
||||||
QChar typedChar)
|
QChar typedChar)
|
||||||
{
|
{
|
||||||
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
||||||
@@ -1058,33 +1056,43 @@ void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine,
|
|||||||
if (!bt)
|
if (!bt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditor::TabSettings tabSettings;
|
const TextEditor::TabSettings oldTabSettings = bt->tabSettings();
|
||||||
|
|
||||||
|
TabSettings tabSettings;
|
||||||
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
|
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
|
||||||
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
|
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
|
||||||
tabSettings.m_spacesForTabs = theFakeVimSetting(ConfigExpandTab)->value().toBool();
|
tabSettings.m_spacesForTabs = theFakeVimSetting(ConfigExpandTab)->value().toBool();
|
||||||
typedef SharedTools::Indenter<TextEditor::TextBlockIterator> Indenter;
|
bt->setTabSettings(tabSettings);
|
||||||
Indenter &indenter = Indenter::instance();
|
|
||||||
indenter.setIndentSize(tabSettings.m_indentSize);
|
QTextDocument *doc = bt->document();
|
||||||
indenter.setTabSize(tabSettings.m_tabSize);
|
QTextBlock startBlock = doc->findBlockByNumber(beginLine);
|
||||||
|
|
||||||
|
// Record line lenghts for mark adjustments
|
||||||
|
QVector<int> lineLengths(endLine - beginLine + 1);
|
||||||
|
QTextBlock block = startBlock;
|
||||||
|
|
||||||
const QTextDocument *doc = bt->document();
|
|
||||||
const TextEditor::TextBlockIterator docStart(doc->begin());
|
|
||||||
QTextBlock cur = doc->findBlockByNumber(beginLine);
|
|
||||||
for (int i = beginLine; i <= endLine; ++i) {
|
for (int i = beginLine; i <= endLine; ++i) {
|
||||||
if (typedChar == 0 && cur.text().simplified().isEmpty()) {
|
lineLengths[i - beginLine] = block.text().length();
|
||||||
|
if (typedChar == 0 && block.text().simplified().isEmpty()) {
|
||||||
// clear empty lines
|
// clear empty lines
|
||||||
*amount = 0;
|
QTextCursor cursor(block);
|
||||||
QTextCursor cursor(cur);
|
|
||||||
while (!cursor.atBlockEnd())
|
while (!cursor.atBlockEnd())
|
||||||
cursor.deleteChar();
|
cursor.deleteChar();
|
||||||
} else {
|
} else {
|
||||||
const TextEditor::TextBlockIterator current(cur);
|
bt->indentBlock(doc, block, typedChar);
|
||||||
const TextEditor::TextBlockIterator next(cur.next());
|
|
||||||
*amount = indenter.indentForBottomLine(current, docStart, next, typedChar);
|
|
||||||
tabSettings.indentLine(cur, *amount);
|
|
||||||
}
|
}
|
||||||
cur = cur.next();
|
block = block.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust marks.
|
||||||
|
block = startBlock;
|
||||||
|
for (int i = beginLine; i <= endLine; ++i) {
|
||||||
|
const int amount = block.text().length() - lineLengths[i - beginLine];
|
||||||
|
handler->fixMarks(block.position(), amount);
|
||||||
|
block = block.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
bt->setTabSettings(oldTabSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::quitFakeVim()
|
void FakeVimPluginPrivate::quitFakeVim()
|
||||||
|
|||||||
Reference in New Issue
Block a user