prevent escape from undoing text change

This commit is contained in:
Steve Ruiz 2022-07-03 18:44:16 +01:00
parent 7028877699
commit 1c753b73ac
3 changed files with 19 additions and 4 deletions

View file

@ -84,7 +84,12 @@ export class StickyUtil extends TDShapeUtil<T, E> {
const handleKeyDown = React.useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Escape') return
if (e.key === 'Escape') {
e.preventDefault()
e.stopPropagation()
onShapeBlur?.()
return
}
if (e.key === 'Tab' && shape.text.length === 0) {
e.preventDefault()

View file

@ -131,7 +131,12 @@ export class TextUtil extends TDShapeUtil<T, E> {
const handleKeyDown = React.useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Escape') return
if (e.key === 'Escape') {
e.preventDefault()
e.stopPropagation()
onShapeBlur?.()
return
}
if (e.key === 'Tab' && shape.text.length === 0) {
e.preventDefault()

View file

@ -1,6 +1,6 @@
import * as React from 'react'
import { stopPropagation } from '~components/stopPropagation'
import { GHOSTED_OPACITY, LETTER_SPACING } from '~constants'
import { GHOSTED_OPACITY, LETTER_SPACING } from '~constants'
import { TLDR } from '~state/TLDR'
import { styled } from '~styles'
import { getTextLabelSize } from './getTextSize'
@ -40,7 +40,12 @@ export const TextLabel = React.memo(function TextLabel({
)
const handleKeyDown = React.useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Escape') return
if (e.key === 'Escape') {
e.preventDefault()
e.stopPropagation()
onBlur?.()
return
}
if (e.key === 'Tab' && text.length === 0) {
e.preventDefault()