Bluesky app fork with some witchin' additions 💫

Fix deletion of composed emojis in web composer (#8829)

authored by

Arturo Fonseca and committed by
GitHub
bfcdb835 6cd7dc0f

+20 -1
+20 -1
src/view/com/composer/text-input/TextInput.web.tsx
··· 13 13 import {generateJSON} from '@tiptap/html' 14 14 import {Fragment, Node, Slice} from '@tiptap/pm/model' 15 15 import {EditorContent, type JSONContent, useEditor} from '@tiptap/react' 16 + import Graphemer from 'graphemer' 16 17 17 18 import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle' 18 19 import {usePalette} from '#/lib/hooks/usePalette' ··· 214 215 } 215 216 } 216 217 }, 217 - handleKeyDown: (_, event) => { 218 + handleKeyDown: (view, event) => { 218 219 if ((event.metaKey || event.ctrlKey) && event.code === 'Enter') { 219 220 textInputWebEmitter.emit('publish') 220 221 return true 222 + } 223 + if (event.code === 'Backspace') { 224 + const isNotSelection = view.state.selection.empty 225 + if (isNotSelection) { 226 + const cursorPosition = view.state.selection.$anchor.pos 227 + const textBefore = view.state.doc.textBetween(0, cursorPosition) 228 + const graphemes = new Graphemer().splitGraphemes(textBefore) 229 + 230 + if (graphemes.length > 0) { 231 + const lastGrapheme = graphemes[graphemes.length - 1] 232 + const deleteFrom = cursorPosition - lastGrapheme.length 233 + editor?.commands.deleteRange({ 234 + from: deleteFrom, 235 + to: cursorPosition, 236 + }) 237 + return true 238 + } 239 + } 221 240 } 222 241 }, 223 242 },