Skip to content

Commit 0f46a7c

Browse files
committed
fix #142507. Add interactive editor to history.
1 parent c910f79 commit 0f46a7c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1919
import { editorBackground, editorForeground, resolveColorValue } from 'vs/platform/theme/common/colorRegistry';
2020
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
2121
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
22-
import { IEditorMemento, IEditorOpenContext } from 'vs/workbench/common/editor';
22+
import { EditorPaneSelectionChangeReason, IEditorMemento, IEditorOpenContext, IEditorPaneSelectionChangeEvent } from 'vs/workbench/common/editor';
2323
import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
2424
import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput';
2525
import { CodeCellLayoutChangeEvent, IActiveNotebookEditorDelegate, ICellViewModel, INotebookEditorViewState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
@@ -54,9 +54,10 @@ import { ModesHoverController } from 'vs/editor/contrib/hover/browser/hover';
5454
import { MarkerController } from 'vs/editor/contrib/gotoError/browser/gotoError';
5555
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
5656
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfiguration';
57-
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
57+
import { ITextEditorOptions, TextEditorSelectionSource } from 'vs/platform/editor/common/editor';
5858
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
5959
import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
60+
import { ICursorPositionChangedEvent } from 'vs/editor/common/cursorEvents';
6061

6162
const DECORATION_KEY = 'interactiveInputDecoration';
6263
const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'InteractiveEditorViewState';
@@ -110,6 +111,8 @@ export class InteractiveEditor extends EditorPane {
110111

111112
#onDidFocusWidget = this._register(new Emitter<void>());
112113
override get onDidFocus(): Event<void> { return this.#onDidFocusWidget.event; }
114+
#onDidChangeSelection = this._register(new Emitter<IEditorPaneSelectionChangeEvent>());
115+
readonly onDidChangeSelection = this.#onDidChangeSelection.event;
113116

114117
constructor(
115118
@ITelemetryService telemetryService: ITelemetryService,
@@ -436,6 +439,10 @@ export class InteractiveEditor extends EditorPane {
436439
}
437440
}));
438441

442+
this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidChangeCursorPosition(e => this.#onDidChangeSelection.fire({ reason: this.#toEditorPaneSelectionChangeReason(e) })));
443+
this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidChangeModelContent(() => this.#onDidChangeSelection.fire({ reason: EditorPaneSelectionChangeReason.EDIT })));
444+
445+
439446
this.#widgetDisposableStore.add(this.#notebookKernelService.onDidChangeNotebookAffinity(this.#syncWithKernel, this));
440447
this.#widgetDisposableStore.add(this.#notebookKernelService.onDidChangeSelectedNotebooks(this.#syncWithKernel, this));
441448

@@ -495,6 +502,15 @@ export class InteractiveEditor extends EditorPane {
495502
this.#syncWithKernel();
496503
}
497504

505+
#toEditorPaneSelectionChangeReason(e: ICursorPositionChangedEvent): EditorPaneSelectionChangeReason {
506+
switch (e.source) {
507+
case TextEditorSelectionSource.PROGRAMMATIC: return EditorPaneSelectionChangeReason.PROGRAMMATIC;
508+
case TextEditorSelectionSource.NAVIGATION: return EditorPaneSelectionChangeReason.NAVIGATION;
509+
case TextEditorSelectionSource.JUMP: return EditorPaneSelectionChangeReason.JUMP;
510+
default: return EditorPaneSelectionChangeReason.USER;
511+
}
512+
}
513+
498514
#lastCell: ICellViewModel | undefined = undefined;
499515
#lastCellDisposable = new DisposableStore();
500516
#state: ScrollingState = ScrollingState.Initial;

0 commit comments

Comments
 (0)