mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-30 17:23:29 -05:00
Maddy/edit mode events cleanup (#17636)
* remove multiple events * correct preview check * add test
This commit is contained in:
@@ -7,7 +7,7 @@ import 'vs/css!./code';
|
||||
import { OnInit, Component, Input, Inject, ElementRef, ViewChild, Output, EventEmitter, OnChanges, SimpleChange, forwardRef, ChangeDetectorRef } from '@angular/core';
|
||||
|
||||
import { QueryTextEditor } from 'sql/workbench/browser/modelComponents/queryTextEditor';
|
||||
import { ICellModel, CellExecutionState } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { ICellModel, CellExecutionState, CellEditModes } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar';
|
||||
import { RunCellAction, CellContext } from 'sql/workbench/contrib/notebook/browser/cellViews/codeActions';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
@@ -262,8 +262,9 @@ export class CodeComponent extends CellView implements OnInit, OnChanges {
|
||||
this._register(this.cellModel.onCollapseStateChanged(isCollapsed => {
|
||||
this.onCellCollapse(isCollapsed);
|
||||
}));
|
||||
this._register(this.cellModel.onCellPreviewModeChanged((e) => {
|
||||
if (!e && this._cellModel.cellSourceChanged) {
|
||||
this._register(this.cellModel.onCurrentEditModeChanged((e) => {
|
||||
let preview = e !== CellEditModes.MARKDOWN;
|
||||
if (!preview && this._cellModel.cellSourceChanged) {
|
||||
this.updateModel();
|
||||
this._cellModel.cellSourceChanged = false;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,15 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
}
|
||||
this._changeRef.detectChanges();
|
||||
}));
|
||||
this._register(this.cellModel.onCellPreviewModeChanged(preview => {
|
||||
this._register(this.cellModel.onCurrentEditModeChanged(editMode => {
|
||||
let markdown: boolean = editMode !== CellEditModes.WYSIWYG;
|
||||
if (!markdown) {
|
||||
let editorControl = this.cellEditors.length > 0 ? this.cellEditors[0].getEditor().getControl() : undefined;
|
||||
if (editorControl) {
|
||||
let selection = editorControl.getSelection();
|
||||
this.cellModel.markdownCursorPosition = selection?.getPosition();
|
||||
}
|
||||
}
|
||||
// On preview mode change, get the cursor position (get the position only when the selection node is a text node)
|
||||
if (window.getSelection() && window.getSelection().focusNode?.nodeName === '#text' && window.getSelection().getRangeAt(0)) {
|
||||
let selection = window.getSelection().getRangeAt(0);
|
||||
@@ -247,17 +255,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
this.cellModel.richTextCursorPosition = cursorPosition;
|
||||
}
|
||||
}
|
||||
this.previewMode = preview;
|
||||
this.focusIfPreviewMode();
|
||||
}));
|
||||
this._register(this.cellModel.onCellMarkdownModeChanged(markdown => {
|
||||
if (!markdown) {
|
||||
let editorControl = this.cellEditors.length > 0 ? this.cellEditors[0].getEditor().getControl() : undefined;
|
||||
if (editorControl) {
|
||||
let selection = editorControl.getSelection();
|
||||
this.cellModel.markdownCursorPosition = selection?.getPosition();
|
||||
}
|
||||
}
|
||||
this.previewMode = editMode !== CellEditModes.MARKDOWN;
|
||||
this.markdownMode = markdown;
|
||||
this.focusIfPreviewMode();
|
||||
}));
|
||||
|
||||
@@ -27,7 +27,7 @@ import { NotebookFindNextAction, NotebookFindPreviousAction } from 'sql/workbenc
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { CellEditModes, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { INotebookFindModel } from 'sql/workbench/contrib/notebook/browser/models/notebookFindModel';
|
||||
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration } from 'vs/editor/common/model';
|
||||
@@ -380,8 +380,8 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle
|
||||
this._onFindStateChange(changeEvent).catch(onUnexpectedError);
|
||||
}
|
||||
}));
|
||||
this._register(cell.onCellMarkdownModeChanged(e => {
|
||||
if (e) {
|
||||
this._register(cell.onCurrentEditModeChanged(editMode => {
|
||||
if (editMode !== CellEditModes.WYSIWYG) {
|
||||
this._onFindStateChange(changeEvent).catch(onUnexpectedError);
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user