mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
vim-mode: scroll to center after Ctrl+O/I
This commit is contained in:
parent
91d33c3f5c
commit
7c2f1a8927
@ -4410,6 +4410,11 @@ void VVim::processJumpLocationAction(QList<Token> &p_tokens, bool p_next)
|
||||
pib = block.length() - 1;
|
||||
}
|
||||
|
||||
if (!m_editor->isBlockVisible(block)) {
|
||||
// Scroll the block to the center of screen.
|
||||
VEditUtils::scrollBlockInPage(m_editor, block.blockNumber(), 1);
|
||||
}
|
||||
|
||||
cursor.setPosition(block.position() + pib);
|
||||
m_editor->setTextCursor(cursor);
|
||||
}
|
||||
|
@ -1230,3 +1230,29 @@ void VEdit::makeBlockVisible(const QTextBlock &p_block)
|
||||
qDebug() << "scroll page up to make block visible";
|
||||
}
|
||||
}
|
||||
|
||||
bool VEdit::isBlockVisible(const QTextBlock &p_block)
|
||||
{
|
||||
if (!p_block.isValid() || !p_block.isVisible()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QScrollBar *vbar = verticalScrollBar();
|
||||
if (!vbar || !vbar->isVisible()) {
|
||||
// No vertical scrollbar.
|
||||
return true;
|
||||
}
|
||||
|
||||
QAbstractTextDocumentLayout *layout = document()->documentLayout();
|
||||
int height = rect().height();
|
||||
QScrollBar *hbar = horizontalScrollBar();
|
||||
if (hbar && hbar->isVisible()) {
|
||||
height -= hbar->height();
|
||||
}
|
||||
|
||||
QRectF rect = layout->blockBoundingRect(p_block);
|
||||
int y = contentOffsetY() + (int)rect.y();
|
||||
int rectHeight = (int)rect.height();
|
||||
|
||||
return (y >= 0 && y < height) || (y < 0 && y + rectHeight > 0);
|
||||
}
|
||||
|
@ -129,6 +129,8 @@ public:
|
||||
// Will not change current cursor.
|
||||
void makeBlockVisible(const QTextBlock &p_block);
|
||||
|
||||
bool isBlockVisible(const QTextBlock &p_block);
|
||||
|
||||
signals:
|
||||
// Request VEditTab to save and exit edit mode.
|
||||
void saveAndRead();
|
||||
|
Loading…
x
Reference in New Issue
Block a user