forked from qt-creator/qt-creator
FakeVim: Use current text cursor to find out line geometry
Change-Id: If4581d2f38db8311138b871b67fdbe164dde1688 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -1576,7 +1576,6 @@ public:
|
|||||||
QTextBlock previousLine(const QTextBlock &block) const; // previous line (respects wrapped parts)
|
QTextBlock previousLine(const QTextBlock &block) const; // previous line (respects wrapped parts)
|
||||||
|
|
||||||
int linesOnScreen() const;
|
int linesOnScreen() const;
|
||||||
int columnsOnScreen() const;
|
|
||||||
int linesInDocument() const;
|
int linesInDocument() const;
|
||||||
|
|
||||||
// The following use all zero-based counting.
|
// The following use all zero-based counting.
|
||||||
@@ -3673,9 +3672,12 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
|
|||||||
setCursorPosition(&m_cursor, pos);
|
setCursorPosition(&m_cursor, pos);
|
||||||
handleStartOfLine();
|
handleStartOfLine();
|
||||||
} else if (g.gflag && input.is('m')) {
|
} else if (g.gflag && input.is('m')) {
|
||||||
moveToStartOfLine();
|
const QPoint pos(EDITOR(viewport()->width()) / 2, EDITOR(cursorRect(m_cursor)).y());
|
||||||
moveRight(qMin(columnsOnScreen() / 2, rightDist()) - 1);
|
QTextCursor tc = EDITOR(cursorForPosition(pos));
|
||||||
setTargetColumn();
|
if (!tc.isNull()) {
|
||||||
|
m_cursor = tc;
|
||||||
|
setTargetColumn();
|
||||||
|
}
|
||||||
} else if (input.is('M')) {
|
} else if (input.is('M')) {
|
||||||
m_cursor = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
|
m_cursor = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
|
||||||
handleStartOfLine();
|
handleStartOfLine();
|
||||||
@@ -6369,25 +6371,16 @@ int FakeVimHandler::Private::cursorLineOnScreen() const
|
|||||||
{
|
{
|
||||||
if (!editor())
|
if (!editor())
|
||||||
return 0;
|
return 0;
|
||||||
QRect rect = EDITOR(cursorRect());
|
const QRect rect = EDITOR(cursorRect(m_cursor));
|
||||||
return rect.y() / rect.height();
|
return rect.height() > 0 ? rect.y() / rect.height() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FakeVimHandler::Private::linesOnScreen() const
|
int FakeVimHandler::Private::linesOnScreen() const
|
||||||
{
|
{
|
||||||
if (!editor())
|
if (!editor())
|
||||||
return 1;
|
return 1;
|
||||||
QRect rect = EDITOR(cursorRect());
|
const int h = EDITOR(cursorRect(m_cursor)).height();
|
||||||
return EDITOR(viewport()->height()) / rect.height();
|
return h > 0 ? EDITOR(viewport()->height()) / h : 1;
|
||||||
}
|
|
||||||
|
|
||||||
int FakeVimHandler::Private::columnsOnScreen() const
|
|
||||||
{
|
|
||||||
if (!editor())
|
|
||||||
return 1;
|
|
||||||
QRect rect = EDITOR(cursorRect());
|
|
||||||
// qDebug() << "WID: " << EDITOR(width()) << "RECT: " << rect;
|
|
||||||
return EDITOR(viewport()->width()) / rect.width();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FakeVimHandler::Private::cursorLine() const
|
int FakeVimHandler::Private::cursorLine() const
|
||||||
|
|||||||
Reference in New Issue
Block a user