Skip to content

Commit 7ee4934

Browse files
authored
Adding logs to determine focus state of NativeEditContext (#260499)
1 parent 55e0109 commit 7ee4934

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import './nativeEditContext.css';
77
import { isFirefox } from '../../../../../base/browser/browser.js';
8-
import { addDisposableListener, getWindow, getWindowId } from '../../../../../base/browser/dom.js';
8+
import { addDisposableListener, getActiveElement, getWindow, getWindowId } from '../../../../../base/browser/dom.js';
99
import { FastDomNode } from '../../../../../base/browser/fastDomNode.js';
1010
import { StandardKeyboardEvent } from '../../../../../base/browser/keyboardEvent.js';
1111
import { KeyCode } from '../../../../../base/common/keyCodes.js';
@@ -100,7 +100,8 @@ export class NativeEditContext extends AbstractEditContext {
100100
overflowGuardContainer.appendChild(this._imeTextArea);
101101
this._parent = overflowGuardContainer.domNode;
102102

103-
this._focusTracker = this._register(new FocusTracker(this.domNode.domNode, (newFocusValue: boolean) => {
103+
this._focusTracker = this._register(new FocusTracker(logService, this.domNode.domNode, (newFocusValue: boolean) => {
104+
logService.trace('NativeEditContext#handleFocusChange : ', newFocusValue);
104105
this._screenReaderSupport.handleFocusChange(newFocusValue);
105106
this._context.viewModel.setHasFocus(newFocusValue);
106107
}));
@@ -310,6 +311,11 @@ export class NativeEditContext extends AbstractEditContext {
310311
this._screenReaderSupport.onWillPaste();
311312
}
312313

314+
public onWillCopy(): void {
315+
this.logService.trace('NativeEditContext#onWillCopy');
316+
this.logService.trace('NativeEditContext#isFocused : ', this.domNode.domNode === getActiveElement());
317+
}
318+
313319
public writeScreenReaderContent(): void {
314320
this._screenReaderSupport.writeScreenReaderContent();
315321
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { addDisposableListener, getActiveElement, getShadowRoot } from '../../../../../base/browser/dom.js';
77
import { IDisposable, Disposable } from '../../../../../base/common/lifecycle.js';
8+
import { ILogService } from '../../../../../platform/log/common/log.js';
89

910
export interface ITypeData {
1011
text: string;
@@ -18,11 +19,13 @@ export class FocusTracker extends Disposable {
1819
private _isPaused: boolean = false;
1920

2021
constructor(
22+
@ILogService _logService: ILogService,
2123
private readonly _domNode: HTMLElement,
2224
private readonly _onFocusChange: (newFocusValue: boolean) => void,
2325
) {
2426
super();
2527
this._register(addDisposableListener(this._domNode, 'focus', () => {
28+
_logService.trace('NativeEditContext.focus');
2629
if (this._isPaused) {
2730
return;
2831
}
@@ -32,6 +35,7 @@ export class FocusTracker extends Disposable {
3235
this.refreshFocusState();
3336
}));
3437
this._register(addDisposableListener(this._domNode, 'blur', () => {
38+
_logService.trace('NativeEditContext.blur');
3539
if (this._isPaused) {
3640
return;
3741
}

src/vs/editor/contrib/clipboard/browser/clipboard.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ function registerExecCommandImpl(target: MultiCommand | undefined, browserComman
213213
}
214214
// TODO this is very ugly. The entire copy/paste/cut system needs a complete refactoring.
215215
if (focusedEditor.getOption(EditorOption.effectiveEditContext) && browserCommand === 'cut') {
216+
logCopyCommand(focusedEditor);
216217
// execCommand(copy) works for edit context, but not execCommand(cut).
217218
logService.trace('registerExecCommandImpl (before execCommand copy)');
218219
focusedEditor.getContainerDomNode().ownerDocument.execCommand('copy');
219220
focusedEditor.trigger(undefined, Handler.Cut, undefined);
220221
logService.trace('registerExecCommandImpl (after execCommand copy)');
221222
} else {
223+
logCopyCommand(focusedEditor);
222224
logService.trace('registerExecCommandImpl (before execCommand ' + browserCommand + ')');
223225
focusedEditor.getContainerDomNode().ownerDocument.execCommand(browserCommand);
224226
logService.trace('registerExecCommandImpl (after execCommand ' + browserCommand + ')');
@@ -239,6 +241,16 @@ function registerExecCommandImpl(target: MultiCommand | undefined, browserComman
239241
});
240242
}
241243

244+
function logCopyCommand(editor: ICodeEditor) {
245+
const editContextEnabled = editor.getOption(EditorOption.effectiveEditContext);
246+
if (editContextEnabled) {
247+
const nativeEditContext = NativeEditContextRegistry.get(editor.getId());
248+
if (nativeEditContext) {
249+
nativeEditContext.onWillCopy();
250+
}
251+
}
252+
}
253+
242254
registerExecCommandImpl(CutAction, 'cut');
243255
registerExecCommandImpl(CopyAction, 'copy');
244256

0 commit comments

Comments
 (0)