mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
save lastEditMode and use that as default (#17206)
* save lastEditMode * change style to active * addActiveClassFromEditMode * add undefined to declaration * remove from public interface * private * lastEditMode to last selected mode * comments * set active in one place * rename method
This commit is contained in:
@@ -221,6 +221,7 @@ export class MarkdownToolbarComponent extends AngularDisposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._notebookEditor = this._notebookService.findNotebookEditor(this.cellModel?.notebookModel?.notebookUri);
|
this._notebookEditor = this._notebookService.findNotebookEditor(this.cellModel?.notebookModel?.notebookUri);
|
||||||
|
this.updateActiveViewAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async onInsertButtonClick(event: MouseEvent, type: MarkdownButtonType): Promise<void> {
|
public async onInsertButtonClick(event: MouseEvent, type: MarkdownButtonType): Promise<void> {
|
||||||
@@ -291,7 +292,7 @@ export class MarkdownToolbarComponent extends AngularDisposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeActiveClassFromModeActions() {
|
private removeActiveClassFromModeActions() {
|
||||||
const activeClass = ' active';
|
const activeClass = ' active';
|
||||||
for (let action of [this._toggleTextViewAction, this._toggleSplitViewAction, this._toggleMarkdownViewAction]) {
|
for (let action of [this._toggleTextViewAction, this._toggleSplitViewAction, this._toggleMarkdownViewAction]) {
|
||||||
if (action.class.includes(activeClass)) {
|
if (action.class.includes(activeClass)) {
|
||||||
@@ -300,6 +301,16 @@ export class MarkdownToolbarComponent extends AngularDisposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public updateActiveViewAction() {
|
||||||
|
this.removeActiveClassFromModeActions();
|
||||||
|
const activeClass = ' active';
|
||||||
|
switch (this.cellModel.currentMode) {
|
||||||
|
case CellEditModes.MARKDOWN: this._toggleMarkdownViewAction.class += activeClass; break;
|
||||||
|
case CellEditModes.SPLIT: this._toggleSplitViewAction.class += activeClass; break;
|
||||||
|
case CellEditModes.WYSIWYG: this._toggleTextViewAction.class += activeClass; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate modal for use as callout when inserting Link or Image into markdown.
|
* Instantiate modal for use as callout when inserting Link or Image into markdown.
|
||||||
* @param calloutStyle Style of callout passed in to determine which callout is rendered.
|
* @param calloutStyle Style of callout passed in to determine which callout is rendered.
|
||||||
|
|||||||
@@ -607,8 +607,6 @@ export class ToggleViewAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async run(context: MarkdownToolbarComponent): Promise<void> {
|
public override async run(context: MarkdownToolbarComponent): Promise<void> {
|
||||||
context.removeActiveClassFromModeActions();
|
|
||||||
this.class += ' active';
|
|
||||||
context.cellModel.showPreview = this.showPreview;
|
context.cellModel.showPreview = this.showPreview;
|
||||||
context.cellModel.showMarkdown = this.showMarkdown;
|
context.cellModel.showMarkdown = this.showMarkdown;
|
||||||
// Hide image button in WYSIWYG mode
|
// Hide image button in WYSIWYG mode
|
||||||
@@ -617,5 +615,6 @@ export class ToggleViewAction extends Action {
|
|||||||
} else {
|
} else {
|
||||||
context.showLinkAndImageButtons();
|
context.showLinkAndImageButtons();
|
||||||
}
|
}
|
||||||
|
context.updateActiveViewAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
private _outputCounter = 0; // When re-executing the same cell, ensure that we apply chart options in the same order
|
private _outputCounter = 0; // When re-executing the same cell, ensure that we apply chart options in the same order
|
||||||
private _attachments: nb.ICellAttachments | undefined;
|
private _attachments: nb.ICellAttachments | undefined;
|
||||||
private _preventNextChartCache: boolean = false;
|
private _preventNextChartCache: boolean = false;
|
||||||
|
private _lastEditMode: string | undefined;
|
||||||
public richTextCursorPosition: ICaretPosition | undefined;
|
public richTextCursorPosition: ICaretPosition | undefined;
|
||||||
public markdownCursorPosition: IPosition | undefined;
|
public markdownCursorPosition: IPosition | undefined;
|
||||||
|
|
||||||
@@ -230,8 +231,9 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
public set isEditMode(isEditMode: boolean) {
|
public set isEditMode(isEditMode: boolean) {
|
||||||
this._isEditMode = isEditMode;
|
this._isEditMode = isEditMode;
|
||||||
if (this._isEditMode) {
|
if (this._isEditMode) {
|
||||||
this.showPreview = this._defaultTextEditMode !== TextCellEditModes.Markdown;
|
const newEditMode = this._lastEditMode ?? this._defaultTextEditMode;
|
||||||
this.showMarkdown = this._defaultTextEditMode !== TextCellEditModes.RichText;
|
this.showPreview = newEditMode !== TextCellEditModes.Markdown;
|
||||||
|
this.showMarkdown = newEditMode !== TextCellEditModes.RichText;
|
||||||
}
|
}
|
||||||
this._onCellModeChanged.fire(this._isEditMode);
|
this._onCellModeChanged.fire(this._isEditMode);
|
||||||
// Note: this does not require a notebook update as it does not change overall state
|
// Note: this does not require a notebook update as it does not change overall state
|
||||||
@@ -421,7 +423,7 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
public set showPreview(val: boolean) {
|
public set showPreview(val: boolean) {
|
||||||
this._showPreview = val;
|
this._showPreview = val;
|
||||||
this._onCellPreviewChanged.fire(this._showPreview);
|
this._onCellPreviewChanged.fire(this._showPreview);
|
||||||
this._onCurrentEditModeChanged.fire(this.currentMode);
|
this.doModeUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get showMarkdown(): boolean {
|
public get showMarkdown(): boolean {
|
||||||
@@ -431,6 +433,13 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
public set showMarkdown(val: boolean) {
|
public set showMarkdown(val: boolean) {
|
||||||
this._showMarkdown = val;
|
this._showMarkdown = val;
|
||||||
this._onCellMarkdownChanged.fire(this._showMarkdown);
|
this._onCellMarkdownChanged.fire(this._showMarkdown);
|
||||||
|
this.doModeUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private doModeUpdates() {
|
||||||
|
if (this._isEditMode) {
|
||||||
|
this._lastEditMode = this._showPreview && this._showMarkdown ? TextCellEditModes.SplitView : (this._showMarkdown ? TextCellEditModes.Markdown : TextCellEditModes.RichText);
|
||||||
|
}
|
||||||
this._onCurrentEditModeChanged.fire(this.currentMode);
|
this._onCurrentEditModeChanged.fire(this.currentMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user