@@ -85,26 +85,32 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal): void {
85
85
* @param ev The original right click event to be handled.
86
86
* @param textarea The terminal's textarea.
87
87
*/
88
- export function moveTextAreaUnderMouseCursor ( ev : MouseEvent , textarea : HTMLTextAreaElement ) : void {
88
+ export function moveTextAreaUnderMouseCursor ( ev : MouseEvent , term : ITerminal ) : void {
89
+
90
+ // Calculate textarea position relative to the screen element
91
+ const pos = term . screenElement . getBoundingClientRect ( ) ;
92
+ const left = ev . clientX - pos . left - 10 ;
93
+ const top = ev . clientY - pos . top - 10 ;
94
+
89
95
// Bring textarea at the cursor position
90
- textarea . style . position = 'fixed ' ;
91
- textarea . style . width = '20px' ;
92
- textarea . style . height = '20px' ;
93
- textarea . style . left = ( ev . clientX - 10 ) + 'px' ;
94
- textarea . style . top = ( ev . clientY - 10 ) + 'px' ;
95
- textarea . style . zIndex = '1000' ;
96
+ term . textarea . style . position = 'absolute ' ;
97
+ term . textarea . style . width = '20px' ;
98
+ term . textarea . style . height = '20px' ;
99
+ term . textarea . style . left = ` ${ left } px` ;
100
+ term . textarea . style . top = ` ${ top } px` ;
101
+ term . textarea . style . zIndex = '1000' ;
96
102
97
- textarea . focus ( ) ;
103
+ term . textarea . focus ( ) ;
98
104
99
105
// Reset the terminal textarea's styling
100
106
// Timeout needs to be long enough for click event to be handled.
101
107
setTimeout ( ( ) => {
102
- textarea . style . position = null ;
103
- textarea . style . width = null ;
104
- textarea . style . height = null ;
105
- textarea . style . left = null ;
106
- textarea . style . top = null ;
107
- textarea . style . zIndex = null ;
108
+ term . textarea . style . position = null ;
109
+ term . textarea . style . width = null ;
110
+ term . textarea . style . height = null ;
111
+ term . textarea . style . left = null ;
112
+ term . textarea . style . top = null ;
113
+ term . textarea . style . zIndex = null ;
108
114
} , 200 ) ;
109
115
}
110
116
@@ -115,14 +121,14 @@ export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextA
115
121
* @param selectionManager The terminal's selection manager.
116
122
* @param shouldSelectWord If true and there is no selection the current word will be selected
117
123
*/
118
- export function rightClickHandler ( ev : MouseEvent , textarea : HTMLTextAreaElement , selectionManager : ISelectionManager , shouldSelectWord : boolean ) : void {
119
- moveTextAreaUnderMouseCursor ( ev , textarea ) ;
124
+ export function rightClickHandler ( ev : MouseEvent , term : ITerminal , selectionManager : ISelectionManager , shouldSelectWord : boolean ) : void {
125
+ moveTextAreaUnderMouseCursor ( ev , term ) ;
120
126
121
127
if ( shouldSelectWord && ! selectionManager . isClickInSelection ( ev ) ) {
122
128
selectionManager . selectWordAtCursor ( ev ) ;
123
129
}
124
130
125
131
// Get textarea ready to copy from the context menu
126
- textarea . value = selectionManager . selectionText ;
127
- textarea . select ( ) ;
132
+ term . textarea . value = selectionManager . selectionText ;
133
+ term . textarea . select ( ) ;
128
134
}
0 commit comments