Trigger inline edits on paste (#236584)

pull/236679/head
Alexandru Dima 2024-12-19 14:10:37 +01:00 committed by GitHub
parent 225d1ca870
commit 5385e31b3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -14,7 +14,7 @@ import { Selection } from '../common/core/selection.js';
import { ICursorSelectionChangedEvent } from '../common/cursorEvents.js';
import { IModelDeltaDecoration, ITextModel } from '../common/model.js';
import { IModelContentChangedEvent } from '../common/textModelEvents.js';
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IOverlayWidget, IOverlayWidgetPosition } from './editorBrowser.js';
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IOverlayWidget, IOverlayWidgetPosition, IPasteEvent } from './editorBrowser.js';
import { Point } from './point.js';
/**
@ -94,6 +94,16 @@ export class ObservableCodeEditor extends Disposable {
}
}));
this._register(this.editor.onDidPaste((e) => {
this._beginUpdate();
try {
this._forceUpdate();
this.onDidPaste.trigger(this._currentTransaction, e);
} finally {
this._endUpdate();
}
}));
this._register(this.editor.onDidChangeModelContent(e => {
this._beginUpdate();
try {
@ -213,6 +223,7 @@ export class ObservableCodeEditor extends Disposable {
public readonly cursorLineNumber = derived<number | null>(this, reader => this.cursorPosition.read(reader)?.lineNumber ?? null);
public readonly onDidType = observableSignal<string>(this);
public readonly onDidPaste = observableSignal<IPasteEvent>(this);
public readonly scrollTop = observableFromEvent(this.editor.onDidScrollChange, () => this.editor.getScrollTop());
public readonly scrollLeft = observableFromEvent(this.editor.onDidScrollChange, () => this.editor.getScrollLeft());

View File

@ -140,6 +140,12 @@ export class InlineCompletionsController extends Disposable {
}
}));
this._register(runOnChange(this._editorObs.onDidPaste, (_value, _changes) => {
if (this._enabled.get()) {
this.model.get()?.trigger();
}
}));
this._register(this._commandService.onDidExecuteCommand((e) => {
// These commands don't trigger onDidType.
const commands = new Set([