From 443ee772a786f03a46735cfcfa663a9b27a5ad31 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 3 Jun 2017 15:55:00 +0800 Subject: [PATCH] make cursor visible after highlight completed Highlight may turn originlly visible cursor partially visible. We make it visible in this case. --- src/vmdedit.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/vmdedit.cpp b/src/vmdedit.cpp index f52e9a77..0b41574e 100644 --- a/src/vmdedit.cpp +++ b/src/vmdedit.cpp @@ -26,6 +26,19 @@ VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type, connect(m_mdHighlighter, &HGMarkdownHighlighter::highlightCompleted, this, &VMdEdit::generateEditOutline); + // After highlight, the cursor may trun into non-visible. We should make it visible + // in this case. + connect(m_mdHighlighter, &HGMarkdownHighlighter::highlightCompleted, + this, [this]() { + QRect rect = this->cursorRect(); + QRect viewRect = this->rect(); + if ((rect.y() < viewRect.height() + && rect.y() + rect.height() > viewRect.height()) + || (rect.y() < 0 && rect.y() + rect.height() > 0)) { + this->ensureCursorVisible(); + } + }); + m_cbHighlighter = new VCodeBlockHighlightHelper(m_mdHighlighter, p_vdoc, p_type);