Commit f31da9ac authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

fakevim: Show current command in minibuffer (showcmd option)



Use showcmd Vim option to show current partial command.

Removed unneeded updateMiniBuffer() calls.

Change-Id: Iddacd364b7c92882b6169a6894c89cdb202a32bf
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 7e57e819
......@@ -256,6 +256,13 @@ FakeVimSettings *theFakeVimSettings()
item->setCheckable(true);
instance->insertItem(ConfigClipboard, item, _("clipboard"), _("cb"));
item = new SavedAction(instance);
item->setDefaultValue(true);
item->setValue(true);
item->setSettingsKey(group, _("ShowCmd")); item->setCheckable(true);
item->setCheckable(true);
instance->insertItem(ConfigShowCmd, item, _("showcmd"), _("sc"));
return instance;
}
......
......@@ -70,7 +70,8 @@ enum FakeVimSettingsCode
// other actions
ConfigShowMarks,
ConfigPassControlKey,
ConfigClipboard
ConfigClipboard,
ConfigShowCmd
};
class FakeVimSettings : public QObject
......
......@@ -615,6 +615,94 @@ static void setClipboardData(const QString &content, RangeMode mode,
clipboard->setMimeData(data, clipboardMode);
}
static const QMap<QString, int> &vimKeyNames()
{
static QMap<QString, int> k;
if (!k.isEmpty())
return k;
// FIXME: Should be value of mapleader.
k.insert("LEADER", Key_Backslash);
k.insert("SPACE", Key_Space);
k.insert("TAB", Key_Tab);
k.insert("NL", Key_Return);
k.insert("NEWLINE", Key_Return);
k.insert("LINEFEED", Key_Return);
k.insert("LF", Key_Return);
k.insert("CR", Key_Return);
k.insert("RETURN", Key_Return);
k.insert("ENTER", Key_Return);
k.insert("BS", Key_Backspace);
k.insert("BACKSPACE", Key_Backspace);
k.insert("ESC", Key_Escape);
k.insert("BAR", Key_Bar);
k.insert("BSLASH", Key_Backslash);
k.insert("DEL", Key_Delete);
k.insert("DELETE", Key_Delete);
k.insert("KDEL", Key_Delete);
k.insert("UP", Key_Up);
k.insert("DOWN", Key_Down);
k.insert("LEFT", Key_Left);
k.insert("RIGHT", Key_Right);
k.insert("F1", Key_F1);
k.insert("F2", Key_F2);
k.insert("F3", Key_F3);
k.insert("F4", Key_F4);
k.insert("F5", Key_F5);
k.insert("F6", Key_F6);
k.insert("F7", Key_F7);
k.insert("F8", Key_F8);
k.insert("F9", Key_F9);
k.insert("F10", Key_F10);
k.insert("F11", Key_F11);
k.insert("F12", Key_F12);
k.insert("F13", Key_F13);
k.insert("F14", Key_F14);
k.insert("F15", Key_F15);
k.insert("F16", Key_F16);
k.insert("F17", Key_F17);
k.insert("F18", Key_F18);
k.insert("F19", Key_F19);
k.insert("F20", Key_F20);
k.insert("F21", Key_F21);
k.insert("F22", Key_F22);
k.insert("F23", Key_F23);
k.insert("F24", Key_F24);
k.insert("F25", Key_F25);
k.insert("F26", Key_F26);
k.insert("F27", Key_F27);
k.insert("F28", Key_F28);
k.insert("F29", Key_F29);
k.insert("F30", Key_F30);
k.insert("F31", Key_F31);
k.insert("F32", Key_F32);
k.insert("F33", Key_F33);
k.insert("F34", Key_F34);
k.insert("F35", Key_F35);
k.insert("INSERT", Key_Insert);
k.insert("INS", Key_Insert);
k.insert("KINSERT", Key_Insert);
k.insert("HOME", Key_Home);
k.insert("END", Key_End);
k.insert("PAGEUP", Key_PageUp);
k.insert("PAGEDOWN", Key_PageDown);
k.insert("KPLUS", Key_Plus);
k.insert("KMINUS", Key_Minus);
k.insert("KDIVIDE", Key_Slash);
k.insert("KMULTIPLY", Key_Asterisk);
k.insert("KENTER", Key_Enter);
k.insert("KPOINT", Key_Period);
return k;
}
Range::Range()
: beginPos(-1), endPos(-1), rangemode(RangeCharMode)
......@@ -810,6 +898,17 @@ public:
return m_key;
}
QString toString() const
{
bool hasCtrl = m_modifiers & int(HostOsInfo::controlModifier());
QString key = vimKeyNames().key(m_key);
if (key.isEmpty())
key = QChar(m_xkey);
else
key = '<' + key + '>';
return (hasCtrl ? QString("^") : QString()) + key;
}
QDebug dump(QDebug ts) const
{
return ts << m_key << '-' << m_modifiers << '-'
......@@ -849,92 +948,6 @@ private:
bool m_silent;
};
static QMap<QString, int> vimKeyNames()
{
QMap<QString, int> k;
// FIXME: Should be value of mapleader.
k.insert("LEADER", Key_Backslash);
k.insert("SPACE", Key_Space);
k.insert("TAB", Key_Tab);
k.insert("NL", Key_Return);
k.insert("NEWLINE", Key_Return);
k.insert("LINEFEED", Key_Return);
k.insert("LF", Key_Return);
k.insert("CR", Key_Return);
k.insert("RETURN", Key_Return);
k.insert("ENTER", Key_Return);
k.insert("BS", Key_Backspace);
k.insert("BACKSPACE", Key_Backspace);
k.insert("ESC", Key_Escape);
k.insert("BAR", Key_Bar);
k.insert("BSLASH", Key_Backslash);
k.insert("DEL", Key_Delete);
k.insert("DELETE", Key_Delete);
k.insert("KDEL", Key_Delete);
k.insert("UP", Key_Up);
k.insert("DOWN", Key_Down);
k.insert("LEFT", Key_Left);
k.insert("RIGHT", Key_Right);
k.insert("F1", Key_F1);
k.insert("F2", Key_F2);
k.insert("F3", Key_F3);
k.insert("F4", Key_F4);
k.insert("F5", Key_F5);
k.insert("F6", Key_F6);
k.insert("F7", Key_F7);
k.insert("F8", Key_F8);
k.insert("F9", Key_F9);
k.insert("F10", Key_F10);
k.insert("F11", Key_F11);
k.insert("F12", Key_F12);
k.insert("F13", Key_F13);
k.insert("F14", Key_F14);
k.insert("F15", Key_F15);
k.insert("F16", Key_F16);
k.insert("F17", Key_F17);
k.insert("F18", Key_F18);
k.insert("F19", Key_F19);
k.insert("F20", Key_F20);
k.insert("F21", Key_F21);
k.insert("F22", Key_F22);
k.insert("F23", Key_F23);
k.insert("F24", Key_F24);
k.insert("F25", Key_F25);
k.insert("F26", Key_F26);
k.insert("F27", Key_F27);
k.insert("F28", Key_F28);
k.insert("F29", Key_F29);
k.insert("F30", Key_F30);
k.insert("F31", Key_F31);
k.insert("F32", Key_F32);
k.insert("F33", Key_F33);
k.insert("F34", Key_F34);
k.insert("F35", Key_F35);
k.insert("INSERT", Key_Insert);
k.insert("INS", Key_Insert);
k.insert("KINSERT", Key_Insert);
k.insert("HOME", Key_Home);
k.insert("END", Key_End);
k.insert("PAGEUP", Key_PageUp);
k.insert("PAGEDOWN", Key_PageDown);
k.insert("KPLUS", Key_Plus);
k.insert("KMINUS", Key_Minus);
k.insert("KDIVIDE", Key_Slash);
k.insert("KMULTIPLY", Key_Asterisk);
k.insert("KENTER", Key_Enter);
k.insert("KPOINT", Key_Period);
return k;
}
static Input parseVimKeyName(const QString &keyName)
{
if (keyName.length() == 1)
......@@ -966,9 +979,8 @@ static Input parseVimKeyName(const QString &keyName)
}
// find key name
static const QMap<QString, int> k = vimKeyNames();
QMap<QString, int>::ConstIterator it = k.constFind(key.toUpper());
if (it != k.end())
QMap<QString, int>::ConstIterator it = vimKeyNames().constFind(key.toUpper());
if (it != vimKeyNames().end())
return Input(*it, mods);
}
......@@ -1751,6 +1763,7 @@ public:
// Current mini buffer message.
QString currentMessage;
MessageLevel currentMessageLevel;
QString currentCommand;
// Search state.
QString lastSearch;
......@@ -1828,8 +1841,7 @@ bool FakeVimHandler::Private::wantsOverride(QKeyEvent *ev)
if (isNoVisualMode()
&& m_mode == CommandMode
&& m_submode == NoSubMode
&& m_opcount.isEmpty()
&& m_mvcount.isEmpty())
&& g.currentCommand.isEmpty())
return false;
return true;
}
......@@ -2141,6 +2153,8 @@ EventResult FakeVimHandler::Private::handleKey(const Input &input)
// if the mapped input can be completed complete.
if (hasInput && g.currentMap.walk(input)) {
if (g.currentMap.canExtend()) {
g.currentCommand.append(input.toString());
updateMiniBuffer();
g.inputTimer = startTimer(1000);
return EventHandled;
} else {
......@@ -2153,6 +2167,8 @@ EventResult FakeVimHandler::Private::handleKey(const Input &input)
g.currentMap.reset();
handleMapped = false;
}
g.currentCommand.clear();
updateMiniBuffer();
}
EventResult r = EventUnhandled;
......@@ -2174,6 +2190,8 @@ EventResult FakeVimHandler::Private::handleKey(const Input &input)
// handle user mapping
if (g.currentMap.canExtend()) {
g.currentCommand.append(in.toString());
updateMiniBuffer();
// wait for user to press any key or trigger complete mapping after interval
g.inputTimer = startTimer(1000);
return EventHandled;
......@@ -2496,7 +2514,6 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement)
int endLine = lineForPosition(position());
setPosition(qMin(anchor(), position()));
enterExMode(QString(".,+%1!").arg(qAbs(endLine - beginLine)));
updateMiniBuffer();
return;
}
......@@ -2600,6 +2617,7 @@ void FakeVimHandler::Private::resetCommandMode()
m_rangemode = RangeCharMode;
if (isNoVisualMode())
setAnchor();
g.currentCommand.clear();
}
void FakeVimHandler::Private::updateSelection()
......@@ -2658,6 +2676,9 @@ void FakeVimHandler::Private::updateMiniBuffer()
} else if (g.mapStates.size() > 1 && !g.mapStates.last().silent) {
// Do not reset previous message when after running a mapped command.
return;
} else if (m_mode == CommandMode && !g.currentCommand.isEmpty() && hasConfig(ConfigShowCmd)) {
msg = g.currentCommand;
messageLevel = MessageShowCmd;
} else if (m_mode == CommandMode && isVisualMode()) {
if (isVisualCharMode()) {
msg = "VISUAL";
......@@ -2696,14 +2717,12 @@ void FakeVimHandler::Private::showMessage(MessageLevel level, const QString &msg
//qDebug() << "MSG: " << msg;
g.currentMessage = msg;
g.currentMessageLevel = level;
updateMiniBuffer();
}
void FakeVimHandler::Private::notImplementedYet()
{
qDebug() << "Not implemented in FakeVim";
showMessage(MessageError, FakeVimHandler::tr("Not implemented in FakeVim"));
updateMiniBuffer();
}
void FakeVimHandler::Private::passShortcuts(bool enable)
......@@ -2868,7 +2887,6 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
m_searchFromScreenLine = firstVisibleLine();
m_searchCursor = QTextCursor();
g.searchBuffer.clear();
updateMiniBuffer();
}
} else if (input.is('`')) {
m_subsubmode = BackTickSubSubMode;
......@@ -3156,7 +3174,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
handled = handleChangeCaseSubMode(input);
}
// Clear state if necessary.
// Clear state and display incomplete command if necessary.
if (handled) {
bool noMode =
(m_mode == CommandMode && m_submode == NoSubMode && m_subsubmode == NoSubSubMode);
......@@ -3172,6 +3190,11 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
m_mvcount.clear();
m_opcount.clear();
}
// Show or clear current command on minibuffer (showcmd).
if (input.isEscape() || m_mode != CommandMode || clearCount)
g.currentCommand.clear();
else
g.currentCommand.append(input.toString());
}
} else {
resetCommandMode();
......@@ -3185,6 +3208,8 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
}
}
updateMiniBuffer();
m_positionPastEnd = (m_visualTargetColumn == -1) && isVisualMode();
return handled ? EventHandled : EventCancelled;
......@@ -3195,7 +3220,6 @@ bool FakeVimHandler::Private::handleEscape()
if (isVisualMode())
leaveVisualMode();
resetCommandMode();
updateMiniBuffer();
return true;
}
......@@ -3207,12 +3231,10 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
handleExCommand(m_gflag ? "%s//~/&" : "s");
} else if (input.is(':')) {
enterExMode();
updateMiniBuffer();
} else if (input.is('!') && isNoVisualMode()) {
m_submode = FilterSubMode;
} else if (input.is('!') && isVisualMode()) {
enterExMode(QString("!"));
updateMiniBuffer();
} else if (input.is('"')) {
m_submode = RegisterSubMode;
} else if (input.is(',')) {
......@@ -3257,7 +3279,6 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
if (!atEndOfLine())
moveRight();
setUndoPosition();
updateMiniBuffer();
} else if (input.is('A')) {
breakEditBlock();
moveBehindEndOfLine();
......@@ -3266,7 +3287,6 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
enterInsertMode();
setDotCommand("%1A", count());
m_lastInsertion.clear();
updateMiniBuffer();
} else if (input.isControl('a')) {
changeNumberTextObject(count());
setDotCommand("%1<c-a>", count());
......@@ -3360,7 +3380,6 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
setDotCommand("%1i", count());
breakEditBlock();
enterInsertMode();
updateMiniBuffer();
if (atEndOfLine())
moveLeft();
} else if (input.is('I')) {
......@@ -3430,7 +3449,6 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
setUndoPosition();
breakEditBlock();
enterReplaceMode();
updateMiniBuffer();
} else if (input.isControl('r')) {
int repeat = count();
while (--repeat >= 0)
......
......@@ -82,7 +82,8 @@ enum MessageLevel
MessageCommand, // show last Ex command or search
MessageInfo, // result of a command
MessageWarning, // warning
MessageError // error
MessageError, // error
MessageShowCmd // partial command
};
class FakeVimHandler : public QObject
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>513</width>
<height>449</height>
<height>461</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -31,69 +31,6 @@
<string>Vim Behavior</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
<string>Automatic indentation</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBoxStartOfLine">
<property name="text">
<string>Start of line</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartIndent">
<property name="text">
<string>Smart indentation</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="checkBoxUseCoreSearch">
<property name="text">
<string>Use search dialog</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="checkBoxSmartCase">
<property name="text">
<string>Use smartcase</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QCheckBox" name="checkBoxWrapScan">
<property name="text">
<string>Use wrapscan</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxExpandTab">
<property name="text">
<string>Expand tabulators</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="checkBoxShowMarks">
<property name="text">
<string>Show position of text marks</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartTab">
<property name="text">
<string>Smart tabulators</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QCheckBox" name="checkBoxPassControlKey">
<property name="toolTip">
......@@ -118,17 +55,31 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelShiftWidth">
<item row="0" column="2">
<widget class="QCheckBox" name="checkBoxStartOfLine">
<property name="text">
<string>Shift width:</string>
<string>Start of line</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartIndent">
<property name="text">
<string>Smart indentation</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
<string>Automatic indentation</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSpinBox" name="spinBoxShiftWidth">
<widget class="QSpinBox" name="spinBoxTabStop">
<property name="minimum">
<number>1</number>
</property>
......@@ -138,7 +89,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......@@ -152,7 +103,24 @@
</item>
</layout>
</item>
<item row="7" column="0">
<item row="9" column="0">
<widget class="QLabel" name="labelBackspace">
<property name="text">
<string>Backspace:</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QLineEdit" name="lineEditBackspace"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelIsKeyword">
<property name="text">
<string>Keyword characters:</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelTabulator">
<property name="toolTip">
<string>Vim tabstop option</string>
......@@ -162,20 +130,31 @@
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item row="12" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="spinBoxTabStop">
<property name="minimum">
<number>1</number>
<widget class="QPushButton" name="pushButtonCopyTextEditorSettings">
<property name="text">
<string>Copy Text Editor Settings</string>
</property>
<property name="maximum">
<number>80</number>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSetQtStyle">
<property name="text">
<string>Set Qt Style</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<widget class="QPushButton" name="pushButtonSetPlainStyle">
<property name="text">
<string>Set Plain Style</string>
</property>
</widget>
</item>
<item>