未验证 提交 2b179bff 编写于 作者: A Alex Dima

Extract `_undo`, `_redo`

上级 0ac5e952
...@@ -811,7 +811,7 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -811,7 +811,7 @@ export class UndoRedoService implements IUndoRedoService {
if (element.canSplit()) { if (element.canSplit()) {
this._splitPastWorkspaceElement(element, ignoreResources); this._splitPastWorkspaceElement(element, ignoreResources);
this._notificationService.info(message); this._notificationService.info(message);
return new WorkspaceVerificationError(this.undo(strResource)); return new WorkspaceVerificationError(this._undo(strResource));
} else { } else {
// Cannot safely split this workspace element => flush all undo/redo stacks // Cannot safely split this workspace element => flush all undo/redo stacks
for (const strResource of element.strResources) { for (const strResource of element.strResources) {
...@@ -959,7 +959,7 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -959,7 +959,7 @@ export class UndoRedoService implements IUndoRedoService {
if (result.choice === 1) { if (result.choice === 1) {
// choice: undo this file // choice: undo this file
this._splitPastWorkspaceElement(element, null); this._splitPastWorkspaceElement(element, null);
return this.undo(strResource); return this._undo(strResource);
} }
// choice: undo in all files // choice: undo in all files
...@@ -1044,16 +1044,22 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -1044,16 +1044,22 @@ export class UndoRedoService implements IUndoRedoService {
const [, matchedStrResource] = this._findClosestUndoElementInGroup(groupId); const [, matchedStrResource] = this._findClosestUndoElementInGroup(groupId);
if (matchedStrResource) { if (matchedStrResource) {
return this.undo(matchedStrResource); return this._undo(matchedStrResource);
} }
} }
public undo(resourceOrSource: URI | UndoRedoSource | string): Promise<void> | void { public undo(resourceOrSource: URI | UndoRedoSource): Promise<void> | void {
if (resourceOrSource instanceof UndoRedoSource) { if (resourceOrSource instanceof UndoRedoSource) {
const [, matchedStrResource] = this._findClosestUndoElementWithSource(resourceOrSource.id); const [, matchedStrResource] = this._findClosestUndoElementWithSource(resourceOrSource.id);
return matchedStrResource ? this.undo(matchedStrResource) : undefined; return matchedStrResource ? this._undo(matchedStrResource) : undefined;
} }
const strResource = typeof resourceOrSource === 'string' ? resourceOrSource : this.getUriComparisonKey(resourceOrSource); if (typeof resourceOrSource === 'string') {
return this._undo(resourceOrSource);
}
return this._undo(this.getUriComparisonKey(resourceOrSource));
}
private _undo(strResource: string): Promise<void> | void {
if (!this._editStacks.has(strResource)) { if (!this._editStacks.has(strResource)) {
return; return;
} }
...@@ -1069,7 +1075,7 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -1069,7 +1075,7 @@ export class UndoRedoService implements IUndoRedoService {
const [matchedElement, matchedStrResource] = this._findClosestUndoElementInGroup(element.groupId); const [matchedElement, matchedStrResource] = this._findClosestUndoElementInGroup(element.groupId);
if (element !== matchedElement && matchedStrResource) { if (element !== matchedElement && matchedStrResource) {
// there is an element in the same group that should be undone before this one // there is an element in the same group that should be undone before this one
return this.undo(matchedStrResource); return this._undo(matchedStrResource);
} }
} }
...@@ -1128,7 +1134,7 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -1128,7 +1134,7 @@ export class UndoRedoService implements IUndoRedoService {
if (element.canSplit()) { if (element.canSplit()) {
this._splitFutureWorkspaceElement(element, ignoreResources); this._splitFutureWorkspaceElement(element, ignoreResources);
this._notificationService.info(message); this._notificationService.info(message);
return new WorkspaceVerificationError(this.redo(strResource)); return new WorkspaceVerificationError(this._redo(strResource));
} else { } else {
// Cannot safely split this workspace element => flush all undo/redo stacks // Cannot safely split this workspace element => flush all undo/redo stacks
for (const strResource of element.strResources) { for (const strResource of element.strResources) {
...@@ -1300,16 +1306,22 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -1300,16 +1306,22 @@ export class UndoRedoService implements IUndoRedoService {
const [, matchedStrResource] = this._findClosestRedoElementInGroup(groupId); const [, matchedStrResource] = this._findClosestRedoElementInGroup(groupId);
if (matchedStrResource) { if (matchedStrResource) {
return this.redo(matchedStrResource); return this._redo(matchedStrResource);
} }
} }
public redo(resourceOrSource: URI | UndoRedoSource | string): Promise<void> | void { public redo(resourceOrSource: URI | UndoRedoSource | string): Promise<void> | void {
if (resourceOrSource instanceof UndoRedoSource) { if (resourceOrSource instanceof UndoRedoSource) {
const [, matchedStrResource] = this._findClosestRedoElementWithSource(resourceOrSource.id); const [, matchedStrResource] = this._findClosestRedoElementWithSource(resourceOrSource.id);
return matchedStrResource ? this.redo(matchedStrResource) : undefined; return matchedStrResource ? this._redo(matchedStrResource) : undefined;
} }
const strResource = typeof resourceOrSource === 'string' ? resourceOrSource : this.getUriComparisonKey(resourceOrSource); if (typeof resourceOrSource === 'string') {
return this._redo(resourceOrSource);
}
return this._redo(this.getUriComparisonKey(resourceOrSource));
}
private _redo(strResource: string): Promise<void> | void {
if (!this._editStacks.has(strResource)) { if (!this._editStacks.has(strResource)) {
return; return;
} }
...@@ -1325,7 +1337,7 @@ export class UndoRedoService implements IUndoRedoService { ...@@ -1325,7 +1337,7 @@ export class UndoRedoService implements IUndoRedoService {
const [matchedElement, matchedStrResource] = this._findClosestRedoElementInGroup(element.groupId); const [matchedElement, matchedStrResource] = this._findClosestRedoElementInGroup(element.groupId);
if (element !== matchedElement && matchedStrResource) { if (element !== matchedElement && matchedStrResource) {
// there is an element in the same group that should be redone before this one // there is an element in the same group that should be redone before this one
return this.redo(matchedStrResource); return this._redo(matchedStrResource);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册