Revert "perf(desktop): use textContent for trigger precondition"
This reverts commit a6a78ff08a.
This commit is contained in:
@@ -408,13 +408,13 @@ export function ChatBar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fast-bail: if neither `@` nor `/` appears in the current draft, there's
|
// Fast-bail: if neither `@` nor `/` appears in the current draft, there's
|
||||||
// nothing for `detectTrigger` to match. Use `textContent` (cheap browser-
|
// nothing for `detectTrigger` to match. Skip the DOM range walk inside
|
||||||
// native walk) for the precondition check rather than `composerPlainText`
|
// `textBeforeCaret` (which calls `range.toString()`, O(n) over the draft)
|
||||||
// (recursive child walk with chip-aware logic). Only when a trigger char
|
// and the regex pass that follows. Only when a relevant char is present
|
||||||
// is present do we pay the cost of the full walk + DOM range work.
|
// do we pay the cost.
|
||||||
const rawText = editor.textContent ?? ''
|
const text = composerPlainText(editor)
|
||||||
|
|
||||||
if (!rawText.includes('@') && !rawText.includes('/')) {
|
if (!text.includes('@') && !text.includes('/')) {
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
setTrigger(null)
|
setTrigger(null)
|
||||||
setTriggerActive(0)
|
setTriggerActive(0)
|
||||||
@@ -424,7 +424,7 @@ export function ChatBar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const before = textBeforeCaret(editor)
|
const before = textBeforeCaret(editor)
|
||||||
const detected = detectTrigger(before ?? composerPlainText(editor))
|
const detected = detectTrigger(before ?? text)
|
||||||
|
|
||||||
setTrigger(detected)
|
setTrigger(detected)
|
||||||
setTriggerActive(0)
|
setTriggerActive(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user