Unwanted clipboard behavior flex inline table

Concerning https://jsfiddle.net/a2bsvoer/ Visually I have what I want. However, the linked jsfiddle causes the browser to copy cells into the clipboard with each cell (character) on its own line. How do I make it so that the browser copies full lines into the clipboard? I'm open to completely refactoring with these requirements: 1. I do need to access (via JS, CSS) individual cells containing at most a single Unicode glyph (ignoring ZWJ etc. behaviors). Pretend this is a terminal screen or VGA text mode. 2. The emojis must be centered within their text cells. (If this wasn't a requirement, I'd be done by now.) The HTML is generated, so strict use of whitespace is also fine. I wrote the example this way to be easier to see what is going on. My gut is telling me to go old-school and use a table element, but doing so causes tab characters to be inserted into the clipboard. I'm trying to avoid writing JS to intercept and de-mangle the clipboard on the copy operation.
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
56 Replies
ἔρως
ἔρως6mo ago
well, this is the behavior that's supposed to happen you're using spaces for layouting, and forcing divs to be inline
LJ
LJOP6mo ago
Sure. I've been able to squeeze the balloon so to speak, and get copy lines, but then the characters are no longer centered in their cell.
ἔρως
ἔρως6mo ago
because you're using divs and for some reason, you're using spans inside the divs
LJ
LJOP6mo ago
initially the col divs were spans
ἔρως
ἔρως6mo ago
they become block-level elements because they are part of a float in the end, will work like divs
LJ
LJOP6mo ago
if i take those spans out, then the whitespace disappears. those are 0x20 not 0xA0
ἔρως
ἔρως6mo ago
i know but that doesn't matter
LJ
LJOP6mo ago
fwiw, changing those divs to span does nothing
ἔρως
ἔρως6mo ago
why don't you use a table?
LJ
LJOP6mo ago
i say in the OP. i get tabs instead of newlines
ἔρως
ἔρως6mo ago
how about you remove the spans and use the html entity for the spaces?
LJ
LJOP6mo ago
what   ? or whatever it is. i've not used numeric entities in a while
ἔρως
ἔρως6mo ago
yes, that or something like that
LJ
LJOP6mo ago
no, whitespace becomes insignificant then.
ἔρως
ἔρως6mo ago
then can you re-create the table solution?
LJ
LJOP6mo ago
https://jsfiddle.net/a2bsvoer/1/ is probably as close as i'm going to get
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
ἔρως
ἔρως6mo ago
you're still setting the td to be inline-flex which makes it into inline elements
LJ
LJOP6mo ago
this does make it easier to demonstrate part of the problem though. change td { display: ___; } to each of inline, inline-block, inline-flex, table-cell and observe i cannot center the wide characters within its cell if i do not change how it is displayed
ἔρως
ἔρως6mo ago
don't touch the display i have an almost-working solution
LJ
LJOP6mo ago
the clipboard behavior of inline is mutually exclusive with being able to center the glyph
ἔρως
ἔρως6mo ago
correction
LJ
LJOP6mo ago
table has a weird line-height behavior i had to work around >_>
ἔρως
ἔρως6mo ago
I HAVE a working solution
LJ
LJOP6mo ago
ooOOOoo
ἔρως
ἔρως6mo ago
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
LJ
LJOP6mo ago
that does not meet my 2nd requirement
ἔρως
ἔρως6mo ago
what is it?
ἔρως
ἔρως6mo ago
it works
No description
LJ
LJOP6mo ago
per OP:
The emojis must be centered within their text cells. (If this wasn't a requirement, I'd be done by now.)
ἔρως
ἔρως6mo ago
they are
LJ
LJOP6mo ago
what browser?
ἔρως
ἔρως6mo ago
chrome
LJ
LJOP6mo ago
do you have a screenshot?
ἔρως
ἔρως6mo ago
of what?
LJ
LJOP6mo ago
No description
ἔρως
ἔρως6mo ago
this?
No description
LJ
LJOP6mo ago
that is wrong. those are not centered within their individual cells
ἔρως
ἔρως6mo ago
alright, let me start over
LJ
LJOP6mo ago
i don't think it's possible without using JS. the behavior of display: inline-flex; to show the glyphs centered seems to be mutually exclusive with the behavior of display: inline-block; to copy the text as complete lines
ἔρως
ἔρως6mo ago
it is, but i have a solution for the first one
LJ
LJOP6mo ago
i already had that working though : | i do appreciate your time. thank you for trying if i can't figure this out, i'm moving forward with the table/table-cell approach, using a to-be-written JS copy routine to strip tabs before committing anything to the clipboard
ἔρως
ἔρως6mo ago
my solution is almost working
LJ
LJOP6mo ago
i've been almost working for well over two hours, amid unrelated youtube videos
ἔρως
ἔρως6mo ago
how about using svg to center the icon?
LJ
LJOP6mo ago
if you're trying to leverage user-select, it's probably not going to work. the icon? that's just a placeholder for any wide characters i want to support whatever characters. i'm not trying to show a specific set of them i picked 🤬 as i feel it's the most apropos to the problem i'm having ; )
ἔρως
ἔρως6mo ago
that's what made it work 90% of the way
LJ
LJOP6mo ago
no, it isn't maybe it works to strip the tabs from the table output but it doesn't help when the cell text is in an inline-flex, which is needed for centering when using inline-block, the clipboard contents look fine; there no need for user-select shenanigans.
ἔρως
ἔρως6mo ago
because it's handled as a block element
LJ
LJOP6mo ago
right but inline-block somehow is handled differently. it sucks that being able to center text is tied to the clipboard behavior. thanks for trying user-select. i didn't know it changed the behavior of copying from table-cell.
ἔρως
ἔρως6mo ago
because it's treated as inline flex and grid as inline are hacky as hell this might even be a bug it does, for everything
LJ
LJOP6mo ago
not everything ; )
ἔρως
ἔρως6mo ago
if you use text, it only selects the text without any richtext that is, styles and stuff
LJ
LJOP6mo ago
in your example, if you give td the style display: inline-flex; it looks right but still copies wrong
ἔρως
ἔρως6mo ago
yeah, because flex requires it's children to be treated as blocks and not as inline
LJ
LJOP6mo ago
i'm wondering if i can get grid to do my bidding. grid is new to me. is flex slightly older?
ἔρως
ἔρως6mo ago
both are kinda somewhat the same age i say grid but the same happens to flex every child has to be a block
Want results from more Discord servers?
Add your server