diff --git a/src/vedittab.cpp b/src/vedittab.cpp index 4845f7f0..da77ab56 100644 --- a/src/vedittab.cpp +++ b/src/vedittab.cpp @@ -400,6 +400,7 @@ void VEditTab::requestUpdateCurHeader() void VEditTab::requestUpdateOutline() { + checkToc(); emit outlineChanged(tableOfContent); } @@ -427,6 +428,9 @@ void VEditTab::updateCurHeader(const QString &anchor) } curHeader = VAnchor(m_file->retrivePath(), "#" + anchor, -1); if (!anchor.isEmpty()) { + if (checkToc()) { + emit outlineChanged(tableOfContent); + } const QVector &headers = tableOfContent.headers; for (int i = 0; i < headers.size(); ++i) { if (headers[i].anchor == curHeader.anchor) { @@ -443,6 +447,9 @@ void VEditTab::updateCurHeader(int p_lineNumber, int p_outlineIndex) if (!isEditMode || curHeader.lineNumber == p_lineNumber) { return; } + if (checkToc()) { + emit outlineChanged(tableOfContent); + } curHeader = VAnchor(m_file->retrivePath(), "", p_lineNumber); curHeader.m_outlineIndex = p_outlineIndex; if (p_lineNumber > -1) { @@ -519,3 +526,14 @@ void VEditTab::clearFindSelectionInWebView() webPreviewer->findText(""); } } + +bool VEditTab::checkToc() +{ + bool ret = false; + if (tableOfContent.filePath != m_file->retrivePath()) { + tableOfContent.filePath = m_file->retrivePath(); + ret = true; + } + return ret; +} + diff --git a/src/vedittab.h b/src/vedittab.h index e1703fd3..c6b696a4 100644 --- a/src/vedittab.h +++ b/src/vedittab.h @@ -77,6 +77,9 @@ private: void scrollPreviewToHeader(int p_outlineIndex); void findTextInWebView(const QString &p_text, uint p_options, bool p_peek, bool p_forward); + // Check if @tableOfContent is outdated (such as renaming the file). + // Return true if we need to update toc. + bool checkToc(); QPointer m_file; bool isEditMode;