Skip to content

Commit d53ae26

Browse files
Merge branch 'anxious-kangaroo' into Main
2 parents ff250e9 + c0b1595 commit d53ae26

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/vs/editor/browser/controller/editContext/native/nativeEditContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class NativeEditContext extends AbstractEditContext {
252252
}
253253

254254
public isFocused(): boolean {
255-
return this._focusTracker.isFocused || (getActiveWindow().document.activeElement === this.textArea.domNode);
255+
return this._focusTracker.isFocused;
256256
}
257257

258258
public focus(): void {

src/vs/editor/browser/controller/editContext/native/nativeEditContextUtils.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { addDisposableListener, getActiveWindow } from '../../../../../base/browser/dom.js';
6+
import { addDisposableListener, getActiveElement, getShadowRoot } from '../../../../../base/browser/dom.js';
77
import { IDisposable, Disposable } from '../../../../../base/common/lifecycle.js';
88

99
export interface ITypeData {
@@ -21,8 +21,12 @@ export class FocusTracker extends Disposable {
2121
private readonly _onFocusChange: (newFocusValue: boolean) => void,
2222
) {
2323
super();
24-
this._register(addDisposableListener(this._domNode, 'focus', () => this._handleFocusedChanged(true)));
25-
this._register(addDisposableListener(this._domNode, 'blur', () => this._handleFocusedChanged(false)));
24+
this._register(addDisposableListener(this._domNode, 'focus', () => {
25+
this.refreshFocusState();
26+
}));
27+
this._register(addDisposableListener(this._domNode, 'blur', () => {
28+
this._handleFocusedChanged(false);
29+
}));
2630
}
2731

2832
private _handleFocusedChanged(focused: boolean): void {
@@ -34,15 +38,19 @@ export class FocusTracker extends Disposable {
3438
}
3539

3640
public focus(): void {
37-
// fixes: https://github.com/microsoft/vscode/issues/228147
38-
// Immediately call this method in order to directly set the field isFocused to true so the textInputFocus context key is evaluated correctly
39-
this._handleFocusedChanged(true);
4041
this._domNode.focus();
42+
this.refreshFocusState();
4143
}
4244

4345
public refreshFocusState(): void {
44-
const focused = this._domNode === getActiveWindow().document.activeElement;
45-
this._handleFocusedChanged(focused);
46+
let activeElement: Element | null = null;
47+
const shadowRoot = getShadowRoot(this._domNode);
48+
if (shadowRoot) {
49+
activeElement = shadowRoot.activeElement;
50+
} else {
51+
activeElement = getActiveElement();
52+
}
53+
this._handleFocusedChanged(activeElement === this._domNode);
4654
}
4755

4856
get isFocused(): boolean {

0 commit comments

Comments
 (0)