Commit 8e3bfaf2 authored by hjk's avatar hjk
Browse files

Merge branch 'aumuell'

parents cc82a0c7 3be27a70
......@@ -40,8 +40,6 @@
// Qt Creator. The idea is to keep this file here in a "clean" state that
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
//#include <indenter.h>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QObject>
......@@ -790,11 +788,14 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
m_subsubmode = NoSubSubMode;
} else if (key >= '0' && key <= '9') {
if (key == '0' && m_mvcount.isEmpty()) {
moveToFirstNonBlankOnLine();
moveToStartOfLine();
finishMovement();
} else {
m_mvcount.append(QChar(key));
}
} else if (key == '^') {
moveToFirstNonBlankOnLine();
finishMovement();
} else if (0 && key == ',') {
// FIXME: fakevim uses ',' by itself, so it is incompatible
m_subsubmode = FtSubSubMode;
......@@ -951,7 +952,15 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
m_subsubmode = FtSubSubMode;
m_subsubdata = key;
} else if (key == 'g') {
m_gflag = true;
if (m_gflag) {
m_gflag = false;
m_tc.setPosition(firstPositionInLine(1), KeepAnchor);
if (m_config[ConfigStartOfLine] == ConfigOn)
moveToFirstNonBlankOnLine();
finishMovement();
} else {
m_gflag = true;
}
} else if (key == 'G') {
int n = m_mvcount.isEmpty() ? linesInDocument() : count();
m_tc.setPosition(firstPositionInLine(n), KeepAnchor);
......@@ -996,7 +1005,9 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
moveDown(count());
moveToDesiredColumn();
} else {
m_moveType = MoveLineWise;
moveToStartOfLine();
setAnchor();
moveDown(count() + 1);
}
finishMovement();
......@@ -1021,8 +1032,10 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
moveUp(count());
moveToDesiredColumn();
} else {
m_moveType = MoveLineWise;
moveToStartOfLine();
moveDown();
setAnchor();
moveUp(count() + 1);
}
finishMovement();
......@@ -1221,6 +1234,8 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
} else if (key == Key_Escape) {
if (m_visualMode != NoVisualMode)
leaveVisualMode();
else
handled = false;
} else {
qDebug() << "IGNORED IN COMMAND MODE: " << key << text;
if (text.isEmpty())
......@@ -1704,11 +1719,15 @@ int FakeVimHandler::Private::indentDist() const
const TextEditor::TextBlockIterator end(m_tc.block().next());
return indenter.indentForBottomLine(current, begin, end, QChar(' '));
#endif
return 0;
int amount = 0;
emit q->indentRegion(&amount, m_tc.block(), m_tc.block(), QChar(' '));
return amount;
}
void FakeVimHandler::Private::indentRegion(QTextBlock begin, QTextBlock end, QChar typedChar)
{
int amount = 0;
emit q->indentRegion(&amount, begin, end, typedChar);
#if 0
// FIXME: Make independent of TextEditor
if (!m_texteditor)
......@@ -1844,6 +1863,16 @@ void FakeVimHandler::Private::moveToNextWord(bool simple)
void FakeVimHandler::Private::moveToMatchingParanthesis()
{
bool moved = false;
bool forward = false;
emit q->moveToMatchingParenthesis(&moved, &forward, &m_tc);
if (moved && forward) {
if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode)
m_tc.movePosition(Left, KeepAnchor, 1);
}
#if 0
// FIXME: remove TextEditor dependency
bool undoFakeEOL = false;
......
......@@ -36,6 +36,7 @@
#include <QtCore/QObject>
#include <QtGui/QTextEdit>
#include <QtGui/QTextBlock>
QT_BEGIN_NAMESPACE
class QString;
......@@ -79,6 +80,8 @@ signals:
void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection);
void writeFileRequested(bool *handled,
const QString &fileName, const QString &contents);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
void indentRegion(int *amount, QTextBlock begin, QTextBlock end, QChar typedChar);
private:
bool eventFilter(QObject *ob, QEvent *ev);
......
......@@ -56,9 +56,12 @@
#include <texteditor/interactionsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/textblockiterator.h>
#include <utils/qtcassert.h>
#include <indenter.h>
#include <QtCore/QDebug>
#include <QtCore/QtPlugin>
#include <QtCore/QObject>
......@@ -122,6 +125,8 @@ private slots:
void showExtraInformation(const QString &msg);
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections);
void writeFile(bool *handled, const QString &fileName, const QString &contents);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
void indentRegion(int *amount, QTextBlock begin, QTextBlock end, QChar typedChar);
private:
FakeVimPlugin *q;
......@@ -203,6 +208,10 @@ void FakeVimPluginPrivate::installHandler(Core::IEditor *editor)
this, SLOT(writeFile(bool*,QString,QString)));
connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)),
this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)),
this, SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)));
connect(handler, SIGNAL(indentRegion(int*,QTextBlock,QTextBlock,QChar)),
this, SLOT(indentRegion(int*,QTextBlock,QTextBlock,QChar)));
handler->setupWidget();
handler->setExtraData(editor);
......@@ -250,6 +259,81 @@ void FakeVimPluginPrivate::writeFile(bool *handled,
}
}
void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward,
QTextCursor *cursor)
{
*moved = false;
bool undoFakeEOL = false;
if (cursor->atBlockEnd() && cursor->block().length() > 1) {
cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1);
undoFakeEOL = true;
}
TextEditor::TextBlockUserData::MatchType match
= TextEditor::TextBlockUserData::matchCursorForward(cursor);
if (match == TextEditor::TextBlockUserData::Match) {
*moved = true;
*forward = true;
} else {
if (undoFakeEOL)
cursor->movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1);
if (match == TextEditor::TextBlockUserData::NoMatch) {
// backward matching is according to the character before the cursor
bool undoMove = false;
if (!cursor->atBlockEnd()) {
cursor->movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1);
undoMove = true;
}
match = TextEditor::TextBlockUserData::matchCursorBackward(cursor);
if (match == TextEditor::TextBlockUserData::Match) {
*moved = true;
*forward = false;
} else if (undoMove) {
cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1);
}
}
}
}
void FakeVimPluginPrivate::indentRegion(int *amount, QTextBlock begin, QTextBlock end,
QChar typedChar)
{
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
if (!handler)
return;
BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget());
if (!bt)
return;
typedef SharedTools::Indenter<TextEditor::TextBlockIterator> Indenter;
Indenter &indenter = Indenter::instance();
indenter.setIndentSize(bt->tabSettings().m_indentSize);
indenter.setTabSize(bt->tabSettings().m_tabSize);
const QTextDocument *doc = begin.document();
const TextEditor::TextBlockIterator docStart(doc->begin());
QTextBlock cur = begin;
do {
if (typedChar == 0 && cur.text().simplified().isEmpty()) {
*amount = 0;
if (cur != end) {
QTextCursor cursor(cur);
while (!cursor.atBlockEnd())
cursor.deleteChar();
}
} else {
const TextEditor::TextBlockIterator current(cur);
const TextEditor::TextBlockIterator next(cur.next());
*amount = indenter.indentForBottomLine(current, docStart, next, typedChar);
if (cur != end)
bt->tabSettings().indentLine(cur, *amount);
}
if (cur != end)
cur = cur.next();
} while (cur != end);
}
void FakeVimPluginPrivate::removeHandler()
{
if (FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender())) {
......
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