Browse Source

show hovered link in status line in read mode

Le Tan 7 years ago
parent
commit
960426579b
5 changed files with 29 additions and 1 deletions
  1. 16 0
      src/resources/markdown_template.js
  2. 5 0
      src/vdocument.cpp
  3. 5 0
      src/vdocument.h
  4. 1 1
      src/vmainwindow.cpp
  5. 2 0
      src/vmdtab.cpp

+ 16 - 0
src/resources/markdown_template.js

@@ -859,6 +859,7 @@ var finishOneAsyncJob = function() {
 // markdown-specifi handle logics, such as Mermaid, MathJax.
 var finishLogics = function() {
     if (asyncJobsCount <= 0) {
+        hookLinks();
         content.finishLogics();
         calculateWordCount();
     }
@@ -1427,3 +1428,18 @@ var setPreviewContent = function(lang, html) {
         previewDiv.className = '';
     }
 };
+
+// Show the href text of a link when mouse is over it.
+var showRefInLink = function(e) {
+    if (typeof content.showHoveredLink != 'undefined') {
+        content.showHoveredLink(this.href);
+    }
+};
+
+var hookLinks = function() {
+    var As = document.links;
+
+    for (var i = 0; i < As.length; ++i){
+        As[i].onmouseover = showRefInLink;
+    }
+};

+ 5 - 0
src/vdocument.cpp

@@ -188,3 +188,8 @@ void VDocument::previewCodeBlockCB(int p_id, const QString &p_lang, const QStrin
 {
     emit codeBlockPreviewReady(p_id, p_lang, p_html);
 }
+
+void VDocument::showHoveredLink(const QString &p_link)
+{
+    emit linkHovered(p_link);
+}

+ 5 - 0
src/vdocument.h

@@ -112,6 +112,9 @@ public slots:
 
     void previewCodeBlockCB(int p_id, const QString &p_lang, const QString &p_html);
 
+    // Show @p_link in status line.
+    void showHoveredLink(const QString &p_link);
+
 signals:
     void textChanged(const QString &text);
 
@@ -173,6 +176,8 @@ signals:
 
     void codeBlockPreviewReady(int p_id, const QString &p_lang, const QString &p_html);
 
+    void linkHovered(const QString &p_link);
+
 private:
     QString m_toc;
     QString m_header;

+ 1 - 1
src/vmainwindow.cpp

@@ -2542,7 +2542,7 @@ QAction *VMainWindow::newAction(const QIcon &p_icon,
 
 void VMainWindow::showStatusMessage(const QString &p_msg)
 {
-    const int timeout = 3000;
+    const int timeout = 5000;
     statusBar()->showMessage(p_msg, timeout);
 }
 

+ 2 - 0
src/vmdtab.cpp

@@ -457,6 +457,8 @@ void VMdTab::setupMarkdownViewer()
 
                 emit statusUpdated(info);
             });
+    connect(m_document, &VDocument::linkHovered,
+            this, &VMdTab::statusMessage);
 
     page->setWebChannel(channel);