Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

Detect facets when composer is opened with mention (#9625)

* highlight the initial mention

* fix mention initalisation on web

authored by

Samuel Newman and committed by
GitHub
1eb09b72 ee99320e

+34 -1
+3
src/view/com/composer/state/composer.ts
··· 670 670 } 671 671 } 672 672 } 673 + } else if (initMention) { 674 + // highlight the mention 675 + initRichText.detectFacetsWithoutResolution() 673 676 } 674 677 675 678 return {
+31 -1
src/view/com/composer/text-input/TextInput.web.tsx
··· 241 241 } 242 242 }, 243 243 }, 244 - content: generateJSON(richtext.text.toString(), extensions, { 244 + content: generateJSON(richTextToHTML(richtext), extensions, { 245 245 preserveWhitespace: 'full', 246 246 }), 247 247 autofocus: 'end', ··· 380 380 )} 381 381 </> 382 382 ) 383 + } 384 + 385 + /** 386 + * Helper function to initialise the editor with RichText, which expects HTML 387 + * 388 + * All the extensions are able to initialise themselves from plain text, *except* 389 + * for the Mention extension - we need to manually convert it into a `<span>` element 390 + * 391 + * It also escapes HTML characters 392 + */ 393 + function richTextToHTML(richtext: RichText): string { 394 + let html = '' 395 + 396 + for (const segment of richtext.segments()) { 397 + if (segment.mention) { 398 + html += `<span data-type="mention" data-id="${escapeHTML(segment.mention.did)}"></span>` 399 + } else { 400 + html += escapeHTML(segment.text) 401 + } 402 + } 403 + 404 + return html 405 + } 406 + 407 + function escapeHTML(str: string): string { 408 + return str 409 + .replace(/&/g, '&amp;') 410 + .replace(/</g, '&lt;') 411 + .replace(/>/g, '&gt;') 412 + .replace(/"/g, '&quot;') 383 413 } 384 414 385 415 function editorJsonToText(