Commit 2377567f authored by hjk's avatar hjk Committed by Roberto Raggi
Browse files

basic mark handling (setting, jumping to)

parent 6d03617c
...@@ -93,7 +93,10 @@ enum SubMode ...@@ -93,7 +93,10 @@ enum SubMode
enum SubSubMode enum SubSubMode
{ {
NoSubSubMode, NoSubSubMode,
FtSubSubMode, // used for f, F, t, T FtSubSubMode, // used for f, F, t, T
MarkSubSubMode, // used for m
BackTickSubSubMode, // used for `
TickSubSubMode // used for '
}; };
static const QString ConfigStartOfLine = "startofline"; static const QString ConfigStartOfLine = "startofline";
...@@ -187,6 +190,9 @@ public: ...@@ -187,6 +190,9 @@ public:
QStringList m_commandHistory; QStringList m_commandHistory;
int m_commandHistoryIndex; int m_commandHistoryIndex;
// marks as lines
QHash<int, int> m_marks;
// vi style configuration // vi style configuration
QHash<QString, QString> m_config; QHash<QString, QString> m_config;
}; };
...@@ -348,6 +354,20 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text) ...@@ -348,6 +354,20 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
handleFfTt(key); handleFfTt(key);
m_subsubmode = NoSubSubMode; m_subsubmode = NoSubSubMode;
finishMovement(); finishMovement();
} else if (m_subsubmode == MarkSubSubMode) {
m_marks[key] = m_tc.position();
m_subsubmode = NoSubSubMode;
} else if (m_subsubmode == BackTickSubSubMode
|| m_subsubmode == TickSubSubMode) {
if (m_marks.contains(key)) {
m_tc.setPosition(m_marks[key]);
if (m_subsubmode == TickSubSubMode)
moveToFirstNonBlankOnLine();
finishMovement();
} else {
showMessage(tr("E20: Mark '%1' not set").arg(text));
}
m_subsubmode = NoSubSubMode;
} else if (key >= '0' && key <= '9') { } else if (key >= '0' && key <= '9') {
if (key == '0' && m_mvcount.isEmpty()) { if (key == '0' && m_mvcount.isEmpty()) {
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
...@@ -366,6 +386,10 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text) ...@@ -366,6 +386,10 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
m_commandHistoryIndex = m_commandHistory.size() - 1; m_commandHistoryIndex = m_commandHistory.size() - 1;
} }
updateMiniBuffer(); updateMiniBuffer();
} else if (key == '`') {
m_subsubmode = BackTickSubSubMode;
} else if (key == '\'') {
m_subsubmode = TickSubSubMode;
} else if (key == '|') { } else if (key == '|') {
m_tc.movePosition(StartOfLine, KeepAnchor); m_tc.movePosition(StartOfLine, KeepAnchor);
m_tc.movePosition(Right, KeepAnchor, qMin(count(), rightDist()) - 1); m_tc.movePosition(Right, KeepAnchor, qMin(count(), rightDist()) - 1);
...@@ -484,6 +508,8 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text) ...@@ -484,6 +508,8 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
m_tc.movePosition(Up, KeepAnchor, qMax(count(), 1)); m_tc.movePosition(Up, KeepAnchor, qMax(count(), 1));
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
finishMovement(); finishMovement();
} else if (key == 'm') {
m_subsubmode = MarkSubSubMode;
} else if (key == 'M') { } else if (key == 'M') {
m_tc = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2))); m_tc = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
...@@ -657,6 +683,8 @@ void FakeVimHandler::Private::handleExMode(int key, const QString &text) ...@@ -657,6 +683,8 @@ void FakeVimHandler::Private::handleExMode(int key, const QString &text)
m_mode = CommandMode; m_mode = CommandMode;
updateMiniBuffer(); updateMiniBuffer();
} else if (key == Key_Up && isSearchCommand()) { } else if (key == Key_Up && isSearchCommand()) {
// FIXME: This and the three cases below are wrong as vim
// takes only matching entires in the history into account.
if (m_searchHistoryIndex > 0) { if (m_searchHistoryIndex > 0) {
--m_searchHistoryIndex; --m_searchHistoryIndex;
m_commandBuffer = m_searchHistory.at(m_searchHistoryIndex); m_commandBuffer = m_searchHistory.at(m_searchHistoryIndex);
......
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