Bug 115255 - [NEWHELP] Enable copy to clipboard of some text in help pages
Summary: [NEWHELP] Enable copy to clipboard of some text in help pages
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
(earliest affected)
Hardware: All All
: medium enhancement
Assignee: Not Assigned
Whiteboard: target:6.1.0
Depends on:
Blocks: New-Help
  Show dependency treegraph
Reported: 2018-01-27 12:42 UTC by Olivier Hallot
Modified: 2018-02-08 19:24 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Hallot 2018-01-27 12:42:20 UTC
With the help now displayed in browser, some lines of help contents should be put in the clipboard with a simple click.

Steps to Reproduce:

Actual Results:  

Expected Results:
On hovering the mouse around the spanned text, display a button to copy the text to the clipboard.

Then user can paste the copied text in a document and work on it.

For example, a Calc function such as COS, the example in the help page can be copied and pasted in a spreadsheet.

same for BASIC code.

Reproducible: Always

User Profile Reset: No

Additional Info:
The example text is inside a <item type="input"></item>

<item type="input">=COS(0)</item> returns 1.

The transformation (online_transform.xsl) can generate a <span> or <div> tag with an ID and a piece of javascript can display a button on hovering to copy "=COS(0)" to clipboard.

User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
Comment 1 Buovjaga 2018-01-27 19:28:04 UTC
The simplest solution would be to do it without a button. We could have a CSS tooltip say "Click on the text to copy it to your clipboard".

We could also include a text at the beginning of such articles "the texts looking like this can be copied to the clipboard by clicking on them".

JS to target a class (not an ID because we want to be able to have multiple copyable elements in a single article):

> var copyable = document.getElementsByClassName("copyable");
> for (var i = 0, len = copyable.length; i < len; i++) {
>     (function() {
>         var item = copyable[i];
>         item.onclick = function() {
>             document.execCommand("copy");
>         }
>         item.addEventListener("copy", function(event) {
>             event.preventDefault();
>             if (event.clipboardData) {
>                 event.clipboardData.setData("text/plain", item.textContent);
>             }
>         });
>     }());
> }

Not tested, but should work.

Let me know what you think and we can develop it further.
Comment 2 Commit Notification 2018-02-08 19:20:49 UTC
Ilmari Lauhakangas committed a patch related to this issue.
It has been pushed to "master":


tdf#115255 and auto-expand contents per subitem