mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Merge pull request #124996 from microsoft/hediet/isUndoRedo
Forwards the isUndoing/isRedoing flags to the extension host.
This commit is contained in:
commit
556f74ae55
|
@ -23,6 +23,14 @@ export interface IModelChangedEvent {
|
|||
* The new version id the model has transitioned to.
|
||||
*/
|
||||
readonly versionId: number;
|
||||
/**
|
||||
* Flag that indicates that this event was generated while undoing.
|
||||
*/
|
||||
readonly isUndoing: boolean;
|
||||
/**
|
||||
* Flag that indicates that this event was generated while redoing.
|
||||
*/
|
||||
readonly isRedoing: boolean;
|
||||
}
|
||||
|
||||
export interface IMirrorTextModel {
|
||||
|
|
14
src/vs/vscode.d.ts
vendored
14
src/vs/vscode.d.ts
vendored
|
@ -10130,6 +10130,14 @@ declare module 'vscode' {
|
|||
readonly text: string;
|
||||
}
|
||||
|
||||
export enum TextDocumentChangeReason {
|
||||
/** The text change is caused by an undo operation. */
|
||||
Undo = 1,
|
||||
|
||||
/** The text change is caused by an redo operation. */
|
||||
Redo = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* An event describing a transactional {@link TextDocument document} change.
|
||||
*/
|
||||
|
@ -10144,6 +10152,12 @@ declare module 'vscode' {
|
|||
* An array of content changes.
|
||||
*/
|
||||
readonly contentChanges: readonly TextDocumentContentChangeEvent[];
|
||||
|
||||
/**
|
||||
* The reason why the document was changed.
|
||||
* Is undefined if the reason is not known.
|
||||
*/
|
||||
readonly reason?: TextDocumentChangeReason;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1239,6 +1239,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
TextEditorLineNumbersStyle: extHostTypes.TextEditorLineNumbersStyle,
|
||||
TextEditorRevealType: extHostTypes.TextEditorRevealType,
|
||||
TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind,
|
||||
TextDocumentChangeReason: extHostTypes.TextDocumentChangeReason,
|
||||
ThemeColor: extHostTypes.ThemeColor,
|
||||
ThemeIcon: extHostTypes.ThemeIcon,
|
||||
TreeItem: extHostTypes.TreeItem,
|
||||
|
|
|
@ -14,6 +14,7 @@ import * as TypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
|
|||
import type * as vscode from 'vscode';
|
||||
import { assertIsDefined } from 'vs/base/common/types';
|
||||
import { deepFreeze } from 'vs/base/common/objects';
|
||||
import { TextDocumentChangeReason } from 'vs/workbench/api/common/extHostTypes';
|
||||
|
||||
export class ExtHostDocuments implements ExtHostDocumentsShape {
|
||||
|
||||
|
@ -134,7 +135,8 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
|||
data._acceptIsDirty(isDirty);
|
||||
this._onDidChangeDocument.fire({
|
||||
document: data.document,
|
||||
contentChanges: []
|
||||
contentChanges: [],
|
||||
reason: undefined
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -146,6 +148,14 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
|||
}
|
||||
data._acceptIsDirty(isDirty);
|
||||
data.onEvents(events);
|
||||
|
||||
let reason: vscode.TextDocumentChangeReason | undefined = undefined;
|
||||
if (events.isUndoing) {
|
||||
reason = TextDocumentChangeReason.Undo;
|
||||
} else if (events.isRedoing) {
|
||||
reason = TextDocumentChangeReason.Redo;
|
||||
}
|
||||
|
||||
this._onDidChangeDocument.fire(deepFreeze({
|
||||
document: data.document,
|
||||
contentChanges: events.changes.map((change) => {
|
||||
|
@ -155,7 +165,8 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
|||
rangeLength: change.rangeLength,
|
||||
text: change.text
|
||||
};
|
||||
})
|
||||
}),
|
||||
reason
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -1590,6 +1590,11 @@ export enum TextEditorSelectionChangeKind {
|
|||
Command = 3
|
||||
}
|
||||
|
||||
export enum TextDocumentChangeReason {
|
||||
Undo = 1,
|
||||
Redo = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* These values match very carefully the values of `TrackedRangeStickiness`
|
||||
*/
|
||||
|
|
|
@ -104,6 +104,8 @@ suite('ExtHostDocumentData', () => {
|
|||
}],
|
||||
eol: undefined!,
|
||||
versionId: undefined!,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
});
|
||||
|
||||
// line didn't change
|
||||
|
@ -161,6 +163,8 @@ suite('ExtHostDocumentData', () => {
|
|||
}],
|
||||
eol: undefined!,
|
||||
versionId: undefined!,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
});
|
||||
|
||||
assertOffsetAt(0, 1, 1);
|
||||
|
@ -179,6 +183,8 @@ suite('ExtHostDocumentData', () => {
|
|||
}],
|
||||
eol: undefined!,
|
||||
versionId: undefined!,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
});
|
||||
|
||||
assertOffsetAt(0, 1, 1);
|
||||
|
@ -197,6 +203,8 @@ suite('ExtHostDocumentData', () => {
|
|||
}],
|
||||
eol: undefined!,
|
||||
versionId: undefined!,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
});
|
||||
|
||||
assertOffsetAt(0, 1, 1);
|
||||
|
@ -218,6 +226,8 @@ suite('ExtHostDocumentData', () => {
|
|||
}],
|
||||
eol: undefined!,
|
||||
versionId: undefined!,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
});
|
||||
|
||||
assertOffsetAt(0, 1, 1);
|
||||
|
@ -398,6 +408,8 @@ suite('ExtHostDocumentData updates line mapping', () => {
|
|||
}],
|
||||
eol: eol!,
|
||||
versionId: undefined!,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -423,7 +435,7 @@ suite('ExtHostDocumentData updates line mapping', () => {
|
|||
'and this is line number two',
|
||||
'it is followed by #3',
|
||||
'and finished with the fourth.',
|
||||
], { changes: [], eol: undefined!, versionId: 7 });
|
||||
], { changes: [], eol: undefined!, versionId: 7, isRedoing: false, isUndoing: false });
|
||||
});
|
||||
|
||||
test('after remove', () => {
|
||||
|
|
|
@ -306,7 +306,9 @@ suite('ExtHostDocumentSaveParticipant', () => {
|
|||
text: 'bar'
|
||||
}],
|
||||
eol: undefined!,
|
||||
versionId: 2
|
||||
versionId: 2,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
}, true);
|
||||
|
||||
e.waitUntil(Promise.resolve([TextEdit.insert(new Position(0, 0), 'bar')]));
|
||||
|
@ -338,7 +340,9 @@ suite('ExtHostDocumentSaveParticipant', () => {
|
|||
rangeLength: undefined!,
|
||||
}],
|
||||
eol: undefined!,
|
||||
versionId: documents.getDocumentData(uri)!.version + 1
|
||||
versionId: documents.getDocumentData(uri)!.version + 1,
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
}, true);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -334,7 +334,9 @@ suite('NotebookConcatDocument', function () {
|
|||
rangeLength: 6,
|
||||
rangeOffset: 12,
|
||||
text: 'Hi'
|
||||
}]
|
||||
}],
|
||||
isRedoing: false,
|
||||
isUndoing: false,
|
||||
}, false);
|
||||
assertLines(doc, 'Hello', 'World', 'Hi World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
assertLocation(doc, new Position(2, 12), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 9)), false);
|
||||
|
|
Loading…
Reference in a new issue