Browse Source

MdTab: focus bug fix and find-in-page in expanded preview mode

Le Tan 7 years ago
parent
commit
62c0f218df
3 changed files with 32 additions and 6 deletions
  1. 3 0
      src/resources/vnote.ini
  2. 27 6
      src/vmdtab.cpp
  3. 2 0
      src/vmdtab.h

+ 3 - 0
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

+ 27 - 6
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();
+}

+ 2 - 0
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;