MdTab: fix the synchronization between read and edit mode

Mute web view in edit mode.
This commit is contained in:
Le Tan 2018-07-13 21:54:26 +08:00
parent 926e053d37
commit 3e29a647ab
4 changed files with 29 additions and 2 deletions

View File

@ -154,12 +154,18 @@ var htmlContent = function() {
content.htmlContentCB("", styleContent(), contentDiv.innerHTML); content.htmlContentCB("", styleContent(), contentDiv.innerHTML);
}; };
var mute = function(muted) {
g_muteScroll = muted;
};
new QWebChannel(qt.webChannelTransport, new QWebChannel(qt.webChannelTransport,
function(channel) { function(channel) {
content = channel.objects.content; content = channel.objects.content;
content.requestScrollToAnchor.connect(scrollToAnchor); content.requestScrollToAnchor.connect(scrollToAnchor);
content.requestMuted.connect(mute);
if (typeof highlightText == "function") { if (typeof highlightText == "function") {
content.requestHighlightText.connect(highlightText); content.requestHighlightText.connect(highlightText);
content.noticeReadyToHighlightText(); content.noticeReadyToHighlightText();

View File

@ -12,7 +12,8 @@ VDocument::VDocument(const VFile *v_file, QObject *p_parent)
m_readyToHighlight(false), m_readyToHighlight(false),
m_plantUMLHelper(NULL), m_plantUMLHelper(NULL),
m_graphvizHelper(NULL), m_graphvizHelper(NULL),
m_nextID(0) m_nextID(0),
m_webViewMuted(false)
{ {
} }
@ -46,7 +47,7 @@ void VDocument::scrollToAnchor(const QString &anchor)
void VDocument::setHeader(const QString &anchor) void VDocument::setHeader(const QString &anchor)
{ {
if (anchor == m_header) { if (m_webViewMuted || anchor == m_header) {
return; return;
} }

View File

@ -67,6 +67,8 @@ public:
int registerIdentifier(); int registerIdentifier();
void muteWebView(bool p_muted);
public slots: public slots:
// Will be called in the HTML side // Will be called in the HTML side
@ -173,6 +175,8 @@ signals:
void codeBlockPreviewReady(int p_id, const QString &p_lang, const QString &p_html); void codeBlockPreviewReady(int p_id, const QString &p_lang, const QString &p_html);
void requestMuted(bool p_muted);
private: private:
QString m_toc; QString m_toc;
QString m_header; QString m_header;
@ -198,6 +202,9 @@ private:
VGraphvizHelper *m_graphvizHelper; VGraphvizHelper *m_graphvizHelper;
int m_nextID; int m_nextID;
// Whether propogate signals from web view.
bool m_webViewMuted;
}; };
inline bool VDocument::isReadyToHighlight() const inline bool VDocument::isReadyToHighlight() const
@ -219,4 +226,10 @@ inline int VDocument::registerIdentifier()
{ {
return ++m_nextID; return ++m_nextID;
} }
inline void VDocument::muteWebView(bool p_muted)
{
m_webViewMuted = p_muted;
emit requestMuted(m_webViewMuted);
}
#endif // VDOCUMENT_H #endif // VDOCUMENT_H

View File

@ -434,6 +434,7 @@ void VMdTab::setupMarkdownViewer()
// Recover header from edit mode. // Recover header from edit mode.
scrollWebViewToHeader(m_headerFromEditMode); scrollWebViewToHeader(m_headerFromEditMode);
m_headerFromEditMode.clear(); m_headerFromEditMode.clear();
m_document->muteWebView(false);
return; return;
} }
@ -1058,6 +1059,10 @@ void VMdTab::tabIsReady(TabReady p_mode)
|| (!m_isEditMode && p_mode == TabReady::ReadMode); || (!m_isEditMode && p_mode == TabReady::ReadMode);
if (isCurrentMode) { if (isCurrentMode) {
if (p_mode == TabReady::ReadMode) {
m_document->muteWebView(false);
}
restoreFromTabInfo(); restoreFromTabInfo();
if (m_enableBackupFile if (m_enableBackupFile
@ -1426,6 +1431,7 @@ void VMdTab::setCurrentMode(Mode p_mode)
break; break;
case Mode::Edit: case Mode::Edit:
m_document->muteWebView(true);
m_webViewer->hide(); m_webViewer->hide();
m_editor->show(); m_editor->show();
@ -1435,6 +1441,7 @@ void VMdTab::setCurrentMode(Mode p_mode)
case Mode::EditPreview: case Mode::EditPreview:
Q_ASSERT(m_editor); Q_ASSERT(m_editor);
m_document->muteWebView(true);
m_webViewer->setInPreview(true); m_webViewer->setInPreview(true);
m_webViewer->show(); m_webViewer->show();
m_editor->show(); m_editor->show();