chiark / gitweb /
doxygen: make it possible to easily copy result links to clipboard.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 2 Jan 2019 21:02:26 +0000 (22:02 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 2 Jan 2019 21:25:05 +0000 (22:25 +0100)
Especially Markdown links. A huge timesaver when doing tech support via
Gitter or so :)

css/m-dark+doxygen.compiled.css
css/m-dark.doxygen.compiled.css
css/m-doxygen.css
css/m-light+doxygen.compiled.css
css/m-light.doxygen.compiled.css
doxygen/dox2html5.py
doxygen/search.js
doxygen/test/layout_generated_doxyfile/index.html
doxygen/test/layout_minimal/index.html
doxygen/test/test_doxyfile.py

index 6a8fcbe1628d160cd26afb46e5d60c50ab62d635..0fc962a0bb50bb05e6bdde948b27da76666bc37d 100644 (file)
@@ -2765,6 +2765,9 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico
 .m-dox-search ul#search-results li#search-current a {
   background-color: #34424d;
 }
+.m-dox-search ul#search-results li#search-current.m-dox-search-copied a {
+  background-color: #2a703f;
+}
 .m-dox-search-typed {
   color: #5b9dd9;
 }
index 4760c3544323b29b705e263a3809387a8fc82896..b1a0656dd86b97b9d4f36b4cb1329aa305bb09cf 100644 (file)
@@ -287,6 +287,9 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico
 .m-dox-search ul#search-results li#search-current a {
   background-color: #34424d;
 }
+.m-dox-search ul#search-results li#search-current.m-dox-search-copied a {
+  background-color: #2a703f;
+}
 .m-dox-search-typed {
   color: #5b9dd9;
 }
index 3163ddcd977e93e5472097de203017bb221a4064..ef82b1cd615da4000a7f861eee4b8c1038b2d021 100644 (file)
@@ -308,6 +308,9 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico
 .m-dox-search ul#search-results li#search-current a {
   background-color: var(--default-filled-background-color);
 }
+.m-dox-search ul#search-results li#search-current.m-dox-search-copied a {
+  background-color: var(--success-filled-background-color);
+}
 .m-dox-search-typed {
   color: var(--link-color);
 }
index 16e390d9d81c27d4fd530c2520cdf00bec8e4f90..30d1924021dab9862ee7be084ff66eb367f8d9fa 100644 (file)
@@ -2698,6 +2698,9 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico
 .m-dox-search ul#search-results li#search-current a {
   background-color: #fbf0ec;
 }
+.m-dox-search ul#search-results li#search-current.m-dox-search-copied a {
+  background-color: #4dd376;
+}
 .m-dox-search-typed {
   color: #ea7944;
 }
index 0478021aae42012414de00b43b961607e145eee4..fcf661530bdcfad39f7ca2faec81dc306463c723 100644 (file)
@@ -287,6 +287,9 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico
 .m-dox-search ul#search-results li#search-current a {
   background-color: #fbf0ec;
 }
+.m-dox-search ul#search-results li#search-current.m-dox-search-copied a {
+  background-color: #4dd376;
+}
 .m-dox-search-typed {
   color: #ea7944;
 }
index 6fab057f7c928b59c053a38da7a0f8f302e9930e..6f5f5885d03754e00ea0ac123245ffda7484f45d 100755 (executable)
@@ -3224,12 +3224,18 @@ def parse_doxyfile(state: State, doxyfile, config = None):
         'M_SEARCH_DISABLED': ['NO'],
         'M_SEARCH_DOWNLOAD_BINARY': ['NO'],
         'M_SEARCH_HELP': [
-"""Search for symbols, directories, files, pages or modules. You can omit any
-prefix from the symbol or file path; adding a <code>:</code> or <code>/</code>
-suffix lists all members of given symbol or directory. Navigate through the
-list using <span class="m-label m-dim">&darr;</span> and
-<span class="m-label m-dim">&uarr;</span>, press
-<span class="m-label m-dim">Enter</span> to go."""],
+"""<p class="m-noindent">Search for symbols, directories, files, pages or
+modules. You can omit any prefix from the symbol or file path; adding a
+<code>:</code> or <code>/</code> suffix lists all members of given symbol or
+directory.</p>
+<p class="m-noindent">Use <span class="m-label m-dim">&darr;</span>
+/ <span class="m-label m-dim">&uarr;</span> to navigate through the list,
+<span class="m-label m-dim">Enter</span> to go.
+<span class="m-label m-dim">Tab</span> autocompletes common prefix, you can
+copy a link to the result using <span class="m-label m-dim">⌘</span>
+<span class="m-label m-dim">L</span> while <span class="m-label m-dim">⌘</span>
+<span class="m-label m-dim">M</span> produces a Markdown link.</p>
+"""],
         'M_SEARCH_BASE_URL': [''],
         'M_SEARCH_EXTERNAL_URL': ['']
     }
index 6031ca5d268b6a04c77a867d1e398cef5f443a60..13fc3222ab24bd3fde9f5c57013f4d9b7c811baa 100644 (file)
@@ -514,7 +514,7 @@ var Search = {
                 }
 
                 /* Labels + */
-                list += '<li' + (i ? '' : ' id="search-current"') + '><a href="' + results[i].url + '" onmouseover="selectResult(event)"><div class="m-label m-flat ' + color + '">' + type + '</div>' + (results[i].flags & 2 ? '<div class="m-label m-danger">deprecated</div>' : '') + (results[i].flags & 4 ? '<div class="m-label m-danger">deleted</div>' : '');
+                list += '<li' + (i ? '' : ' id="search-current"') + '><a href="' + results[i].url + '" onmouseover="selectResult(event)" data-md-link-title="' + this.escape(results[i].name.substr(results[i].name.length - value.length - results[i].suffixLength)) + '"><div class="m-label m-flat ' + color + '">' + type + '</div>' + (results[i].flags & 2 ? '<div class="m-label m-danger">deprecated</div>' : '') + (results[i].flags & 4 ? '<div class="m-label m-danger">deleted</div>' : '');
 
                 /* Render the alias (cut off from the right) */
                 if(results[i].alias) {
@@ -629,6 +629,23 @@ function hideSearch() {
     return false;
 }
 
+/* istanbul ignore next */
+function copyToKeyboard(text) {
+    /* Append to the popup, appending to document.body would cause it to
+       scroll when focused */
+    let searchPopup = document.getElementsByClassName('m-dox-search')[0];
+    let textarea = document.createElement("textarea");
+    textarea.value = text;
+    searchPopup.appendChild(textarea);
+    textarea.focus();
+    textarea.select();
+
+    document.execCommand('copy');
+
+    searchPopup.removeChild(textarea);
+    document.getElementById('search-input').focus();
+}
+
 /* Only in case we're running in a browser. Why a simple if(document) doesn't
    work is beyond me. */ /* istanbul ignore if */
 if(typeof document !== 'undefined') {
@@ -695,6 +712,26 @@ if(typeof document !== 'undefined') {
 
                 return false; /* so the form doesn't get sent */
 
+            /* Copy (Markdown) link to keyboard */
+            } else if((event.key.toLowerCase() == 'l' || event.key.toLowerCase() == 'm') && event.metaKey) {
+                let result = document.getElementById('search-current');
+                if(result) {
+                    let plain = event.key.toLowerCase() == 'l';
+                    let link = plain ? result.firstElementChild.href :
+                        '[' + result.firstElementChild.dataset.mdLinkTitle + '](' + result.firstElementChild.href + ')';
+
+                    copyToKeyboard(link);
+
+                    /* Add CSS class to the element for visual feedback (this
+                       will get removed on keyup), but only if it's not already
+                       there (in case of key repeat, e.g.) */
+                    if(result.className.indexOf('m-dox-search-copied') == -1)
+                        result.className += ' m-dox-search-copied';
+                    console.log("Copied " +  (plain ? "link" : "Markdown link") + " to " + result.firstElementChild.dataset.mdLinkTitle);
+                }
+
+                return false; /* so L doesn't get entered into the box */
+
             /* Looks like the user is inserting some text (and not cutting,
                copying or whatever), allow autocompletion for the new
                character. The oninput event resets this back to false, so this
@@ -725,6 +762,14 @@ if(typeof document !== 'undefined') {
         }
     };
 
+    document.onkeyup = function(event) {
+        /* Remove highlight after key is released after a link copy */
+        if((event.key.toLowerCase() == 'l' || event.key.toLowerCase() == 'm') && event.metaKey) {
+            let result = document.getElementById('search-current');
+            if(result) result.className = result.className.replace(' m-dox-search-copied', '');
+        }
+    };
+
     /* Allow selecting items by mouse hover only after it moves once the
        results are populated. This prevents a random item getting selected if
        the cursor is left motionless over the result area. */
index 4bc45dbea103d09b3a4f397210fae0d5fb51eefb..af66782a783e54fb4310bd85a84ba1a2ebae4065 100644 (file)
           </form>
           <noscript class="m-text m-danger m-text-center">Unlike everything else in the docs, the search functionality <em>requires</em> JavaScript.</noscript>
           <div id="search-help" class="m-text m-dim m-text-center">
-            Search for symbols, directories, files, pages or modules. You can omit any
-            prefix from the symbol or file path; adding a <code>:</code> or <code>/</code>
-            suffix lists all members of given symbol or directory. Navigate through the
-            list using <span class="m-label m-dim">&darr;</span> and
-            <span class="m-label m-dim">&uarr;</span>, press
+            <p class="m-noindent">Search for symbols, directories, files, pages or
+            modules. You can omit any prefix from the symbol or file path; adding a
+            <code>:</code> or <code>/</code> suffix lists all members of given symbol or
+            directory.</p>
+            <p class="m-noindent">Use <span class="m-label m-dim">&darr;</span>
+            / <span class="m-label m-dim">&uarr;</span> to navigate through the list,
             <span class="m-label m-dim">Enter</span> to go.
+            <span class="m-label m-dim">Tab</span> autocompletes common prefix, you can
+            copy a link to the result using <span class="m-label m-dim">⌘</span>
+            <span class="m-label m-dim">L</span> while <span class="m-label m-dim">⌘</span>
+            <span class="m-label m-dim">M</span> produces a Markdown link.</p>
           </div>
           <div id="search-notfound" class="m-text m-warning m-text-center">Sorry, nothing was found.</div>
           <ul id="search-results"></ul>
index 4bc45dbea103d09b3a4f397210fae0d5fb51eefb..af66782a783e54fb4310bd85a84ba1a2ebae4065 100644 (file)
           </form>
           <noscript class="m-text m-danger m-text-center">Unlike everything else in the docs, the search functionality <em>requires</em> JavaScript.</noscript>
           <div id="search-help" class="m-text m-dim m-text-center">
-            Search for symbols, directories, files, pages or modules. You can omit any
-            prefix from the symbol or file path; adding a <code>:</code> or <code>/</code>
-            suffix lists all members of given symbol or directory. Navigate through the
-            list using <span class="m-label m-dim">&darr;</span> and
-            <span class="m-label m-dim">&uarr;</span>, press
+            <p class="m-noindent">Search for symbols, directories, files, pages or
+            modules. You can omit any prefix from the symbol or file path; adding a
+            <code>:</code> or <code>/</code> suffix lists all members of given symbol or
+            directory.</p>
+            <p class="m-noindent">Use <span class="m-label m-dim">&darr;</span>
+            / <span class="m-label m-dim">&uarr;</span> to navigate through the list,
             <span class="m-label m-dim">Enter</span> to go.
+            <span class="m-label m-dim">Tab</span> autocompletes common prefix, you can
+            copy a link to the result using <span class="m-label m-dim">⌘</span>
+            <span class="m-label m-dim">L</span> while <span class="m-label m-dim">⌘</span>
+            <span class="m-label m-dim">M</span> produces a Markdown link.</p>
           </div>
           <div id="search-notfound" class="m-text m-warning m-text-center">Sorry, nothing was found.</div>
           <ul id="search-results"></ul>
index 9948518a3acb3644fd3a609e760c60a7c71dd0ba..eccf17d644550af8e5cbf236c768ea87b64d1457 100644 (file)
@@ -61,12 +61,18 @@ class Doxyfile(unittest.TestCase):
             'M_SEARCH_BASE_URL': '',
             'M_SEARCH_EXTERNAL_URL': '',
             'M_SEARCH_HELP':
-"""Search for symbols, directories, files, pages or modules. You can omit any
-prefix from the symbol or file path; adding a <code>:</code> or <code>/</code>
-suffix lists all members of given symbol or directory. Navigate through the
-list using <span class="m-label m-dim">&darr;</span> and
-<span class="m-label m-dim">&uarr;</span>, press
-<span class="m-label m-dim">Enter</span> to go.""",
+"""<p class="m-noindent">Search for symbols, directories, files, pages or
+modules. You can omit any prefix from the symbol or file path; adding a
+<code>:</code> or <code>/</code> suffix lists all members of given symbol or
+directory.</p>
+<p class="m-noindent">Use <span class="m-label m-dim">&darr;</span>
+/ <span class="m-label m-dim">&uarr;</span> to navigate through the list,
+<span class="m-label m-dim">Enter</span> to go.
+<span class="m-label m-dim">Tab</span> autocompletes common prefix, you can
+copy a link to the result using <span class="m-label m-dim">⌘</span>
+<span class="m-label m-dim">L</span> while <span class="m-label m-dim">⌘</span>
+<span class="m-label m-dim">M</span> produces a Markdown link.</p>
+""",
             'M_THEME_COLOR': '#22272e',
             'OUTPUT_DIRECTORY': '',
             'PROJECT_BRIEF': 'is cool',