fix: multiline text shape

This commit is contained in:
Peng Xiao
2022-08-24 23:24:42 +08:00
parent 134d7bf7dd
commit b2048358bf
3 changed files with 31 additions and 31 deletions

View File

@@ -424,6 +424,7 @@ const TextStyleAction = observer(() => {
shape.update({
fontWeight: v ? 700 : 400,
})
shape.onResetBounds()
})
app.persist()
}}
@@ -439,6 +440,7 @@ const TextStyleAction = observer(() => {
shape.update({
italic: v,
})
shape.onResetBounds()
})
app.persist()
}}

View File

@@ -6,6 +6,7 @@ import { observer } from 'mobx-react-lite'
import * as React from 'react'
import type { SizeLevel } from '~lib'
import { CustomStyleProps, withClampedStyles } from './style-props'
import { TextAreaUtils } from './text/TextAreaUtils'
export interface TextShapeProps extends TLTextShapeProps, CustomStyleProps {
borderRadius: number
@@ -87,39 +88,35 @@ export class TextShape extends TLTextShape<TextShapeProps> {
}, [])
const handleKeyDown = React.useCallback((e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.metaKey) e.stopPropagation()
switch (e.key) {
case 'Meta': {
e.stopPropagation()
break
if (e.key === 'Escape') return
if (e.key === 'Tab' && text.length === 0) {
e.preventDefault()
return
}
if (!(e.key === 'Meta' || e.metaKey)) {
e.stopPropagation()
} else if (e.key === 'z' && e.metaKey) {
if (e.shiftKey) {
document.execCommand('redo', false)
} else {
document.execCommand('undo', false)
}
case 'z': {
if (e.metaKey) {
if (e.shiftKey) {
document.execCommand('redo', false)
} else {
document.execCommand('undo', false)
}
e.preventDefault()
}
break
}
case 'Enter': {
if (e.ctrlKey || e.metaKey) {
e.currentTarget.blur()
}
break
}
case 'Tab': {
e.preventDefault()
if (e.shiftKey) {
TextUtils.unindent(e.currentTarget)
} else {
TextUtils.indent(e.currentTarget)
}
this.update({ text: TextUtils.normalizeText(e.currentTarget.value) })
break
e.stopPropagation()
e.preventDefault()
return
}
if (e.key === 'Tab') {
e.preventDefault()
if (e.shiftKey) {
TextAreaUtils.unindent(e.currentTarget)
} else {
TextAreaUtils.indent(e.currentTarget)
}
this.update({ text: TextUtils.normalizeText(e.currentTarget.value) })
}
}, [])

View File

@@ -347,6 +347,7 @@ button.tl-select-input-trigger {
font-family: inherit;
font-size: inherit;
font-variant: inherit;
font-style: inherit;
text-align: inherit;
min-height: inherit;
min-width: inherit;