mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-13 11:38:36 -05:00
Merge from vscode e6a45f4242ebddb7aa9a229f85555e8a3bd987e2 (#9253)
* Merge from vscode e6a45f4242ebddb7aa9a229f85555e8a3bd987e2 * skip failing tests * remove github-authentication extensions * ignore github compile steps * ignore github compile steps * check in compiled files
This commit is contained in:
@@ -36,6 +36,8 @@ import { TokensStore, MultilineTokens, countEOL, MultilineTokens2, TokensStore2
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { Constants } from 'vs/base/common/uint';
|
||||
import { EditorTheme } from 'vs/editor/common/view/viewContext';
|
||||
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
|
||||
import { UndoRedoService } from 'vs/platform/undoRedo/common/undoRedoService';
|
||||
|
||||
function createTextBufferBuilder() {
|
||||
return new PieceTreeTextBufferBuilder();
|
||||
@@ -188,7 +190,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
};
|
||||
|
||||
public static createFromString(text: string, options: model.ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier | null = null, uri: URI | null = null): TextModel {
|
||||
return new TextModel(text, options, languageIdentifier, uri);
|
||||
return new TextModel(text, options, languageIdentifier, uri, new UndoRedoService());
|
||||
}
|
||||
|
||||
public static resolveOptions(textBuffer: model.ITextBuffer, options: model.ITextModelCreationOptions): model.TextModelResolvedOptions {
|
||||
@@ -253,6 +255,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
public readonly id: string;
|
||||
public readonly isForSimpleWidget: boolean;
|
||||
private readonly _associatedResource: URI;
|
||||
private readonly _undoRedoService: IUndoRedoService;
|
||||
private _attachedEditorCount: number;
|
||||
private _buffer: model.ITextBuffer;
|
||||
private _options: model.TextModelResolvedOptions;
|
||||
@@ -268,7 +271,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
private readonly _isTooLargeForTokenization: boolean;
|
||||
|
||||
//#region Editing
|
||||
private _commandManager: EditStack;
|
||||
private readonly _commandManager: EditStack;
|
||||
private _isUndoing: boolean;
|
||||
private _isRedoing: boolean;
|
||||
private _trimAutoWhitespaceLines: number[] | null;
|
||||
@@ -293,7 +296,13 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
private readonly _tokenization: TextModelTokenization;
|
||||
//#endregion
|
||||
|
||||
constructor(source: string | model.ITextBufferFactory, creationOptions: model.ITextModelCreationOptions, languageIdentifier: LanguageIdentifier | null, associatedResource: URI | null = null) {
|
||||
constructor(
|
||||
source: string | model.ITextBufferFactory,
|
||||
creationOptions: model.ITextModelCreationOptions,
|
||||
languageIdentifier: LanguageIdentifier | null,
|
||||
associatedResource: URI | null = null,
|
||||
undoRedoService: IUndoRedoService
|
||||
) {
|
||||
super();
|
||||
|
||||
// Generate a new unique model id
|
||||
@@ -305,6 +314,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
} else {
|
||||
this._associatedResource = associatedResource;
|
||||
}
|
||||
this._undoRedoService = undoRedoService;
|
||||
this._attachedEditorCount = 0;
|
||||
|
||||
this._buffer = createTextBuffer(source, creationOptions.defaultEOL);
|
||||
@@ -347,7 +357,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
this._decorations = Object.create(null);
|
||||
this._decorationsTree = new DecorationsTrees();
|
||||
|
||||
this._commandManager = new EditStack(this);
|
||||
this._commandManager = new EditStack(this, undoRedoService);
|
||||
this._isUndoing = false;
|
||||
this._isRedoing = false;
|
||||
this._trimAutoWhitespaceLines = null;
|
||||
@@ -362,6 +372,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
this._onWillDispose.fire();
|
||||
this._languageRegistryListener.dispose();
|
||||
this._tokenization.dispose();
|
||||
this._undoRedoService.removeElements(this.uri);
|
||||
this._isDisposed = true;
|
||||
super.dispose();
|
||||
this._isDisposing = false;
|
||||
@@ -436,7 +447,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
this._decorationsTree = new DecorationsTrees();
|
||||
|
||||
// Destroy my edit history and settings
|
||||
this._commandManager = new EditStack(this);
|
||||
this._commandManager.clear();
|
||||
this._trimAutoWhitespaceLines = null;
|
||||
|
||||
this._emitContentChangedEvent(
|
||||
@@ -483,6 +494,21 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
);
|
||||
}
|
||||
|
||||
_setEOL(eol: model.EndOfLineSequence, isUndoing: boolean, isRedoing: boolean, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void {
|
||||
try {
|
||||
this._onDidChangeDecorations.beginDeferredEmit();
|
||||
this._eventEmitter.beginDeferredEmit();
|
||||
this._isUndoing = isUndoing;
|
||||
this._isRedoing = isRedoing;
|
||||
this.setEOL(eol);
|
||||
this._overwriteAlternativeVersionId(resultingAlternativeVersionId);
|
||||
} finally {
|
||||
this._isUndoing = false;
|
||||
this._eventEmitter.endDeferredEmit(resultingSelection);
|
||||
this._onDidChangeDecorations.endDeferredEmit();
|
||||
}
|
||||
}
|
||||
|
||||
private _onBeforeEOLChange(): void {
|
||||
// Ensure all decorations get their `range` set.
|
||||
const versionId = this.getVersionId();
|
||||
@@ -1272,18 +1298,37 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer);
|
||||
}
|
||||
|
||||
_applyEdits(edits: model.IValidEditOperations[], isUndoing: boolean, isRedoing: boolean, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): model.IValidEditOperations[] {
|
||||
try {
|
||||
this._onDidChangeDecorations.beginDeferredEmit();
|
||||
this._eventEmitter.beginDeferredEmit();
|
||||
this._isUndoing = isUndoing;
|
||||
this._isRedoing = isRedoing;
|
||||
let reverseEdits: model.IValidEditOperations[] = [];
|
||||
for (let i = 0, len = edits.length; i < len; i++) {
|
||||
reverseEdits[i] = { operations: this.applyEdits(edits[i].operations) };
|
||||
}
|
||||
this._overwriteAlternativeVersionId(resultingAlternativeVersionId);
|
||||
return reverseEdits;
|
||||
} finally {
|
||||
this._isUndoing = false;
|
||||
this._eventEmitter.endDeferredEmit(resultingSelection);
|
||||
this._onDidChangeDecorations.endDeferredEmit();
|
||||
}
|
||||
}
|
||||
|
||||
public applyEdits(rawOperations: model.IIdentifiedSingleEditOperation[]): model.IValidEditOperation[] {
|
||||
try {
|
||||
this._onDidChangeDecorations.beginDeferredEmit();
|
||||
this._eventEmitter.beginDeferredEmit();
|
||||
return this._applyEdits(this._validateEditOperations(rawOperations));
|
||||
return this._doApplyEdits(this._validateEditOperations(rawOperations));
|
||||
} finally {
|
||||
this._eventEmitter.endDeferredEmit();
|
||||
this._onDidChangeDecorations.endDeferredEmit();
|
||||
}
|
||||
}
|
||||
|
||||
private _applyEdits(rawOperations: model.ValidAnnotatedEditOperation[]): model.IValidEditOperation[] {
|
||||
private _doApplyEdits(rawOperations: model.ValidAnnotatedEditOperation[]): model.IValidEditOperation[] {
|
||||
|
||||
const oldLineCount = this._buffer.getLineCount();
|
||||
const result = this._buffer.applyEdits(rawOperations, this._options.trimAutoWhitespace);
|
||||
@@ -1364,62 +1409,20 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
return result.reverseEdits;
|
||||
}
|
||||
|
||||
private _undo(): Selection[] | null {
|
||||
this._isUndoing = true;
|
||||
let r = this._commandManager.undo();
|
||||
this._isUndoing = false;
|
||||
|
||||
if (!r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this._overwriteAlternativeVersionId(r.recordedVersionId);
|
||||
|
||||
return r.selections;
|
||||
}
|
||||
|
||||
public undo(): Selection[] | null {
|
||||
try {
|
||||
this._onDidChangeDecorations.beginDeferredEmit();
|
||||
this._eventEmitter.beginDeferredEmit();
|
||||
return this._undo();
|
||||
} finally {
|
||||
this._eventEmitter.endDeferredEmit();
|
||||
this._onDidChangeDecorations.endDeferredEmit();
|
||||
}
|
||||
public undo(): void {
|
||||
this._undoRedoService.undo(this.uri);
|
||||
}
|
||||
|
||||
public canUndo(): boolean {
|
||||
return this._commandManager.canUndo();
|
||||
return this._undoRedoService.canUndo(this.uri);
|
||||
}
|
||||
|
||||
private _redo(): Selection[] | null {
|
||||
this._isRedoing = true;
|
||||
let r = this._commandManager.redo();
|
||||
this._isRedoing = false;
|
||||
|
||||
if (!r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this._overwriteAlternativeVersionId(r.recordedVersionId);
|
||||
|
||||
return r.selections;
|
||||
}
|
||||
|
||||
public redo(): Selection[] | null {
|
||||
try {
|
||||
this._onDidChangeDecorations.beginDeferredEmit();
|
||||
this._eventEmitter.beginDeferredEmit();
|
||||
return this._redo();
|
||||
} finally {
|
||||
this._eventEmitter.endDeferredEmit();
|
||||
this._onDidChangeDecorations.endDeferredEmit();
|
||||
}
|
||||
public redo(): void {
|
||||
this._undoRedoService.redo(this.uri);
|
||||
}
|
||||
|
||||
public canRedo(): boolean {
|
||||
return this._commandManager.canRedo();
|
||||
return this._undoRedoService.canRedo(this.uri);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -3191,10 +3194,11 @@ export class DidChangeContentEmitter extends Disposable {
|
||||
this._deferredCnt++;
|
||||
}
|
||||
|
||||
public endDeferredEmit(): void {
|
||||
public endDeferredEmit(resultingSelection: Selection[] | null = null): void {
|
||||
this._deferredCnt--;
|
||||
if (this._deferredCnt === 0) {
|
||||
if (this._deferredEvent !== null) {
|
||||
this._deferredEvent.rawContentChangedEvent.resultingSelection = resultingSelection;
|
||||
const e = this._deferredEvent;
|
||||
this._deferredEvent = null;
|
||||
this._fastEmitter.fire(e);
|
||||
|
||||
Reference in New Issue
Block a user