discourse/plugins/chat/assets/javascripts/discourse
Régis Hanol 7bb363b4cb
FIX: preserve selection formatting in link-insertion modal (#39374)
When CMD+K is pressed (or the link toolbar button clicked) with a
non-empty selection, the modal now only asks for the URL — the existing
selection is wrapped as the link's display content, keeping every inline
mark and block context under it.

Previously the modal pre-filled a "Link text" field from the selection.
In the rich-text editor this serialized the selected slice to markdown
and leaked syntax the user never typed: selecting a word inside an H2
produced `## word`, selecting text inside an inline code span produced
backticks, selecting inside a list produced `- word`, and so on.

The new behavior wraps the selection directly instead of replacing it:

- Rich-text editor: adds a `link` mark over the selection range,
preserving every underlying mark (bold, italic, code, emoji, mentions,
…) and every surrounding block (heading, list, blockquote, …).
- Markdown editor: inserts `[` at the selection start and `](url)` at
the end, preserving any literal characters in between.

Both editors now behave identically for the common "select then link"
flow. The link-text field is still shown when:

- Inserting a link with no selection (the user needs to provide display
text).
- Editing an existing link via the link-toolbar (the user may want to
change the displayed text).

A small `applyLink(url)` method is exposed on the text-manipulation API
of each editor, and `toolbarEvent.applyLink` lets the modal pick the
right path without knowing which editor is active. The chat composer is
wired through the same path.

Ref - t/182095
2026-05-20 11:22:35 +02:00
..
adapters
components FIX: preserve selection formatting in link-insertion modal (#39374) 2026-05-20 11:22:35 +02:00
connectors DEV: Consolidate reusable components into ui-kit (#38703) 2026-05-11 18:07:36 -03:00
controllers FEATURE: extend chat/new-message with prefilling text api (#40007) 2026-05-18 13:43:39 -03:00
helpers DEV: Rename htmlSafe to trustHTML from @ember/template (#38465) 2026-03-11 18:57:22 -03:00
initializers PERF: Skip extraneous requests in full app embed mode (#39295) 2026-04-15 17:17:35 -03:00
lib FIX: preserve selection formatting in link-insertion modal (#39374) 2026-05-20 11:22:35 +02:00
models DEV: Migrate to @ember/reactive/collections (#38221) 2026-03-23 17:44:41 -03:00
modifiers/chat DEV: revert long press changes (#32668) 2025-05-09 18:58:42 +02:00
pre-initializers DEV: Add page-aware plugin APIs for saving user preferences (#36757) 2025-12-18 10:58:16 +01:00
routes FEATURE: extend chat/new-message with prefilling text api (#40007) 2026-05-18 13:43:39 -03:00
services FIX: Routing from chat in subfolder setups (#39609) 2026-04-28 12:47:36 -04:00
templates DEV: Consolidate reusable components into ui-kit (#38703) 2026-05-11 18:07:36 -03:00
admin-chat-route-map.js UX: Hide admin header for edit/new webhook (#30194) 2024-12-12 10:49:17 +11:00
chat-route-map.js FEATURE: Pin chat messages (#37985) 2026-02-23 22:00:16 +01:00
preferences-chat-route-map.js