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
ἔρως
ἔρως2w ago
well, this is the behavior that's supposed to happen you're using spaces for layouting, and forcing divs to be inline
LJ
LJ2w 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.
ἔρως
ἔρως2w ago
because you're using divs and for some reason, you're using spans inside the divs
LJ
LJ2w ago
initially the col divs were spans
ἔρως
ἔρως2w ago
they become block-level elements because they are part of a float in the end, will work like divs
LJ
LJ2w ago
if i take those spans out, then the whitespace disappears. those are 0x20 not 0xA0
ἔρως
ἔρως2w ago
i know but that doesn't matter
LJ
LJ2w ago
fwiw, changing those divs to span does nothing
ἔρως
ἔρως2w ago
why don't you use a table?
LJ
LJ2w ago
i say in the OP. i get tabs instead of newlines
ἔρως
ἔρως2w ago
how about you remove the spans and use the html entity for the spaces?
LJ
LJ2w ago
what   ? or whatever it is. i've not used numeric entities in a while
ἔρως
ἔρως2w ago
yes, that or something like that
LJ
LJ2w ago
no, whitespace becomes insignificant then.
ἔρως
ἔρως2w ago
then can you re-create the table solution?
LJ
LJ2w 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.
ἔρως
ἔρως2w ago
you're still setting the td to be inline-flex which makes it into inline elements
LJ
LJ2w 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
ἔρως
ἔρως2w ago
don't touch the display i have an almost-working solution
LJ
LJ2w ago
the clipboard behavior of inline is mutually exclusive with being able to center the glyph
ἔρως
ἔρως2w ago
correction
LJ
LJ2w ago
table has a weird line-height behavior i had to work around >_>
ἔρως
ἔρως2w ago
I HAVE a working solution
LJ
LJ2w ago
ooOOOoo
ἔρως
ἔρως2w ago
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
LJ
LJ2w ago
that does not meet my 2nd requirement
ἔρως
ἔρως2w ago
what is it?
ἔρως
ἔρως2w ago
it works
No description
LJ
LJ2w ago
per OP:
The emojis must be centered within their text cells. (If this wasn't a requirement, I'd be done by now.)
ἔρως
ἔρως2w ago
they are
LJ
LJ2w ago
what browser?
ἔρως
ἔρως2w ago
chrome
LJ
LJ2w ago
do you have a screenshot?
ἔρως
ἔρως2w ago
of what?
LJ
LJ2w ago
No description
ἔρως
ἔρως2w ago
this?
No description
LJ
LJ2w ago
that is wrong. those are not centered within their individual cells
ἔρως
ἔρως2w ago
alright, let me start over
LJ
LJ2w 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
ἔρως
ἔρως2w ago
it is, but i have a solution for the first one
LJ
LJ2w 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
ἔρως
ἔρως2w ago
my solution is almost working
LJ
LJ2w ago
i've been almost working for well over two hours, amid unrelated youtube videos
ἔρως
ἔρως2w ago
how about using svg to center the icon?
LJ
LJ2w 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 ; )
ἔρως
ἔρως2w ago
that's what made it work 90% of the way
LJ
LJ2w 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.
ἔρως
ἔρως2w ago
because it's handled as a block element
LJ
LJ2w 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.
ἔρως
ἔρως2w 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
LJ2w ago
not everything ; )
ἔρως
ἔρως2w ago
if you use text, it only selects the text without any richtext that is, styles and stuff
LJ
LJ2w ago
in your example, if you give td the style display: inline-flex; it looks right but still copies wrong
ἔρως
ἔρως2w ago
yeah, because flex requires it's children to be treated as blocks and not as inline
LJ
LJ2w ago
i'm wondering if i can get grid to do my bidding. grid is new to me. is flex slightly older?
ἔρως
ἔρως2w ago
both are kinda somewhat the same age i say grid but the same happens to flex every child has to be a block