Commit c4fede0f authored by Martin Aumüller's avatar Martin Aumüller Committed by hjk
Browse files

fakevim: use BaseTextEditor's isElectricCharacter



in order for automatic indenting to work, isElectricCharacter has to match the language of the document

Merge-request: 98
Reviewed-by: default avatarhjk <qtc-committer@nokia.com>
parent 46abe329
......@@ -322,8 +322,7 @@ public:
{ setPosition(p.position); scrollToLineInDocument(p.scrollLine); }
// helper functions for indenting
bool isElectricCharacter(QChar c) const
{ return c == '{' || c == '}' || c == '#'; }
bool isElectricCharacter(QChar c) const;
void indentRegion(QChar lastTyped = QChar());
void shiftRegionLeft(int repeat = 1);
void shiftRegionRight(int repeat = 1);
......@@ -2429,6 +2428,13 @@ void FakeVimHandler::Private::indentRegion(QChar typedChar)
setDotCommand("%1==", endLine - beginLine + 1);
}
bool FakeVimHandler::Private::isElectricCharacter(QChar c) const
{
bool result = false;
emit q->checkForElectricCharacter(&result, c);
return result;
}
void FakeVimHandler::Private::shiftRegionRight(int repeat)
{
int beginLine = lineForPosition(anchor());
......
......@@ -77,6 +77,7 @@ signals:
const QString &fileName, const QString &contents);
void writeAllRequested(QString *error);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
void checkForElectricCharacter(bool *result, QChar c);
void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar);
void completionRequested();
void windowCommandRequested(int key);
......
......@@ -268,6 +268,7 @@ private slots:
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 checkForElectricCharacter(bool *result, QChar c);
void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar);
void handleExCommand(const QString &cmd);
......@@ -446,6 +447,8 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
this, SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)));
connect(handler, SIGNAL(indentRegion(int*,int,int,QChar)),
this, SLOT(indentRegion(int*,int,int,QChar)));
connect(handler, SIGNAL(checkForElectricCharacter(bool*,QChar)),
this, SLOT(checkForElectricCharacter(bool*,QChar)));
connect(handler, SIGNAL(completionRequested()),
this, SLOT(triggerCompletions()));
connect(handler, SIGNAL(windowCommandRequested(int)),
......@@ -502,6 +505,15 @@ void FakeVimPluginPrivate::triggerCompletions()
// bt->triggerCompletions();
}
void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c)
{
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
if (!handler)
return;
if (BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget()))
*result = bt->isElectricCharacter(c);
}
void FakeVimPluginPrivate::writeFile(bool *handled,
const QString &fileName, const QString &contents)
{
......
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