Skip to content

Commit 5412b3c

Browse files
authored
Adding logs for copy paste (microsoft#257428)
* adding logs for copy paste * pushing change * removing reason * removing code * remove code * using this.logservice.trace * adiing uuid
1 parent 2be6e50 commit 5412b3c

File tree

12 files changed

+147
-23
lines changed

12 files changed

+147
-23
lines changed

src/vs/editor/browser/controller/editContext/clipboardUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface ClipboardDataToCopy {
7272

7373
export interface ClipboardStoredMetadata {
7474
version: 1;
75+
id: string | undefined;
7576
isFromEmptySelection: boolean | undefined;
7677
multicursorText: string[] | null | undefined;
7778
mode: string | null;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { IEditorAriaOptions } from '../../../editorBrowser.js';
3131
import { isHighSurrogate, isLowSurrogate } from '../../../../../base/common/strings.js';
3232
import { IME } from '../../../../../base/common/ime.js';
3333
import { OffsetRange } from '../../../../common/core/ranges/offsetRange.js';
34+
import { ILogService, LogLevel } from '../../../../../platform/log/common/log.js';
35+
import { generateUuid } from '../../../../../base/common/uuid.js';
3436

3537
// Corresponds to classes in nativeEditContext.css
3638
enum CompositionClassName {
@@ -75,7 +77,8 @@ export class NativeEditContext extends AbstractEditContext {
7577
overflowGuardContainer: FastDomNode<HTMLElement>,
7678
private readonly _viewController: ViewController,
7779
private readonly _visibleRangeProvider: IVisibleRangeProvider,
78-
@IInstantiationService instantiationService: IInstantiationService
80+
@IInstantiationService instantiationService: IInstantiationService,
81+
@ILogService private readonly logService: ILogService
7982
) {
8083
super(context);
8184

@@ -108,12 +111,17 @@ export class NativeEditContext extends AbstractEditContext {
108111

109112
this._screenReaderSupport = this._register(instantiationService.createInstance(ScreenReaderSupport, this.domNode, context, this._viewController));
110113

111-
this._register(addDisposableListener(this.domNode.domNode, 'copy', (e) => this._ensureClipboardGetsEditorSelection(e)));
114+
this._register(addDisposableListener(this.domNode.domNode, 'copy', (e) => {
115+
this.logService.trace('NativeEditContext#copy');
116+
this._ensureClipboardGetsEditorSelection(e);
117+
}));
112118
this._register(addDisposableListener(this.domNode.domNode, 'cut', (e) => {
119+
this.logService.trace('NativeEditContext#cut');
113120
// Pretend here we touched the text area, as the `cut` event will most likely
114121
// result in a `selectionchange` event which we want to ignore
115122
this._screenReaderSupport.onWillCut();
116123
this._ensureClipboardGetsEditorSelection(e);
124+
this.logService.trace('NativeEditContext#cut (before viewController.cut)');
117125
this._viewController.cut();
118126
}));
119127

@@ -127,11 +135,13 @@ export class NativeEditContext extends AbstractEditContext {
127135
}
128136
}));
129137
this._register(addDisposableListener(this.domNode.domNode, 'paste', (e) => {
138+
this.logService.trace('NativeEditContext#paste');
130139
e.preventDefault();
131140
if (!e.clipboardData) {
132141
return;
133142
}
134143
let [text, metadata] = ClipboardEventUtils.getTextData(e.clipboardData);
144+
this.logService.trace('NativeEditContext#paste with id : ', metadata?.id, ' with text.length: ', text.length);
135145
if (!text) {
136146
return;
137147
}
@@ -146,6 +156,7 @@ export class NativeEditContext extends AbstractEditContext {
146156
multicursorText = typeof metadata.multicursorText !== 'undefined' ? metadata.multicursorText : null;
147157
mode = metadata.mode;
148158
}
159+
this.logService.trace('NativeEditContext#paste (before viewController.paste)');
149160
this._viewController.paste(text, pasteOnNewLine, multicursorText, mode);
150161
}));
151162

@@ -291,6 +302,7 @@ export class NativeEditContext extends AbstractEditContext {
291302
}
292303

293304
public onWillPaste(): void {
305+
this.logService.trace('NativeEditContext#onWillPaste');
294306
this._onWillPaste();
295307
}
296308

@@ -538,8 +550,13 @@ export class NativeEditContext extends AbstractEditContext {
538550
const copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
539551
const selections = this._context.viewModel.getCursorStates().map(cursorState => cursorState.modelState.selection);
540552
const dataToCopy = getDataToCopy(this._context.viewModel, selections, emptySelectionClipboard, copyWithSyntaxHighlighting);
553+
let id = undefined;
554+
if (this.logService.getLevel() === LogLevel.Trace) {
555+
id = generateUuid();
556+
}
541557
const storedMetadata: ClipboardStoredMetadata = {
542558
version: 1,
559+
id,
543560
isFromEmptySelection: dataToCopy.isFromEmptySelection,
544561
multicursorText: dataToCopy.multicursorText,
545562
mode: dataToCopy.mode
@@ -554,5 +571,6 @@ export class NativeEditContext extends AbstractEditContext {
554571
if (e.clipboardData) {
555572
ClipboardEventUtils.setTextData(e.clipboardData, dataToCopy.text, dataToCopy.html, storedMetadata);
556573
}
574+
this.logService.trace('NativeEditContext#_ensureClipboardGetsEditorSelectios with id : ', id, ' with text.length: ', dataToCopy.text.length);
557575
}
558576
}

src/vs/editor/browser/controller/editContext/textArea/textAreaEditContextInput.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import * as strings from '../../../../../base/common/strings.js';
1717
import { Position } from '../../../../common/core/position.js';
1818
import { Selection } from '../../../../common/core/selection.js';
1919
import { IAccessibilityService } from '../../../../../platform/accessibility/common/accessibility.js';
20-
import { ILogService } from '../../../../../platform/log/common/log.js';
20+
import { ILogService, LogLevel } from '../../../../../platform/log/common/log.js';
2121
import { ClipboardDataToCopy, ClipboardEventUtils, ClipboardStoredMetadata, InMemoryClipboardMetadataManager } from '../clipboardUtils.js';
2222
import { _debugComposition, ITextAreaWrapper, ITypeData, TextAreaState } from './textAreaEditContextState.js';
23+
import { generateUuid } from '../../../../../base/common/uuid.js';
2324

2425
export namespace TextAreaSyntethicEvents {
2526
export const Tap = '-monaco-textarea-synthetic-tap';
@@ -357,6 +358,7 @@ export class TextAreaInput extends Disposable {
357358
// --- Clipboard operations
358359

359360
this._register(this._textArea.onCut((e) => {
361+
this._logService.trace(`TextAreaInput#onCut`, e);
360362
// Pretend here we touched the text area, as the `cut` event will most likely
361363
// result in a `selectionchange` event which we want to ignore
362364
this._textArea.setIgnoreSelectionChangeTime('received cut event');
@@ -366,10 +368,12 @@ export class TextAreaInput extends Disposable {
366368
}));
367369

368370
this._register(this._textArea.onCopy((e) => {
371+
this._logService.trace(`TextAreaInput#onCopy`, e);
369372
this._ensureClipboardGetsEditorSelection(e);
370373
}));
371374

372375
this._register(this._textArea.onPaste((e) => {
376+
this._logService.trace(`TextAreaInput#onPaste`, e);
373377
// Pretend here we touched the text area, as the `paste` event will most likely
374378
// result in a `selectionchange` event which we want to ignore
375379
this._textArea.setIgnoreSelectionChangeTime('received paste event');
@@ -381,13 +385,15 @@ export class TextAreaInput extends Disposable {
381385
}
382386

383387
let [text, metadata] = ClipboardEventUtils.getTextData(e.clipboardData);
388+
this._logService.trace(`TextAreaInput#onPaste with id : `, metadata?.id, ' with text.length: ', text.length);
384389
if (!text) {
385390
return;
386391
}
387392

388393
// try the in-memory store
389394
metadata = metadata || InMemoryClipboardMetadataManager.INSTANCE.get(text);
390395

396+
this._logService.trace(`TextAreaInput#onPaste (before onPaste)`);
391397
this._onPaste.fire({
392398
text: text,
393399
metadata: metadata
@@ -605,8 +611,13 @@ export class TextAreaInput extends Disposable {
605611

606612
private _ensureClipboardGetsEditorSelection(e: ClipboardEvent): void {
607613
const dataToCopy = this._host.getDataToCopy();
614+
let id = undefined;
615+
if (this._logService.getLevel() === LogLevel.Trace) {
616+
id = generateUuid();
617+
}
608618
const storedMetadata: ClipboardStoredMetadata = {
609619
version: 1,
620+
id,
610621
isFromEmptySelection: dataToCopy.isFromEmptySelection,
611622
multicursorText: dataToCopy.multicursorText,
612623
mode: dataToCopy.mode
@@ -622,6 +633,7 @@ export class TextAreaInput extends Disposable {
622633
if (e.clipboardData) {
623634
ClipboardEventUtils.setTextData(e.clipboardData, dataToCopy.text, dataToCopy.html, storedMetadata);
624635
}
636+
this._logService.trace('TextAreaEditContextInput#_ensureClipboardGetsEditorSelection with id : ', id, ' with text.length: ', dataToCopy.text.length);
625637
}
626638
}
627639

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IClipboardService } from '../../../../platform/clipboard/common/clipboa
1414
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
1515
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
1616
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
17+
import { ILogService } from '../../../../platform/log/common/log.js';
1718
import { IProductService } from '../../../../platform/product/common/productService.js';
1819
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
1920
import { CopyOptions, InMemoryClipboardMetadataManager } from '../../../browser/controller/editContext/clipboardUtils.js';
@@ -171,6 +172,8 @@ class ExecCommandCopyWithSyntaxHighlightingAction extends EditorAction {
171172
}
172173

173174
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
175+
const logService = accessor.get(ILogService);
176+
logService.trace('ExecCommandCopyWithSyntaxHighlightingAction#run');
174177
if (!editor.hasModel()) {
175178
return;
176179
}
@@ -183,7 +186,9 @@ class ExecCommandCopyWithSyntaxHighlightingAction extends EditorAction {
183186

184187
CopyOptions.forceCopyWithSyntaxHighlighting = true;
185188
editor.focus();
189+
logService.trace('ExecCommandCopyWithSyntaxHighlightingAction (before execCommand copy)');
186190
editor.getContainerDomNode().ownerDocument.execCommand('copy');
191+
logService.trace('ExecCommandCopyWithSyntaxHighlightingAction (after execCommand copy)');
187192
CopyOptions.forceCopyWithSyntaxHighlighting = false;
188193
}
189194
}
@@ -195,6 +200,8 @@ function registerExecCommandImpl(target: MultiCommand | undefined, browserComman
195200

196201
// 1. handle case when focus is in editor.
197202
target.addImplementation(10000, 'code-editor', (accessor: ServicesAccessor, args: any) => {
203+
const logService = accessor.get(ILogService);
204+
logService.trace('registerExecCommandImpl (addImplementation code-editor for : ', browserCommand, ')');
198205
// Only if editor text focus (i.e. not if editor has widget focus).
199206
const focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
200207
if (focusedEditor && focusedEditor.hasTextFocus()) {
@@ -207,10 +214,14 @@ function registerExecCommandImpl(target: MultiCommand | undefined, browserComman
207214
// TODO this is very ugly. The entire copy/paste/cut system needs a complete refactoring.
208215
if (focusedEditor.getOption(EditorOption.effectiveEditContext) && browserCommand === 'cut') {
209216
// execCommand(copy) works for edit context, but not execCommand(cut).
217+
logService.trace('registerExecCommandImpl (before execCommand copy)');
210218
focusedEditor.getContainerDomNode().ownerDocument.execCommand('copy');
211219
focusedEditor.trigger(undefined, Handler.Cut, undefined);
220+
logService.trace('registerExecCommandImpl (after execCommand copy)');
212221
} else {
222+
logService.trace('registerExecCommandImpl (before execCommand ' + browserCommand + ')');
213223
focusedEditor.getContainerDomNode().ownerDocument.execCommand(browserCommand);
224+
logService.trace('registerExecCommandImpl (after execCommand ' + browserCommand + ')');
214225
}
215226
return true;
216227
}
@@ -219,7 +230,11 @@ function registerExecCommandImpl(target: MultiCommand | undefined, browserComman
219230

220231
// 2. (default) handle case when focus is somewhere else.
221232
target.addImplementation(0, 'generic-dom', (accessor: ServicesAccessor, args: any) => {
233+
const logService = accessor.get(ILogService);
234+
logService.trace('registerExecCommandImpl (addImplementation generic-dom for : ', browserCommand, ')');
235+
logService.trace('registerExecCommandImpl (before execCommand ' + browserCommand + ')');
222236
getActiveDocument().execCommand(browserCommand);
237+
logService.trace('registerExecCommandImpl (after execCommand ' + browserCommand + ')');
223238
return true;
224239
});
225240
}
@@ -230,6 +245,8 @@ registerExecCommandImpl(CopyAction, 'copy');
230245
if (PasteAction) {
231246
// 1. Paste: handle case when focus is in editor.
232247
PasteAction.addImplementation(10000, 'code-editor', (accessor: ServicesAccessor, args: any) => {
248+
const logService = accessor.get(ILogService);
249+
logService.trace('registerExecCommandImpl (addImplementation code-editor for : paste)');
233250
const codeEditorService = accessor.get(ICodeEditorService);
234251
const clipboardService = accessor.get(IClipboardService);
235252
const telemetryService = accessor.get(ITelemetryService);
@@ -248,10 +265,12 @@ if (PasteAction) {
248265
}
249266

250267
const sw = StopWatch.create(true);
268+
logService.trace('registerExecCommandImpl (before triggerPaste)');
251269
const triggerPaste = clipboardService.triggerPaste(getActiveWindow().vscodeWindowId);
252270
if (triggerPaste) {
271+
logService.trace('registerExecCommandImpl (triggerPaste defined)');
253272
return triggerPaste.then(async () => {
254-
273+
logService.trace('registerExecCommandImpl (after triggerPaste)');
255274
if (productService.quality !== 'stable') {
256275
const duration = sw.elapsed();
257276
type EditorAsyncPasteClassification = {
@@ -270,8 +289,11 @@ if (PasteAction) {
270289

271290
return CopyPasteController.get(focusedEditor)?.finishedPaste() ?? Promise.resolve();
272291
});
292+
} else {
293+
logService.trace('registerExecCommandImpl (triggerPaste undefined)');
273294
}
274295
if (platform.isWeb) {
296+
logService.trace('registerExecCommandImpl (Paste handling on web)');
275297
// Use the clipboard service if document.execCommand('paste') was not successful
276298
return (async () => {
277299
const clipboardText = await clipboardService.readText();
@@ -285,6 +307,7 @@ if (PasteAction) {
285307
multicursorText = (typeof metadata.multicursorText !== 'undefined' ? metadata.multicursorText : null);
286308
mode = metadata.mode;
287309
}
310+
logService.trace('registerExecCommandImpl (clipboardText.length : ', clipboardText.length, ' id : ', metadata?.id, ')');
288311
focusedEditor.trigger('keyboard', Handler.Paste, {
289312
text: clipboardText,
290313
pasteOnNewLine,
@@ -301,6 +324,8 @@ if (PasteAction) {
301324

302325
// 2. Paste: (default) handle case when focus is somewhere else.
303326
PasteAction.addImplementation(0, 'generic-dom', (accessor: ServicesAccessor, args: any) => {
327+
const logService = accessor.get(ILogService);
328+
logService.trace('registerExecCommandImpl (addImplementation generic-dom for : paste)');
304329
const triggerPaste = accessor.get(IClipboardService).triggerPaste(getActiveWindow().vscodeWindowId);
305330
return triggerPaste ?? false;
306331
});

0 commit comments

Comments
 (0)