Skip to content

Commit

Permalink
馃毟 (buttons) Better multiple item parsing
Browse files Browse the repository at this point in the history
Instead of using the clipboard, we directly detect pasting in the onChange handler
  • Loading branch information
baptisteArno committed Feb 16, 2024
1 parent 5d0be9e commit 07240e6
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const ButtonsItemNode = ({ item, indices, isMouseOver }: Props) => {
itemValue !== t('blocks.inputs.button.clickToEdit.label')
)
handlePlusClick()
if (e.key === 'v' && (e.ctrlKey || e.metaKey)) {
const clipboardContents = await navigator.clipboard.read()
const item = clipboardContents[0]
if (!item.types.includes('text/plain')) return
const text = await (await item.getType('text/plain')).text()
if (!text || !text.includes(',')) return
const values = text.split(',')
}

const handleEditableChange = (val: string) => {
const isPastingMultipleItems =
val.length - itemValue.length > 1 && val.includes(',')
if (isPastingMultipleItems) {
const values = val.split(',')
return values.forEach((v, i) => {
if (i === 0) {
setItemValue(v)
Expand All @@ -80,6 +80,7 @@ export const ButtonsItemNode = ({ item, indices, isMouseOver }: Props) => {
}
})
}
setItemValue(val)
}

const handlePlusClick = () => {
Expand All @@ -105,7 +106,7 @@ export const ButtonsItemNode = ({ item, indices, isMouseOver }: Props) => {
flex="1"
startWithEditView={isNotDefined(item.content)}
value={itemValue}
onChange={setItemValue}
onChange={handleEditableChange}
onSubmit={handleInputSubmit}
onKeyDownCapture={handleKeyPress}
maxW="180px"
Expand Down

0 comments on commit 07240e6

Please sign in to comment.