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/8045.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix markdown disappearing after editing and hitting the escape key.
1 change: 1 addition & 0 deletions src/datascience-ui/native-editor/nativeCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export class NativeCell extends React.Component<INativeCellProps> {
// Unfocus the current cell by giving focus to the cell itself
if (this.wrapperRef && this.wrapperRef.current && this.isFocused()) {
e.stopPropagation();
this.isCodeCell() ? this.onCodeUnfocused() : this.onMarkdownUnfocused();
this.props.focusCell(this.cellId, false);
this.props.stateController.sendCommand(NativeCommandType.Unfocus, 'keyboard');
}
Expand Down
29 changes: 18 additions & 11 deletions src/datascience-ui/native-editor/nativeEditorStateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class NativeEditorStateController extends MainStateController {
case InteractiveWindowMessages.NotebookAddCellBelow:
this.addNewCell();
break;
case InteractiveWindowMessages.DoSave:
case InteractiveWindowMessages.DoSave:
this.save();
break;

Expand Down Expand Up @@ -278,24 +278,31 @@ export class NativeEditorStateController extends MainStateController {

protected onCodeLostFocus(cellId: string) {
// Update the cell's source
const cell = this.findCell(cellId);
if (cell) {
const index = this.findCellIndex(cellId);
if (index >= 0) {
// Get the model for the monaco editor
const monacoId = this.getMonacoId(cellId);
if (monacoId) {
const model = monacoEditor.editor.getModels().find(m => m.id === monacoId);
if (model) {
const newValue = model.getValue().replace(/\r/g, '');
cell.cell.data.source = cell.inputBlockText = newValue;
const newVMs = [...this.getState().cellVMs];

// Update our state
newVMs[index] = {
...newVMs[index],
cell: {
...newVMs[index].cell,
data: {
...newVMs[index].cell.data,
source: newValue
}
}
};

this.setState({ cellVMs: newVMs });
}
}
}

// Special case markdown in the edit cell. Submit it.
if (cell && cell.cell.id === Identifiers.EditCellId && cell.cell.data.cell_type === 'markdown') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case doesn't exist anymore. We don't have edit cells in the native editor.

const code = cell.inputBlockText;
cell.cell.data.source = cell.inputBlockText = '';
this.submitInput(code, cell);
}
}
}