Skip to content

Commit dafa06b

Browse files
committed
Group keyboard and contenteditable pasting into one bullet point
1 parent 9182850 commit dafa06b

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

index.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
var __toESM = (mod, isNodeMode, target) => (
3434
(target = mod != null ? __create(__getProtoOf(mod)) : {}),
3535
__copyProps(
36+
// If the importer is in node compatibility mode or this is not an ESM
37+
// file that has been converted to a CommonJS file using a Babel-
38+
// compatible transform (i.e. "__esModule" has not been set), then set
39+
// "default" to the CommonJS "module.exports" for node compatibility.
3640
isNodeMode || !mod || !mod.__esModule
3741
? __defProp(target, 'default', { value: mod, enumerable: true })
3842
: target,
@@ -10309,6 +10313,13 @@
1030910313
render(data2, 'ClipboardItems');
1031010314
});
1031110315
}, []);
10316+
const autoselect = (0, import_react.useCallback)(e => {
10317+
const range = document.createRange();
10318+
range.selectNodeContents(e.target);
10319+
const selection = window.getSelection();
10320+
selection.removeAllRanges();
10321+
selection.addRange(range);
10322+
}, []);
1031210323
function render_file(file) {
1031310324
return file
1031410325
? /* @__PURE__ */ import_react.default.createElement(
@@ -10446,23 +10457,20 @@
1044610457
'\u2318V'
1044710458
),
1044810459
' ',
10449-
'keyboard shortcut'
10460+
'keyboard shortcut or',
10461+
' ',
10462+
/* @__PURE__ */ import_react.default.createElement(
10463+
'span',
10464+
{ contentEditable: true, onFocus: autoselect },
10465+
'paste in here'
10466+
),
10467+
' ',
10468+
"if you don't have a keyboard"
1045010469
),
1045110470
/* @__PURE__ */ import_react.default.createElement(
1045210471
'li',
1045310472
null,
1045410473
'Drop something on the page'
10455-
),
10456-
/* @__PURE__ */ import_react.default.createElement(
10457-
'li',
10458-
null,
10459-
/* @__PURE__ */ import_react.default.createElement(
10460-
'span',
10461-
{ contentEditable: true, class: 'editable' },
10462-
'Paste using context menu'
10463-
),
10464-
' ',
10465-
'if you are on mobile.'
1046610474
)
1046710475
)
1046810476
);

index.jsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ function ClipboardInspector(props) {
8888
});
8989
}, []);
9090

91+
const autoselect = useCallback(e => {
92+
const range = document.createRange();
93+
range.selectNodeContents(e.target);
94+
const selection = window.getSelection();
95+
selection.removeAllRanges();
96+
selection.addRange(range);
97+
}, []);
98+
9199
function render_file(file) {
92100
return file ? (
93101
<table>
@@ -145,15 +153,13 @@ function ClipboardInspector(props) {
145153
</li>
146154
<li>
147155
Paste with the <kbd>Ctrl+V</kbd> / <kbd>⌘V</kbd>{' '}
148-
keyboard shortcut
149-
</li>
150-
<li>Drop something on the page</li>
151-
<li>
152-
<span contentEditable class="editable">
153-
Paste using context menu
156+
keyboard shortcut or{' '}
157+
<span contentEditable onFocus={autoselect}>
158+
paste in here
154159
</span>{' '}
155-
if you are on mobile.
160+
if you don't have a keyboard
156161
</li>
162+
<li>Drop something on the page</li>
157163
</ul>
158164
</div>
159165
);

style.css

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,33 @@ body {
2020
input,
2121
select,
2222
textarea,
23-
button {
23+
button,
24+
[contenteditable] {
2425
font: inherit;
2526
font-size: max(1em, 16px);
2627
}
2728

28-
button,
29-
.editable {
29+
button {
3030
appearance: none;
3131
border: 0.1em solid;
32-
display: inline-block;
3332
padding: 0.25em 0.5em;
3433
background: #f3f3f3;
3534
color: #000;
3635
white-space: nowrap;
3736
box-shadow: 0.1em 0.1em currentColor;
3837
}
3938

40-
button:active,
41-
.editable:active {
39+
button:active {
4240
background: #fe0;
4341
}
4442

43+
[contenteditable] {
44+
white-space: nowrap;
45+
padding: 0.25em 0.5em;
46+
border: 1px dotted;
47+
background: #fff;
48+
}
49+
4550
button[disabled] {
4651
color: #777;
4752
cursor: not-allowed;
@@ -76,6 +81,10 @@ pre {
7681
margin: 0;
7782
}
7883

84+
kbd {
85+
border-bottom: 1px dotted;
86+
}
87+
7988
.anno {
8089
font-size: 0.6em;
8190
font-weight: bold;

0 commit comments

Comments
 (0)