@@ -33,8 +33,6 @@ export class SelectionController {
3333 private focusScopeEls : HTMLElement [ ] ;
3434 private storedSelection : StoredSelection | null = null ;
3535 private storedToken : string | null = null ;
36- /** Signature of a selection whose chip was sent or removed; never auto-appended again. */
37- private consumedSignature : string | null = null ;
3836 private syncingToken = false ;
3937 private inputHandoffGraceUntil : number | null = null ;
4038 private pollInterval : number | null = null ;
@@ -133,13 +131,6 @@ export class SelectionController {
133131 const notePath = view . file ?. path || 'unknown' ;
134132 const lineCount = selectedText . split ( / \r ? \n / ) . length ;
135133
136- if (
137- ! this . storedSelection
138- && this . consumedSignature === this . selectionSignature ( { notePath, from, to, selectedText } )
139- ) {
140- return ;
141- }
142-
143134 const s = this . storedSelection ;
144135 const sameRange = s
145136 && s . editorView === editorView
@@ -189,13 +180,6 @@ export class SelectionController {
189180 const lineCount = selectedText . split ( / \r ? \n / ) . length ;
190181 const domRanges = this . cloneDOMRanges ( selection ) ;
191182
192- if (
193- ! this . storedSelection
194- && this . consumedSignature === this . selectionSignature ( { notePath, selectedText } )
195- ) {
196- return ;
197- }
198-
199183 const unchanged = this . storedSelection
200184 && this . storedSelection . editorView === undefined
201185 && this . storedSelection . notePath === notePath
@@ -403,17 +387,6 @@ export class SelectionController {
403387 // Token Sync
404388 // ============================================
405389
406- /** Identifies a selection so a sent/removed one is not re-appended while it persists. */
407- private selectionSignature ( sel : {
408- notePath : string ;
409- from ?: number ;
410- to ?: number ;
411- selectedText : string ;
412- } ) : string {
413- const range = sel . from === undefined ? 'dom' : `${ sel . from } -${ sel . to } ` ;
414- return `${ sel . notePath } :${ range } :${ sel . selectedText } ` ;
415- }
416-
417390 private currentToken ( ) : { token : string ; reference : SelectionTokenReference } | null {
418391 const sel = this . storedSelection ;
419392 if ( ! sel ) return null ;
@@ -441,10 +414,6 @@ export class SelectionController {
441414 const nextToken = next ?. token ?? null ;
442415 if ( nextToken === this . storedToken ) return ;
443416
444- if ( nextToken && this . storedSelection ) {
445- // A changed selection is a fresh intent; forget any consumed marker.
446- this . consumedSignature = null ;
447- }
448417 this . syncingToken = true ;
449418 try {
450419 const previous = this . storedToken ;
@@ -469,11 +438,6 @@ export class SelectionController {
469438 if ( this . storedToken ) {
470439 if ( ! value . includes ( this . storedToken ) ) {
471440 const stale = this . storedToken ;
472- // The chip left the text (sent or deleted): remember the selection so
473- // the still-active editor highlight does not immediately re-append it.
474- if ( this . storedSelection ) {
475- this . consumedSignature = this . selectionSignature ( this . storedSelection ) ;
476- }
477441 this . storedToken = null ;
478442 this . storedSelection = null ;
479443 this . tokenSink . unregister ( stale ) ;
@@ -515,11 +479,25 @@ export class SelectionController {
515479 // Clear
516480 // ============================================
517481
482+ /**
483+ * Collapses the editor selection after a turn is sent. The chip travels with
484+ * the message, and without this the still-active highlight would immediately
485+ * re-append it to the now-empty composer.
486+ */
487+ releaseSelectionAfterSend ( ) : void {
488+ const sel = this . storedSelection ;
489+ if ( sel ?. editorView ) {
490+ sel . editorView . dispatch ( { selection : { anchor : sel . from ?? 0 } } ) ;
491+ } else if ( sel ) {
492+ this . getFocusScopeOwnerDocument ( ) ?. getSelection ( ) ?. removeAllRanges ( ) ;
493+ }
494+ this . clear ( ) ;
495+ }
496+
518497 clear ( ) : void {
519498 this . inputHandoffGraceUntil = null ;
520499 this . clearHighlight ( ) ;
521500 this . storedSelection = null ;
522- this . consumedSignature = null ;
523501 this . syncTokenFromStored ( ) ;
524502 }
525503}
0 commit comments