diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp index 78f3979e..f50ef87b 100644 --- a/src/vmdtab.cpp +++ b/src/vmdtab.cpp @@ -168,7 +168,7 @@ bool VMdTab::scrollWebViewToHeader(const VHeaderPointer &p_header) return true; } -bool VMdTab::scrollEditorToHeader(const VHeaderPointer &p_header) +bool VMdTab::scrollEditorToHeader(const VHeaderPointer &p_header, bool p_force) { if (!m_outline.isMatched(p_header) || m_outline.getType() != VTableOfContentType::BlockNumber) { @@ -202,6 +202,17 @@ bool VMdTab::scrollEditorToHeader(const VHeaderPointer &p_header) } } + // If the cursor are now under the right title, we should not change it right at + // the title. + if (!p_force) { + int curBlockNumber = mdEdit->textCursor().block().blockNumber(); + if (m_outline.indexOfItemByBlockNumber(curBlockNumber) + == m_outline.indexOfItemByBlockNumber(blockNumber)) { + m_currentHeader = p_header; + return true; + } + } + if (mdEdit->scrollToHeader(blockNumber)) { m_currentHeader = p_header; return true; @@ -253,7 +264,7 @@ void VMdTab::showFileEditMode() VUtils::sleepWait(100); } - scrollEditorToHeader(header); + scrollEditorToHeader(header, false); mdEdit->setFocus(); } diff --git a/src/vmdtab.h b/src/vmdtab.h index cf2d8a67..2f73a22f 100644 --- a/src/vmdtab.h +++ b/src/vmdtab.h @@ -185,7 +185,8 @@ private: // Return true if scroll was made. bool scrollWebViewToHeader(const VHeaderPointer &p_header); - bool scrollEditorToHeader(const VHeaderPointer &p_header); + // @p_force: when true, will scroll even current mouse is under the specified header. + bool scrollEditorToHeader(const VHeaderPointer &p_header, bool p_force = true); // Scroll web/editor to given header. // Return true if scroll was made.