@@ -51,6 +51,7 @@ export class SelectionManager {
5151 // Store bound event handlers for cleanup
5252 private boundMouseUpHandler : ( ( e : MouseEvent ) => void ) | null = null ;
5353 private boundContextMenuHandler : ( ( e : MouseEvent ) => void ) | null = null ;
54+ private boundClickHandler : ( ( e : MouseEvent ) => void ) | null = null ;
5455
5556 constructor (
5657 terminal : Terminal ,
@@ -291,6 +292,12 @@ export class SelectionManager {
291292 this . boundContextMenuHandler = null ;
292293 }
293294
295+ // Clean up document click listener
296+ if ( this . boundClickHandler ) {
297+ document . removeEventListener ( 'click' , this . boundClickHandler ) ;
298+ this . boundClickHandler = null ;
299+ }
300+
294301 // Canvas event listeners will be cleaned up when canvas is removed from DOM
295302 }
296303
@@ -444,6 +451,21 @@ export class SelectionManager {
444451 } ;
445452
446453 canvas . addEventListener ( 'contextmenu' , this . boundContextMenuHandler ) ;
454+
455+ // Click outside canvas - clear selection
456+ // This allows users to deselect by clicking anywhere outside the terminal
457+ this . boundClickHandler = ( e : MouseEvent ) => {
458+ // Check if the click is outside the canvas
459+ const target = e . target as Node ;
460+ if ( ! canvas . contains ( target ) ) {
461+ // Clicked outside the canvas - clear selection
462+ if ( this . hasSelection ( ) ) {
463+ this . clearSelection ( ) ;
464+ }
465+ }
466+ } ;
467+
468+ document . addEventListener ( 'click' , this . boundClickHandler ) ;
447469 }
448470
449471 /**
0 commit comments