Fixes: fakevim: show column/line information in standalone application

This commit is contained in:
hjk
2009-01-27 14:08:17 +01:00
parent ac8ed036d5
commit 9d8fc28706
2 changed files with 45 additions and 21 deletions

View File

@@ -893,6 +893,13 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
moveDown(qMax(count() - 1, 0)); moveDown(qMax(count() - 1, 0));
moveRight(rightDist()); moveRight(rightDist());
finishMovement(); finishMovement();
} else if (key == control('d')) {
int sline = cursorLineOnScreen();
// FIXME: this should use the "scroll" option, and "count"
moveDown(linesOnScreen() / 2);
moveToFirstNonBlankOnLine();
scrollToLineInDocument(cursorLineInDocument() - sline);
finishMovement();
} else if (key == 'e') { } else if (key == 'e') {
m_moveType = MoveInclusive; m_moveType = MoveInclusive;
moveToWordBoundary(false, true); moveToWordBoundary(false, true);
@@ -1068,6 +1075,13 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
// FIXME: this is non-vim, but as Ctrl-R is taken globally // FIXME: this is non-vim, but as Ctrl-R is taken globally
// we have a substitute here // we have a substitute here
redo(); redo();
} else if (key == control('u')) {
int sline = cursorLineOnScreen();
// FIXME: this should use the "scroll" option, and "count"
moveUp(linesOnScreen() / 2);
moveToFirstNonBlankOnLine();
scrollToLineInDocument(cursorLineInDocument() - sline);
finishMovement();
} else if (key == 'v') { } else if (key == 'v') {
enterVisualMode(VisualCharMode); enterVisualMode(VisualCharMode);
} else if (key == 'V') { } else if (key == 'V') {
@@ -1137,20 +1151,6 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
} }
recordInsertText(str); recordInsertText(str);
recordEndGroup(); recordEndGroup();
} else if (key == control('d')) {
int sline = cursorLineOnScreen();
// FIXME: this should use the "scroll" option, and "count"
moveDown(linesOnScreen() / 2);
moveToFirstNonBlankOnLine();
scrollToLineInDocument(cursorLineInDocument() - sline);
finishMovement();
} else if (key == control('u')) {
int sline = cursorLineOnScreen();
// FIXME: this should use the "scroll" option, and "count"
moveUp(linesOnScreen() / 2);
moveToFirstNonBlankOnLine();
scrollToLineInDocument(cursorLineInDocument() - sline);
finishMovement();
} else if (key == Key_PageDown || key == control('f')) { } else if (key == Key_PageDown || key == control('f')) {
moveDown(count() * (linesOnScreen() - 2)); moveDown(count() * (linesOnScreen() - 2));
finishMovement(); finishMovement();
@@ -1588,6 +1588,7 @@ void FakeVimHandler::Private::search(const QString &needle0, bool forward)
if (EDITOR(find(needle, flags))) { if (EDITOR(find(needle, flags))) {
m_tc = EDITOR(textCursor()); m_tc = EDITOR(textCursor());
m_tc.setPosition(m_tc.anchor()); m_tc.setPosition(m_tc.anchor());
// making this unconditional feels better, but is not "vim like"
if (oldLine != cursorLineInDocument() - cursorLineOnScreen()) if (oldLine != cursorLineInDocument() - cursorLineOnScreen())
scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() / 2); scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() / 2);
return; return;

View File

@@ -17,8 +17,8 @@ class Proxy : public QObject
Q_OBJECT Q_OBJECT
public: public:
Proxy(QWidget *widget, QObject *parent = 0) Proxy(QWidget *widget, QMainWindow *mw, QObject *parent = 0)
: QObject(parent), m_widget(widget) : QObject(parent), m_widget(widget), m_mainWindow(mw)
{} {}
public slots: public slots:
@@ -30,13 +30,35 @@ public slots:
ed->setExtraSelections(s); ed->setExtraSelections(s);
} }
void changeStatusData(const QString &info)
{
m_statusData = info;
updateStatusBar();
}
void changeStatusMessage(const QString &info)
{
m_statusMessage = info;
updateStatusBar();
}
void changeExtraInformation(const QString &info) void changeExtraInformation(const QString &info)
{ {
QMessageBox::information(m_widget, "Information", info); QMessageBox::information(m_widget, "Information", info);
} }
void updateStatusBar()
{
int slack = 80 - m_statusMessage.size() - m_statusData.size();
QString msg = m_statusMessage + QString(slack, QChar(' ')) + m_statusData;
m_mainWindow->statusBar()->showMessage(msg);
}
private: private:
QWidget *m_widget; QWidget *m_widget;
QMainWindow *m_mainWindow;
QString m_statusMessage;
QString m_statusData;
}; };
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@@ -64,11 +86,11 @@ int main(int argc, char *argv[])
//widget->resize(450, 350); //widget->resize(450, 350);
widget->setFocus(); widget->setFocus();
Proxy proxy(widget); QMainWindow mw;
Proxy proxy(widget, &mw);
FakeVimHandler handler(widget, 0); FakeVimHandler handler(widget, 0);
QMainWindow mw;
mw.setWindowTitle("Fakevim (" + title + ")"); mw.setWindowTitle("Fakevim (" + title + ")");
mw.setCentralWidget(widget); mw.setCentralWidget(widget);
mw.resize(600, 650); mw.resize(600, 650);
@@ -85,15 +107,16 @@ int main(int argc, char *argv[])
mw.statusBar()->setFont(font); mw.statusBar()->setFont(font);
QObject::connect(&handler, SIGNAL(commandBufferChanged(QString)), QObject::connect(&handler, SIGNAL(commandBufferChanged(QString)),
mw.statusBar(), SLOT(showMessage(QString))); &proxy, SLOT(changeStatusMessage(QString)));
QObject::connect(&handler, SIGNAL(quitRequested()), QObject::connect(&handler, SIGNAL(quitRequested()),
&app, SLOT(quit())); &app, SLOT(quit()));
QObject::connect(&handler, QObject::connect(&handler,
SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)),
&proxy, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>))); &proxy, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
QObject::connect(&handler, QObject::connect(&handler, SIGNAL(extraInformationChanged(QString)),
SIGNAL(extraInformationChanged(QString)),
&proxy, SLOT(changeExtraInformation(QString))); &proxy, SLOT(changeExtraInformation(QString)));
QObject::connect(&handler, SIGNAL(statusDataChanged(QString)),
&proxy, SLOT(changeStatusData(QString)));
handler.setupWidget(); handler.setupWidget();
if (args.size() >= 1) if (args.size() >= 1)