Skip to content

Commit 277528f

Browse files
authored
Make python interactive prompt up/down behave like terminal window (microsoft#4126)
1 parent 7921cac commit 277528f

File tree

9 files changed

+407
-299
lines changed

9 files changed

+407
-299
lines changed

news/2 Fixes/4092.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix python interactive window up/down arrows in the input prompt to behave like a terminal.

src/client/datascience/history.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export class History implements IWebPanelMessageListener, IHistory {
512512
await this.jupyterServer.shutdown();
513513
}
514514
}
515-
this.loadPromise = this.loadJupyterServer(true);
515+
this.loadPromise = this.load();
516516
}
517517

518518
@captureTelemetry(Telemetry.GotoSourceCode, undefined, false)
@@ -783,19 +783,20 @@ export class History implements IWebPanelMessageListener, IHistory {
783783

784784
private loadWebPanel = async (): Promise<void> => {
785785
// Create our web panel (it's the UI that shows up for the history)
786+
if (this.webPanel === undefined) {
787+
// Figure out the name of our main bundle. Should be in our output directory
788+
const mainScriptPath = path.join(EXTENSION_ROOT_DIR, 'out', 'datascience-ui', 'history-react', 'index_bundle.js');
786789

787-
// Figure out the name of our main bundle. Should be in our output directory
788-
const mainScriptPath = path.join(EXTENSION_ROOT_DIR, 'out', 'datascience-ui', 'history-react', 'index_bundle.js');
789-
790-
// Generate a css to put into the webpanel for viewing code
791-
const css = await this.cssGenerator.generateThemeCss();
790+
// Generate a css to put into the webpanel for viewing code
791+
const css = await this.cssGenerator.generateThemeCss();
792792

793-
// Get our settings to pass along to the react control
794-
const settings = this.generateDataScienceExtraSettings();
793+
// Get our settings to pass along to the react control
794+
const settings = this.generateDataScienceExtraSettings();
795795

796-
// Use this script to create our web view panel. It should contain all of the necessary
797-
// script to communicate with this class.
798-
this.webPanel = this.provider.create(this, localize.DataScience.historyTitle(), mainScriptPath, css, settings);
796+
// Use this script to create our web view panel. It should contain all of the necessary
797+
// script to communicate with this class.
798+
this.webPanel = this.provider.create(this, localize.DataScience.historyTitle(), mainScriptPath, css, settings);
799+
}
799800
}
800801

801802
private load = async (): Promise<void> => {

src/datascience-ui/history-react/MainPanel.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getSettings, updateSettings } from '../react-common/settingsReactSide';
1717
import { Cell, ICellViewModel } from './cell';
1818
import { CellButton } from './cellButton';
1919
import { Image, ImageName } from './image';
20+
import { InputHistory } from './inputHistory';
2021
import { createCellVM, createEditableCellVM, generateTestState, IMainPanelState } from './mainPanelState';
2122
import { MenuBar } from './menuBar';
2223

@@ -29,15 +30,14 @@ export interface IMainPanelProps {
2930

3031
export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState> implements IMessageHandler {
3132
private stackLimit = 10;
32-
3333
private bottom: HTMLDivElement | undefined;
3434

3535
// tslint:disable-next-line:max-func-body-length
3636
constructor(props: IMainPanelProps, state: IMainPanelState) {
3737
super(props);
3838

3939
// Default state should show a busy message
40-
this.state = { cellVMs: [], busy: true, undoStack: [], redoStack : [], historyStack: [], submittedText: false};
40+
this.state = { cellVMs: [], busy: true, undoStack: [], redoStack : [], submittedText: false, history: new InputHistory()};
4141

4242
// Add test state if necessary
4343
if (!this.props.skipDefault) {
@@ -205,7 +205,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
205205
return this.state.cellVMs.map((cellVM: ICellViewModel, index: number) =>
206206
<ErrorBoundary key={index}>
207207
<Cell
208-
history={cellVM.editable ? this.state.historyStack : []}
208+
history={cellVM.editable ? this.state.history : undefined}
209209
maxTextSize={maxTextSize}
210210
autoFocus={document.hasFocus()}
211211
testMode={this.props.testMode}
@@ -628,17 +628,13 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
628628
// hide all inputs turned on.
629629
editCell.directInput = true;
630630

631-
// Compute our new history (skip adding dupes)
632-
const newHistory = this.state.historyStack.indexOf(code) >= 0 ? this.state.historyStack : [code, ...this.state.historyStack];
633-
634631
// Stick in a new cell at the bottom that's editable and update our state
635632
// so that the last cell becomes busy
636633
this.setState({
637634
cellVMs: [...withoutEdits, editCell, createEditableCellVM(this.getInputExecutionCount(withoutEdits))],
638635
undoStack : this.pushStack(this.state.undoStack, this.state.cellVMs),
639636
redoStack: this.state.redoStack,
640637
skipNextScroll: false,
641-
historyStack: newHistory,
642638
submittedText: true
643639
});
644640

src/datascience-ui/history-react/cell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CollapseButton } from './collapseButton';
2323
import { CommandPrompt } from './commandPrompt';
2424
import { ExecutionCount } from './executionCount';
2525
import { Image, ImageName } from './image';
26+
import { InputHistory } from './inputHistory';
2627
import { MenuBar } from './menuBar';
2728
import { SysInfo } from './sysInfo';
2829
import { displayOrder, richestMimetype, transforms } from './transforms';
@@ -34,7 +35,7 @@ interface ICellProps {
3435
testMode?: boolean;
3536
autoFocus: boolean;
3637
maxTextSize?: number;
37-
history: string [];
38+
history: InputHistory | undefined;
3839
showWatermark: boolean;
3940
gotoCode(): void;
4041
delete(): void;

0 commit comments

Comments
 (0)