fix: paste unicode (#819)

* fix: paste unicode

* fix unicode

* use html element to unencode

* Move to insertContent

Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
Judicael 2022-07-14 21:30:03 +03:00 committed by GitHub
parent cb00822404
commit 20d4de02c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -1895,11 +1895,10 @@ export class TldrawApp extends StateManager<TDSnapshot> {
const json: {
type: string
shapes: TDShape[]
shapes: (TDShape & { text: string })[]
bindings: TDBinding[]
assets: TDAsset[]
} = JSON.parse(maybeJson)
if (json.type === 'tldr/clipboard') {
this.insertContent(json, { point, select: true })
return

View file

@ -246,6 +246,22 @@ export function insertContent(
}
}
const elm = document.createElement('textarea')
Object.values(after.shapes as Record<string, TDShape>).forEach((shape) => {
if ('text' in shape) {
elm.innerHTML = shape.text
shape.text = elm.value
}
if ('label' in shape) {
elm.innerHTML = shape.label!
shape.label = elm.value
}
})
elm.remove()
return {
id: 'insert',
before: {