fakevim: consolidate cursor display handling

This commit is contained in:
hjk
2010-05-04 11:00:40 +02:00
parent 15a595b429
commit db355834de

View File

@@ -342,6 +342,11 @@ private:
QString m_text; QString m_text;
}; };
QDebug &operator<<(QDebug &ts, const Input &input)
{
return ts << input.text() << input.key();
}
typedef QVector<Input> Inputs; typedef QVector<Input> Inputs;
// Mappings for a specific mode. // Mappings for a specific mode.
@@ -527,6 +532,7 @@ public:
void notImplementedYet(); void notImplementedYet();
void updateMiniBuffer(); void updateMiniBuffer();
void updateSelection(); void updateSelection();
void updateCursor();
QWidget *editor() const; QWidget *editor() const;
QChar characterAtCursor() const QChar characterAtCursor() const
{ return m_tc.document()->characterAt(m_tc.position()); } { return m_tc.document()->characterAt(m_tc.position()); }
@@ -883,14 +889,12 @@ void FakeVimHandler::Private::installEventFilter()
void FakeVimHandler::Private::setupWidget() void FakeVimHandler::Private::setupWidget()
{ {
enterCommandMode(); enterCommandMode();
//EDITOR(setCursorWidth(QFontMetrics(ed->font()).width(QChar('x')));
if (m_textedit) { if (m_textedit) {
m_textedit->setLineWrapMode(QTextEdit::NoWrap); m_textedit->setLineWrapMode(QTextEdit::NoWrap);
} else if (m_plaintextedit) { } else if (m_plaintextedit) {
m_plaintextedit->setLineWrapMode(QPlainTextEdit::NoWrap); m_plaintextedit->setLineWrapMode(QPlainTextEdit::NoWrap);
} }
m_wasReadOnly = EDITOR(isReadOnly()); m_wasReadOnly = EDITOR(isReadOnly());
//EDITOR(setReadOnly(true));
updateEditor(); updateEditor();
@@ -909,6 +913,7 @@ void FakeVimHandler::Private::setupWidget()
} }
updateMiniBuffer(); updateMiniBuffer();
updateCursor();
} }
void FakeVimHandler::Private::updateEditor() void FakeVimHandler::Private::updateEditor()
@@ -924,9 +929,7 @@ void FakeVimHandler::Private::restoreWidget(int tabSize)
//showBlackMessage(QString()); //showBlackMessage(QString());
//updateMiniBuffer(); //updateMiniBuffer();
//EDITOR(removeEventFilter(q)); //EDITOR(removeEventFilter(q));
EDITOR(setReadOnly(m_wasReadOnly)); //EDITOR(setReadOnly(m_wasReadOnly));
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(false));
const int charWidth = QFontMetrics(EDITOR(font())).width(QChar(' ')); const int charWidth = QFontMetrics(EDITOR(font())).width(QChar(' '));
EDITOR(setTabStopWidth(charWidth * tabSize)); EDITOR(setTabStopWidth(charWidth * tabSize));
@@ -945,6 +948,11 @@ void FakeVimHandler::Private::restoreWidget(int tabSize)
} }
m_visualMode = NoVisualMode; m_visualMode = NoVisualMode;
// Force "ordinary" cursor.
m_mode = InsertMode;
m_submode = NoSubMode;
m_subsubmode = NoSubSubMode;
updateCursor();
updateSelection(); updateSelection();
} }
@@ -1088,6 +1096,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
m_commandHistory.append(QString()); m_commandHistory.append(QString());
m_commandHistoryIndex = m_commandHistory.size() - 1; m_commandHistoryIndex = m_commandHistory.size() - 1;
updateMiniBuffer(); updateMiniBuffer();
updateCursor();
return; return;
} }
@@ -1215,6 +1224,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
} }
resetCommandMode(); resetCommandMode();
updateCursor();
} }
void FakeVimHandler::Private::resetCommandMode() void FakeVimHandler::Private::resetCommandMode()
@@ -2021,9 +2031,9 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
// FIXME: right now we repeat the insertion count() times, // FIXME: right now we repeat the insertion count() times,
// but not the deletion // but not the deletion
m_lastInsertion.clear(); m_lastInsertion.clear();
enterInsertMode();
m_submode = ReplaceSubMode; m_submode = ReplaceSubMode;
setDotCommand(QString(QLatin1Char('R'))); setDotCommand(QString(QLatin1Char('R')));
enterInsertMode();
updateMiniBuffer(); updateMiniBuffer();
} else if (input.isControl('r')) { } else if (input.isControl('r')) {
redo(); redo();
@@ -2283,15 +2293,11 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
enterCommandMode(); enterCommandMode();
m_submode = NoSubMode; m_submode = NoSubMode;
} else if (input.isKey(Key_Insert)) { } else if (input.isKey(Key_Insert)) {
if (m_submode == ReplaceSubMode) { if (m_submode == ReplaceSubMode)
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(false));
m_submode = NoSubMode; m_submode = NoSubMode;
} else { else
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(true));
m_submode = ReplaceSubMode; m_submode = ReplaceSubMode;
} updateCursor();
} else if (input.isKey(Key_Left)) { } else if (input.isKey(Key_Left)) {
moveLeft(count()); moveLeft(count());
setTargetColumn(); setTargetColumn();
@@ -4043,30 +4049,42 @@ void FakeVimHandler::Private::redo()
m_tc.setPosition(m_undoCursorPosition[rev]); m_tc.setPosition(m_undoCursorPosition[rev]);
} }
void FakeVimHandler::Private::updateCursor()
{
if (m_mode == ExMode) {
EDITOR(setCursorWidth(0));
EDITOR(setOverwriteMode(false));
} else if (m_mode == InsertMode || m_submode == ReplaceSubMode) {
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(false));
} else {
// "ordinary" CommandMode
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(true));
}
}
void FakeVimHandler::Private::enterInsertMode() void FakeVimHandler::Private::enterInsertMode()
{ {
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(false));
//leaveVisualMode(); //leaveVisualMode();
m_mode = InsertMode; m_mode = InsertMode;
m_lastInsertion.clear(); m_lastInsertion.clear();
m_beginEditBlock = true; m_beginEditBlock = true;
updateCursor();
} }
void FakeVimHandler::Private::enterCommandMode() void FakeVimHandler::Private::enterCommandMode()
{ {
EDITOR(setCursorWidth(m_cursorWidth));
EDITOR(setOverwriteMode(true));
if (atEndOfLine()) if (atEndOfLine())
moveLeft(); moveLeft();
m_mode = CommandMode; m_mode = CommandMode;
updateCursor();
} }
void FakeVimHandler::Private::enterExMode() void FakeVimHandler::Private::enterExMode()
{ {
EDITOR(setCursorWidth(0));
EDITOR(setOverwriteMode(false));
m_mode = ExMode; m_mode = ExMode;
updateCursor();
} }
void FakeVimHandler::Private::recordJump() void FakeVimHandler::Private::recordJump()