From 62c0f218df4c49ee705d8c0d80fae0cd91fb6083 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 12 Sep 2018 20:35:43 +0800 Subject: [PATCH] MdTab: focus bug fix and find-in-page in expanded preview mode --- src/resources/vnote.ini | 3 +++ src/vmdtab.cpp | 33 +++++++++++++++++++++++++++------ src/vmdtab.h | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index 019c6aec..49f2bbe6 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -265,6 +265,9 @@ insert_new_note_in_front=false ; Whether highlight matches in page when activating a search result item highlight_matches_in_page=true +; Incremental search in page +find_incremental_search=true + [editor] ; Auto indent as previous line auto_indent=true diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp index ca68db5c..e2759fc0 100644 --- a/src/vmdtab.cpp +++ b/src/vmdtab.cpp @@ -689,8 +689,7 @@ void VMdTab::insertLink() void VMdTab::findText(const QString &p_text, uint p_options, bool p_peek, bool p_forward) { - if (m_isEditMode) { - Q_ASSERT(m_editor); + if (m_isEditMode && !previewExpanded()) { if (p_peek) { m_editor->peekText(p_text, p_options); } else { @@ -901,10 +900,27 @@ MarkdownConverterType VMdTab::getMarkdownConverterType() const void VMdTab::focusChild() { - if (m_mode == Mode::Read) { + switch (m_mode) { + case Mode::Read: m_webViewer->setFocus(); - } else { + break; + + case Mode::Edit: m_editor->setFocus(); + break; + + case Mode::EditPreview: + if (m_editor->isVisible()) { + m_editor->setFocus(); + } else { + m_webViewer->setFocus(); + } + + break; + + default: + Q_ASSERT(false); + break; } } @@ -1305,7 +1321,7 @@ void VMdTab::handleVimCmdCommandCancelled() void VMdTab::handleVimCmdCommandFinished(VVim::CommandLineType p_type, const QString &p_cmd) { - if (m_isEditMode) { + if (m_isEditMode && !previewExpanded()) { VVim *vim = getEditor()->getVim(); if (vim) { vim->processCommandLine(p_type, p_cmd); @@ -1328,7 +1344,7 @@ void VMdTab::handleVimCmdCommandChanged(VVim::CommandLineType p_type, const QStr { Q_UNUSED(p_type); Q_UNUSED(p_cmd); - if (m_isEditMode) { + if (m_isEditMode && !previewExpanded()) { VVim *vim = getEditor()->getVim(); if (vim) { vim->processCommandLineChanged(p_type, p_cmd); @@ -1621,3 +1637,8 @@ bool VMdTab::expandRestorePreviewArea() return true; } + +bool VMdTab::previewExpanded() const +{ + return (m_mode == Mode::EditPreview) && !m_editor->isVisible(); +} diff --git a/src/vmdtab.h b/src/vmdtab.h index 6bdcdd25..5549839b 100644 --- a/src/vmdtab.h +++ b/src/vmdtab.h @@ -242,6 +242,8 @@ private: void setCurrentMode(Mode p_mode); + bool previewExpanded() const; + VMdEditor *m_editor; VWebView *m_webViewer; VDocument *m_document;