5
5
6
6
import type { Event } from 'vs/base/common/event' ;
7
7
import type { IDisposable } from 'vs/base/common/lifecycle' ;
8
- import * as webviewMessages from 'vs/workbench/contrib/notebook/browser/view/renderers/webviewMessages' ;
8
+ import type * as webviewMessages from 'vs/workbench/contrib/notebook/browser/view/renderers/webviewMessages' ;
9
9
import type { NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
10
10
import type * as rendererApi from 'vscode-notebook-renderer' ;
11
11
@@ -94,6 +94,8 @@ async function webviewPreloads(ctx: PreloadContext) {
94
94
let currentRenderOptions = ctx . renderOptions ;
95
95
const settingChange : EmitterLike < RenderOptions > = createEmitter < RenderOptions > ( ) ;
96
96
97
+ let isInputElementFocused : boolean | undefined = undefined ;
98
+
97
99
const acquireVsCodeApi = globalThis . acquireVsCodeApi ;
98
100
const vscode = acquireVsCodeApi ( ) ;
99
101
delete ( globalThis as any ) . acquireVsCodeApi ;
@@ -138,16 +140,19 @@ async function webviewPreloads(ctx: PreloadContext) {
138
140
} ;
139
141
140
142
// check if an input element is focused within the output element
141
- const handleOutputFocus = ( ) => {
143
+ const checkOutputInputFocus = ( ) => {
144
+
142
145
const activeElement = document . activeElement ;
143
146
if ( ! activeElement ) {
144
147
return ;
145
148
}
146
149
147
- if ( activeElement . tagName === 'INPUT' || activeElement . tagName === 'TEXTAREA' ) {
150
+ isInputElementFocused = ! ! activeElement && ( activeElement . tagName === 'INPUT' || activeElement . tagName === 'TEXTAREA' ) ;
151
+
152
+ if ( isInputElementFocused ) {
148
153
postNotebookMessage < webviewMessages . IOutputInputFocusMessage > ( 'outputInputFocus' , { hasFocus : true } ) ;
149
154
150
- activeElement . addEventListener ( 'blur ' , ( ) => {
155
+ activeElement . addEventListener ( 'onblur ' , ( ) => {
151
156
postNotebookMessage < webviewMessages . IOutputInputFocusMessage > ( 'outputInputFocus' , { hasFocus : false } ) ;
152
157
} , { once : true } ) ;
153
158
}
@@ -158,7 +163,7 @@ async function webviewPreloads(ctx: PreloadContext) {
158
163
return ;
159
164
}
160
165
161
- handleOutputFocus ( ) ;
166
+ checkOutputInputFocus ( ) ;
162
167
163
168
for ( const node of event . composedPath ( ) ) {
164
169
if ( node instanceof HTMLElement && node . classList . contains ( 'output' ) ) {
@@ -240,7 +245,6 @@ async function webviewPreloads(ctx: PreloadContext) {
240
245
} ;
241
246
242
247
document . body . addEventListener ( 'click' , handleInnerClick ) ;
243
- document . body . addEventListener ( 'focusin' , handleOutputFocus ) ;
244
248
245
249
interface RendererContext extends rendererApi . RendererContext < unknown > {
246
250
readonly onDidChangeSettings : Event < RenderOptions > ;
0 commit comments