MdTab: do not scroll editor when it is under the right header while entering edit mode

This commit is contained in:
Le Tan 2018-09-06 21:12:17 +08:00
parent 377c00c25d
commit d66b4752d4
2 changed files with 15 additions and 3 deletions

View File

@ -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();
}

View File

@ -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.