Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/8491.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Arrowing up and down through cells can lose code that was just typed.
12 changes: 12 additions & 0 deletions src/datascience-ui/interactive-common/mainStateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,18 @@ export class MainStateController implements IMessageHandler {
}
}

public updateCode = (cellId: string, code: string) => {
const index = this.pendingState.cellVMs.findIndex(c => c.cell.id === cellId);
if (index > 0) {
const cellVMs = [...this.pendingState.cellVMs];
const current = this.pendingState.cellVMs[index];
const newCell = { ...current, inputBlockText: code, cell: { ...current.cell, data: { ...current.cell.data, source: code } } };
// tslint:disable-next-line: no-any
cellVMs[index] = (newCell as any); // This is because IMessageCell doesn't fit in here. But message cells can't change type
this.setState({ cellVMs });
}
}

public changeCellType = (cellId: string, newType: 'code' | 'markdown') => {
const index = this.pendingState.cellVMs.findIndex(c => c.cell.id === cellId);
if (index >= 0 && this.pendingState.cellVMs[index].cell.data.cell_type !== newType) {
Expand Down
6 changes: 6 additions & 0 deletions src/datascience-ui/native-editor/nativeCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ export class NativeCell extends React.Component<INativeCellProps> {
const prevCellId = this.getPrevCellId();
if (prevCellId) {
e.stopPropagation();
if (e.editorInfo) {
this.props.stateController.updateCode(this.getCell().id, e.editorInfo.contents);
}
this.moveSelection(prevCellId, this.isFocused(), CursorPos.Bottom);
}

Expand All @@ -396,6 +399,9 @@ export class NativeCell extends React.Component<INativeCellProps> {

if (nextCellId) {
e.stopPropagation();
if (e.editorInfo) {
this.props.stateController.updateCode(this.getCell().id, e.editorInfo.contents);
}
this.moveSelection(nextCellId, this.isFocused(), CursorPos.Top);
}

Expand Down