Commit 04731b79 authored by hjk's avatar hjk
Browse files

fakevim: implement Ctrl-e

parent f7240bd6
...@@ -250,6 +250,8 @@ private: ...@@ -250,6 +250,8 @@ private:
int cursorColumnInDocument() const; int cursorColumnInDocument() const;
int linesInDocument() const; int linesInDocument() const;
void scrollToLineInDocument(int line); void scrollToLineInDocument(int line);
void scrollUp(int count);
void scrollDown(int count) { scrollUp(-count); }
// helper functions for indenting // helper functions for indenting
bool isElectricCharacter(QChar c) const bool isElectricCharacter(QChar c) const
...@@ -531,7 +533,7 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev) ...@@ -531,7 +533,7 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
moveLeft(); moveLeft();
EDITOR(setTextCursor(m_tc)); EDITOR(setTextCursor(m_tc));
EDITOR(ensureCursorVisible()); //EDITOR(ensureCursorVisible());
return result; return result;
} }
...@@ -856,21 +858,21 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified, ...@@ -856,21 +858,21 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
if (key == Key_Return || key == 't') { // cursor line to top of window if (key == Key_Return || key == 't') { // cursor line to top of window
if (!m_mvcount.isEmpty()) if (!m_mvcount.isEmpty())
setPosition(firstPositionInLine(count())); setPosition(firstPositionInLine(count()));
scrollToLineInDocument(cursorLineInDocument()); scrollUp(- cursorLineOnScreen());
if (key == Key_Return) if (key == Key_Return)
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
finishMovement(); finishMovement();
} else if (key == '.' || key == 'z') { // cursor line to center of window } else if (key == '.' || key == 'z') { // cursor line to center of window
if (!m_mvcount.isEmpty()) if (!m_mvcount.isEmpty())
setPosition(firstPositionInLine(count())); setPosition(firstPositionInLine(count()));
scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() / 2); scrollUp(linesOnScreen() / 2 - cursorLineOnScreen());
if (key == '.') if (key == '.')
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
finishMovement(); finishMovement();
} else if (key == '-' || key == 'b') { // cursor line to bottom of window } else if (key == '-' || key == 'b') { // cursor line to bottom of window
if (!m_mvcount.isEmpty()) if (!m_mvcount.isEmpty())
setPosition(firstPositionInLine(count())); setPosition(firstPositionInLine(count()));
scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() - 1); scrollUp(linesOnScreen() - cursorLineOnScreen());
if (key == '-') if (key == '-')
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
finishMovement(); finishMovement();
...@@ -1110,6 +1112,12 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified, ...@@ -1110,6 +1112,12 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
m_moveType = MoveInclusive; m_moveType = MoveInclusive;
moveToWordBoundary(true, true); moveToWordBoundary(true, true);
finishMovement(); finishMovement();
} else if (key == control('e')) {
// FIXME: this should use the "scroll" option, and "count"
if (cursorLineOnScreen() == 0)
moveDown(1);
scrollDown(1);
finishMovement();
} else if (key == 'f') { } else if (key == 'f') {
m_subsubmode = FtSubSubMode; m_subsubmode = FtSubSubMode;
m_moveType = MoveInclusive; m_moveType = MoveInclusive;
...@@ -2154,9 +2162,15 @@ void FakeVimHandler::Private::scrollToLineInDocument(int line) ...@@ -2154,9 +2162,15 @@ void FakeVimHandler::Private::scrollToLineInDocument(int line)
{ {
// FIXME: works only for QPlainTextEdit // FIXME: works only for QPlainTextEdit
QScrollBar *scrollBar = EDITOR(verticalScrollBar()); QScrollBar *scrollBar = EDITOR(verticalScrollBar());
//qDebug() << "SCROLL: " << scrollBar->value() << line;
scrollBar->setValue(line); scrollBar->setValue(line);
} }
void FakeVimHandler::Private::scrollUp(int count)
{
scrollToLineInDocument(cursorLineInDocument() - cursorLineOnScreen() - count);
}
int FakeVimHandler::Private::lastPositionInDocument() const int FakeVimHandler::Private::lastPositionInDocument() const
{ {
QTextBlock block = m_tc.block().document()->lastBlock(); QTextBlock block = m_tc.block().document()->lastBlock();
......
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