Bitcoin Forum
May 19, 2026, 02:15:36 PM *
News: Latest Bitcoin Core release: 31.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: A select link/button for [code] blocks (SMF patch)  (Read 210 times)
PowerGlove (OP)
Hero Member
*****
hacker
Offline

Activity: 698
Merit: 7036



View Profile
October 16, 2024, 07:20:32 AM
Merited by vapourminer (4), Xal0lex (3), bitmover (3), dkbit98 (3), Cyrus (2), Welsh (2), icopress (1), ibminer (1), noorman0 (1)
 #1

I did a similar patch a while ago to add a "Copy" button to [code] blocks. I figured that it would get accepted pretty quickly, but I'm glad that it wasn't, because I think that this new patch is a bit nicer. The old patch had two problems with it (that I can think of):

(1) Programmatic access to the clipboard is something that I expect to get more and more fragile over time. There's already some not-completely-reliable browser logic that stops the clipboard from being interacted with in non-user-initiated contexts. So, rather than implement something that I expect will pick up more and more cross-browser weirdness as time goes on, I think it's better to solve basically the same problem (how finicky it is to copy-paste [code], especially on mobile), but with something that's likely to behave more reliably across more browsers.

(2) The previous patch added the button whether JavaScript was enabled or not. This patch only adds the button when JavaScript is available. Not a big deal, but, it is kind of goofy for the button to be there if it's not going to do anything when you click on it. Better to just not even show it in those situations.

Compared to the version that people helped me test, the only user-facing change I've made is to tweak the opacity (so that it's distinct from the text it's adjacent to, and so that it's a little softer/quieter in appearance):



(That's an image, above. You tried to use that select link/button, didn't you?) Cheesy

Code: (Where's the code?)
No diff(s) this time... I'm experimenting with a new way to do certain kinds of patches, and this is one of those patches: I've sent the code to theymos.
theymos
Administrator
Legendary
*
Offline

Activity: 5936
Merit: 15466


View Profile
May 07, 2026, 12:42:47 PM
Merited by Xal0lex (3), bitmover (2), Cyrus (1), icopress (1), ibminer (1), PowerGlove (1)
 #2

PowerGlove sent me a different way of doing this, which is live now, but it's sort of hidden: if you click the blue "Code:" text immediately before the actual code block, then it'll select the whole code block.

Thanks to PowerGlove for the patch!

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
SquirrelJulietGarden
Hero Member
*****
Offline

Activity: 2002
Merit: 940



View Profile
May 07, 2026, 12:47:51 PM
 #3

PowerGlove sent me a different way of doing this, which is live now, but it's sort of hidden: if you click the blue "Code:" text immediately before the actual code block, then it'll select the whole code block.

Thanks to PowerGlove for the patch!
Great! Thanks theymos.

I try to test and see that there are two ways.

First way is like you guided: Click on Code before a box of code block, and content will be selected.
Second way is clicking on the box, then the content in the code block will be selected too.

Code:
Copy

It is clearer for an example if I centralize the code block. Then I can select the content by clicking on the block at the left corner.
Code: (secondway)
copy

 
.Winna.com..

░░░░░░░▄▀▀▀
░░


▐▌▐▌
▄▄▄▒▒▒▄▄▄
████████████
█████████████
███▀▀███▀

▄▄

██████████████
████████████▄
█████████████
███▄███▄█████▌
███▀▀█▀▀█████
████▀▀▀█████▌
████████████
█████████████
█████
▀▀▀██████

▄▄
THE ULTIMATE CRYPTO
...CASINO & SPORTSBOOK...
─────  ♦  ─────

▄▄██▄▄
▄▄████████▄▄
██████████████
████████████████
███████████████
████████████████
▀██████████████▀
▀██████████▀
▀████▀

▄▄▄▄

▄▄▀███▀▄▄
▄██████████▄
███████████
███▄▄
▄███▄▄▄███
████▀█████▀███
█████████████████
█████████████
▀███████████
▀▀█████▀▀

▄▄▄▄


.....INSTANT.....
WITHDRAWALS
 
...UP TO 30%...
LOSSBACK
 
 

   PLAY NOW   
ibminer
Legendary
*
Offline

Activity: 2057
Merit: 3680


Goonies never say die.


View Profile WWW
May 07, 2026, 03:34:00 PM
Merited by Cyrus (1), PowerGlove (1)
 #4

First way is like you guided: Click on Code before a box of code block, and content will be selected.
Second way is clicking on the box, then the content in the code block will be selected too.

Looks like only one way to me, the centering just moves the "code" text to the middle, but it is still allowing the click anywhere on that top line/header of the code box:





Good to see you still around PG, I thought about you not too long ago when I was watching pixels with the family, great movie. Smiley

noorman0
Hero Member
*****
Offline

Activity: 2016
Merit: 841


[Nope]No hype delivers more than hope


View Profile WWW
May 07, 2026, 03:41:15 PM
 #5

-snip-
Second way is clicking on the box, then the content in the code block will be selected too.

-snip-
It is clearer for an example if I centralize the code block. Then I can select the content by clicking on the block at the left corner.
Code: (secondway)
copy
Actually, the second method you mentioned doesn't work for me. Double- or tripple-clicking only helps select the current line. I mean, does that also work if the code block contains more than 1 line of contents?

PowerGlove (OP)
Hero Member
*****
hacker
Offline

Activity: 698
Merit: 7036



View Profile
Today at 02:44:10 AM
Merited by vapourminer (4)
 #6

Looks like only one way to me, the centering just moves the "code" text to the middle, but it is still allowing the click anywhere on that top line/header (...)
Yup. The below excerpt is from the patch PM:

One little quirk is that that div has more horizontal extent than the header text, so, while people will tend to think of this feature as being tied specifically to the header text, it actually affects all of the space immediately above the contents of a [code] block (which, accidentally, will probably help discoverability).

Good to see you still around PG, I thought about you not too long ago (...)
Yep. I'm still kind of around... I thought about you, too, recently. (I was looking at the Merit Poker code the other day, which I haven't touched in a little over a year, and I gave myself the giggles pretty good listening to the audio for the /virus easter egg, and that "Wilhelm scream" that plays when someone goes bust.) Cheesy

I do miss this place. Unfortunately, it still makes just as much sense for me to throw myself at Bitcointalk as it did ~4 months ago when theymos and I arrived at the decision to part ways (which is to say: it doesn't make much sense at all). But, old habits die hard, and I expect I'll continue to once-in-a-while get an urge to contribute something (sometimes those improvements will be announced, like with this small code-selection patch, and sometimes they'll be too insignificant for that, like with the very small ignore-related bug I fixed at around the same time).



(I don't want to turn this post into a diary entry, but in case anyone is wondering what I'm spending my energy on these days: I've more-or-less focused my attention back on an old PLT-related idea that I was pursuing just before I joined Bitcointalk. I really enjoy working on compilers and so on, and they often present really interesting problems, especially when I approach them in the dependency-free, self-hosted, trusting-trust-proof way that I've been closing in on for the last 15 years or so. I was thinking of occasionally sharing/posting-about some of the bootstrapping problems that I've bumped into, and how fascinating and fundamental their solutions can be, but I don't think that there's much of an audience for that kind of exposition nowadays. Even before AI, I struggled mightily to find fellow programmers possessed of any serious desire to make use of and build nothing but deeply-understood things. I struggled even to just find people who were willing to think critically about the sacrifices that they had been taught to make at the altar of productivity. In the AI age, the "comprehension optional" style has really taken root, and that school of thought is anathema to someone like me. So, instead of depressing myself further by trying and failing to find the few remaining members of my tribe, I'll for now just quietly pursue my interests and keep the bulk of my thinking unshared.)
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!