From a98ccfb1e6a44d49871dc56c81502209b88a05dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 2 Jan 2019 22:02:26 +0100 Subject: [PATCH] doxygen: make it possible to easily copy result links to clipboard. Especially Markdown links. A huge timesaver when doing tech support via Gitter or so :) --- css/m-dark+doxygen.compiled.css | 3 ++ css/m-dark.doxygen.compiled.css | 3 ++ css/m-doxygen.css | 3 ++ css/m-light+doxygen.compiled.css | 3 ++ css/m-light.doxygen.compiled.css | 3 ++ doxygen/dox2html5.py | 18 ++++--- doxygen/search.js | 47 ++++++++++++++++++- .../test/layout_generated_doxyfile/index.html | 15 ++++-- doxygen/test/layout_minimal/index.html | 15 ++++-- doxygen/test/test_doxyfile.py | 18 ++++--- 10 files changed, 105 insertions(+), 23 deletions(-) diff --git a/css/m-dark+doxygen.compiled.css b/css/m-dark+doxygen.compiled.css index 6a8fcbe1..0fc962a0 100644 --- a/css/m-dark+doxygen.compiled.css +++ b/css/m-dark+doxygen.compiled.css @@ -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; } diff --git a/css/m-dark.doxygen.compiled.css b/css/m-dark.doxygen.compiled.css index 4760c354..b1a0656d 100644 --- a/css/m-dark.doxygen.compiled.css +++ b/css/m-dark.doxygen.compiled.css @@ -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; } diff --git a/css/m-doxygen.css b/css/m-doxygen.css index 3163ddcd..ef82b1cd 100644 --- a/css/m-doxygen.css +++ b/css/m-doxygen.css @@ -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); } diff --git a/css/m-light+doxygen.compiled.css b/css/m-light+doxygen.compiled.css index 16e390d9..30d19240 100644 --- a/css/m-light+doxygen.compiled.css +++ b/css/m-light+doxygen.compiled.css @@ -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; } diff --git a/css/m-light.doxygen.compiled.css b/css/m-light.doxygen.compiled.css index 0478021a..fcf66153 100644 --- a/css/m-light.doxygen.compiled.css +++ b/css/m-light.doxygen.compiled.css @@ -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; } diff --git a/doxygen/dox2html5.py b/doxygen/dox2html5.py index 6fab057f..6f5f5885 100755 --- a/doxygen/dox2html5.py +++ b/doxygen/dox2html5.py @@ -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 : or / -suffix lists all members of given symbol or directory. Navigate through the -list using and -, press -Enter to go."""], +"""

Search for symbols, directories, files, pages or +modules. You can omit any prefix from the symbol or file path; adding a +: or / suffix lists all members of given symbol or +directory.

+

Use +/ to navigate through the list, +Enter to go. +Tab autocompletes common prefix, you can +copy a link to the result using ⌘ +L while ⌘ +M produces a Markdown link.

+"""], 'M_SEARCH_BASE_URL': [''], 'M_SEARCH_EXTERNAL_URL': [''] } diff --git a/doxygen/search.js b/doxygen/search.js index 6031ca5d..13fc3222 100644 --- a/doxygen/search.js +++ b/doxygen/search.js @@ -514,7 +514,7 @@ var Search = { } /* Labels + */ - list += '
' + type + '
' + (results[i].flags & 2 ? '
deprecated
' : '') + (results[i].flags & 4 ? '
deleted
' : ''); + list += '
' + type + '
' + (results[i].flags & 2 ? '
deprecated
' : '') + (results[i].flags & 4 ? '
deleted
' : ''); /* 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. */ diff --git a/doxygen/test/layout_generated_doxyfile/index.html b/doxygen/test/layout_generated_doxyfile/index.html index 4bc45dbe..af66782a 100644 --- a/doxygen/test/layout_generated_doxyfile/index.html +++ b/doxygen/test/layout_generated_doxyfile/index.html @@ -65,12 +65,17 @@
- Search for symbols, directories, files, pages or modules. You can omit any - prefix from the symbol or file path; adding a : or / - suffix lists all members of given symbol or directory. Navigate through the - list using and - , press +

Search for symbols, directories, files, pages or + modules. You can omit any prefix from the symbol or file path; adding a + : or / suffix lists all members of given symbol or + directory.

+

Use + / to navigate through the list, Enter to go. + Tab autocompletes common prefix, you can + copy a link to the result using ⌘ + L while ⌘ + M produces a Markdown link.

Sorry, nothing was found.
    diff --git a/doxygen/test/layout_minimal/index.html b/doxygen/test/layout_minimal/index.html index 4bc45dbe..af66782a 100644 --- a/doxygen/test/layout_minimal/index.html +++ b/doxygen/test/layout_minimal/index.html @@ -65,12 +65,17 @@
    - Search for symbols, directories, files, pages or modules. You can omit any - prefix from the symbol or file path; adding a : or / - suffix lists all members of given symbol or directory. Navigate through the - list using and - , press +

    Search for symbols, directories, files, pages or + modules. You can omit any prefix from the symbol or file path; adding a + : or / suffix lists all members of given symbol or + directory.

    +

    Use + / to navigate through the list, Enter to go. + Tab autocompletes common prefix, you can + copy a link to the result using ⌘ + L while ⌘ + M produces a Markdown link.

    Sorry, nothing was found.
      diff --git a/doxygen/test/test_doxyfile.py b/doxygen/test/test_doxyfile.py index 9948518a..eccf17d6 100644 --- a/doxygen/test/test_doxyfile.py +++ b/doxygen/test/test_doxyfile.py @@ -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 : or / -suffix lists all members of given symbol or directory. Navigate through the -list using and -, press -Enter to go.""", +"""

      Search for symbols, directories, files, pages or +modules. You can omit any prefix from the symbol or file path; adding a +: or / suffix lists all members of given symbol or +directory.

      +

      Use +/ to navigate through the list, +Enter to go. +Tab autocompletes common prefix, you can +copy a link to the result using ⌘ +L while ⌘ +M produces a Markdown link.

      +""", 'M_THEME_COLOR': '#22272e', 'OUTPUT_DIRECTORY': '', 'PROJECT_BRIEF': 'is cool', -- 2.30.2