Commit c68c245f authored by hluk's avatar hluk Committed by hjk

FakeVim: Reset FakeVim properly after user command

If FakeVim mode is disabled, enable it just for the single requested
user command.

Keep useful messages shown for few seconds.

Task-number: QTCREATORBUG-10460
Change-Id: I89c1722542f47befbf2c24a663bf3d1c455b77d9
Reviewed-by: default avatarMitch Curtis <mitch.curtis@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 790b9763
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
#include <QTextBlock> #include <QTextBlock>
#include <QTextCursor> #include <QTextCursor>
#include <QTextEdit> #include <QTextEdit>
#include <QTimer>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
using namespace TextEditor; using namespace TextEditor;
...@@ -120,7 +121,11 @@ class MiniBuffer : public QStackedWidget ...@@ -120,7 +121,11 @@ class MiniBuffer : public QStackedWidget
Q_OBJECT Q_OBJECT
public: public:
MiniBuffer() : m_label(new QLabel(this)), m_edit(new QLineEdit(this)), m_eventFilter(0) MiniBuffer()
: m_label(new QLabel(this))
, m_edit(new QLineEdit(this))
, m_eventFilter(0)
, m_lastMessageLevel(MessageMode)
{ {
connect(m_edit, SIGNAL(textEdited(QString)), SLOT(changed())); connect(m_edit, SIGNAL(textEdited(QString)), SLOT(changed()));
connect(m_edit, SIGNAL(cursorPositionChanged(int,int)), SLOT(changed())); connect(m_edit, SIGNAL(cursorPositionChanged(int,int)), SLOT(changed()));
...@@ -129,6 +134,10 @@ public: ...@@ -129,6 +134,10 @@ public:
addWidget(m_label); addWidget(m_label);
addWidget(m_edit); addWidget(m_edit);
m_hideTimer.setSingleShot(true);
m_hideTimer.setInterval(8000);
connect(&m_hideTimer, SIGNAL(timeout()), SLOT(hide()));
} }
void setContents(const QString &contents, int cursorPos, int anchorPos, void setContents(const QString &contents, int cursorPos, int anchorPos,
...@@ -145,10 +154,16 @@ public: ...@@ -145,10 +154,16 @@ public:
m_edit->blockSignals(false); m_edit->blockSignals(false);
setCurrentWidget(m_edit); setCurrentWidget(m_edit);
m_edit->setFocus(); m_edit->setFocus();
} else if (contents.isEmpty() && messageLevel != MessageShowCmd) { } else {
if (contents.isEmpty()) {
if (m_lastMessageLevel == MessageMode)
hide(); hide();
else
m_hideTimer.start();
} else { } else {
m_hideTimer.stop();
show(); show();
m_label->setText(contents); m_label->setText(contents);
QString css; QString css;
...@@ -164,6 +179,7 @@ public: ...@@ -164,6 +179,7 @@ public:
} }
m_label->setStyleSheet(QString::fromLatin1( m_label->setStyleSheet(QString::fromLatin1(
"*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css)); "*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css));
}
if (m_edit->hasFocus()) if (m_edit->hasFocus())
emit edited(QString(), -1, -1); emit edited(QString(), -1, -1);
...@@ -183,6 +199,8 @@ public: ...@@ -183,6 +199,8 @@ public:
} }
m_eventFilter = eventFilter; m_eventFilter = eventFilter;
} }
m_lastMessageLevel = messageLevel;
} }
QSize sizeHint() const QSize sizeHint() const
...@@ -209,6 +227,8 @@ private: ...@@ -209,6 +227,8 @@ private:
QLabel *m_label; QLabel *m_label;
QLineEdit *m_edit; QLineEdit *m_edit;
QObject *m_eventFilter; QObject *m_eventFilter;
QTimer m_hideTimer;
int m_lastMessageLevel;
}; };
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
...@@ -1124,11 +1144,20 @@ void FakeVimPluginPrivate::userActionTriggered() ...@@ -1124,11 +1144,20 @@ void FakeVimPluginPrivate::userActionTriggered()
const int key = act->data().toInt(); const int key = act->data().toInt();
if (!key) if (!key)
return; return;
QString cmd = userCommandMap().value(key);
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
FakeVimHandler *handler = m_editorToHandler[editor]; FakeVimHandler *handler = m_editorToHandler[editor];
if (handler) if (handler) {
// If disabled, enable FakeVim mode just for single user command.
bool enableFakeVim = !theFakeVimSetting(ConfigUseFakeVim)->value().toBool();
if (enableFakeVim)
setUseFakeVimInternal(true);
const QString cmd = userCommandMap().value(key);
handler->handleInput(cmd); handler->handleInput(cmd);
if (enableFakeVim)
setUseFakeVimInternal(false);
}
} }
......
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