Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove unnecessary `.trimEnd()` and fix facet detection (#3672)

* Fix link facet detection

Exclude the trailing period from the link, similar as done in the atproto package

* Fix JSON to text conversion

The trimEnd() call was only needed because we were always appending \n\n at the end. Fix that by only adding line breaks after non-final paragraphs.

* Detect paste reliably

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>

authored by

Hailey
Dan Abramov
and committed by
GitHub
b3df0b17 05beb1bb

+23 -12
+20 -9
src/view/com/composer/text-input/TextInput.web.tsx
··· 61 61 ref, 62 62 ) { 63 63 const autocomplete = useActorAutocompleteFn() 64 - const prevLength = React.useRef(0) 65 64 const prevAddedLinks = useRef(new Set<string>()) 66 65 67 66 const pal = usePalette('default') ··· 185 184 }, 186 185 onUpdate({editor: editorProp}) { 187 186 const json = editorProp.getJSON() 188 - const newText = editorJsonToText(json).trimEnd() 189 - const mayBePaste = newText.length > prevLength.current + 1 187 + const newText = editorJsonToText(json) 188 + const mayBePaste = window.event?.type === 'paste' 190 189 191 190 const newRt = new RichText({text: newText}) 192 191 newRt.detectFacetsWithoutResolution() ··· 219 218 prevAddedLinks.current.delete(uri) 220 219 } 221 220 } 222 - 223 - prevLength.current = newText.length 224 221 }, 225 222 }, 226 223 [modeClass], ··· 277 274 ) 278 275 }) 279 276 280 - function editorJsonToText(json: JSONContent): string { 277 + function editorJsonToText( 278 + json: JSONContent, 279 + isLastDocumentChild: boolean = false, 280 + ): string { 281 281 let text = '' 282 - if (json.type === 'doc' || json.type === 'paragraph') { 282 + if (json.type === 'doc') { 283 283 if (json.content?.length) { 284 - for (const node of json.content) { 284 + for (let i = 0; i < json.content.length; i++) { 285 + const node = json.content[i] 286 + const isLastNode = i === json.content.length - 1 287 + text += editorJsonToText(node, isLastNode) 288 + } 289 + } 290 + } else if (json.type === 'paragraph') { 291 + if (json.content?.length) { 292 + for (let i = 0; i < json.content.length; i++) { 293 + const node = json.content[i] 285 294 text += editorJsonToText(node) 286 295 } 287 296 } 288 - text += '\n' 297 + if (!isLastDocumentChild) { 298 + text += '\n' 299 + } 289 300 } else if (json.type === 'hardBreak') { 290 301 text += '\n' 291 302 } else if (json.type === 'text') {
+3 -3
src/view/com/composer/text-input/web/LinkDecorator.ts
··· 14 14 * the facet-set. 15 15 */ 16 16 17 + import {URL_REGEX} from '@atproto/api' 17 18 import {Mark} from '@tiptap/core' 18 - import {Plugin, PluginKey} from '@tiptap/pm/state' 19 19 import {Node as ProsemirrorNode} from '@tiptap/pm/model' 20 + import {Plugin, PluginKey} from '@tiptap/pm/state' 20 21 import {Decoration, DecorationSet} from '@tiptap/pm/view' 21 - import {URL_REGEX} from '@atproto/api' 22 22 23 23 import {isValidDomain} from 'lib/strings/url-helpers' 24 24 ··· 91 91 uri = `https://${uri}` 92 92 } 93 93 let from = str.indexOf(match[2], match.index) 94 - let to = from + match[2].length + 1 94 + let to = from + match[2].length 95 95 // strip ending puncuation 96 96 if (/[.,;!?]$/.test(uri)) { 97 97 uri = uri.slice(0, -1)