vuepress icon indicating copy to clipboard operation
vuepress copied to clipboard

Tripple clicking inline code should select it

Open PeppeL-G opened this issue 4 years ago • 11 comments

Feature request

The following markdown code:

Use the code `print(sum(4, 7))` to print the sum of 4 and 7.

is compiled to:

<p>Use the code <code>print(sum(4, 7))</code> to print the sum of 4 and 7.</p>

Tripple clicking on a word inside <code> will select the entire paragraph (since that's the closest block element), but most often you just want to select the code inside the <code> element, so you can copy-paste it. Adding display: block to <code> would give you this functionality, but that would of course render it as a block element which would screw up the presentation, so I suggest adding display: inline-block to <code> elements instead. Unfortunately, tripple clicking on an inline-block element only selects it's content in FireFox, and not in Chrome or Edge (haven't tested other browsers on windows 10), but at least the functionality would work in FireFox.

You can try tripple clicking on a code element here:

https://jsfiddle.net/ywup1rho/1/

What problem does this feature solve?

Easier to select and copy-paste inline code.

What does the proposed API look like?

N/A

How should this be implemented in your opinion?

Add display: inline-block to the CSS rule with the selector .theme-default-content code, and change padding and margin so it looks good.

Are you willing to work on this yourself?

Sure.

PeppeL-G avatar Sep 26 '19 10:09 PeppeL-G

This is a good idea, but I think we should find a way to make it work on all browsers, not just Firefox.

kefranabg avatar Sep 30 '19 12:09 kefranabg

I agree that identical cross-browser experience is better, but I don't know how to achieve that without using client-side JS. But maybe using the CSS property user-select could work just as well (clicking just once to select it):

https://jsfiddle.net/w4jnqrfp/

PeppeL-G avatar Sep 30 '19 13:09 PeppeL-G

My bad, user-select: all does not seem to have good browser support yet (73%):

https://caniuse.com/#feat=mdn-css_properties_user-select_all

PeppeL-G avatar Sep 30 '19 13:09 PeppeL-G

My bad, user-select: all does not seem to have good browser support yet (73%):

https://caniuse.com/#feat=mdn-css_properties_user-select_all

But it;s already good enough, much better then our situation now.

Mister-Hope avatar Oct 09 '19 09:10 Mister-Hope

May it be an option adding some button in the code box, that adds the code in the clipboard by just clicking it?

roeeyn avatar Oct 14 '19 03:10 roeeyn

@roeeyn I think that would work good for block code consisting of multiple lines, but I don't think it would work good for inline code, where there could be many code pieces on the same line.

user-select: all is the best solution I can think of at the moment. Can we get an official approvement of implementing it like that? If so, anyone is welcome to do it.

PeppeL-G avatar Oct 14 '19 07:10 PeppeL-G

73% support is better than nothing I guess! Contributions welcome!

kefranabg avatar Oct 14 '19 10:10 kefranabg

i can take this one

adico1 avatar Oct 09 '20 09:10 adico1

Hi,

I found the way to change the code section in the 'Guide'.

I looked for other places and found non so because I'm not very familiar with the project can you help me identify places where this should be in affect.

Thanks

adico1 avatar Oct 10 '20 10:10 adico1

@kefranabg hi, can I get a review?

adico1 avatar Oct 13 '20 15:10 adico1

hi @PeppeL-G can't we just use

<p> Use the code  <code><span> print(sum(4, 7)</span></code> to print the sum of 4 and 7 </p>
code{
  display: inline-flex;
}

OR

<p>Use the code <code>print(sum(4, 7))</code> to print the sum of 4 and 7.</p>
p{
  display: inline-flex;
  }

Saeed-Paris avatar Jul 28 '22 09:07 Saeed-Paris