Skip to content

Commit

Permalink
chore: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jul 11, 2024
1 parent 10f5c02 commit 91809b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,19 @@ export class LivePreviewDiffDecorationModel extends Disposable {
/**
* added widget 通常是在 removed widget 的下面一行的位置
*/
const findRemovedWidget = this.removedZoneWidgets.find((w) => w.position?.lineNumber === position.lineNumber - 1);
const findAddedDec = this.addedRangeDec.getDecorationByLineNumber(position.lineNumber);
const removedWidget = this.removedZoneWidgets.find((w) => w.position?.lineNumber === position.lineNumber - 1);
const addedDec = this.addedRangeDec.getDecorationByLineNumber(position.lineNumber);

const hide = () => {
widget.hide();
findAddedDec?.hide();
findRemovedWidget?.hide();
addedDec?.hide();
removedWidget?.hide();
};

const resume = () => {
widget.resume();
findAddedDec?.resume();
findRemovedWidget?.resume();
addedDec?.resume();
removedWidget?.resume();
};

/**
Expand All @@ -479,7 +479,7 @@ export class LivePreviewDiffDecorationModel extends Disposable {

case EPartialEdit.discard:
{
const operation = this.doDiscardPartialWidget(widget, findAddedDec, findRemovedWidget);
const operation = this.doDiscardPartialWidget(widget, addedDec, removedWidget);
if (operation) {
if (isPushStack) {
this.pushUndoElement({
Expand All @@ -501,10 +501,13 @@ export class LivePreviewDiffDecorationModel extends Disposable {
totalPartialEditCount: this.partialEditWidgetList.length,
acceptedPartialEditCount: this.partialEditWidgetList.filter((w) => w.isHidden).length,
totalAddedLinesCount: this.addedRangeDec.getDecorations().reduce((prev, current) => prev + current.length, 0),
totalRemovedLinesCount: this.removedZoneWidgets.reduce((prev, current) => prev + current.getRemovedTextLines().length, 0),
totalRemovedLinesCount: this.removedZoneWidgets.reduce(
(prev, current) => prev + current.getRemovedTextLines().length,
0,
),
currentPartialEdit: {
addedLinesCount: findAddedDec?.length || 0,
deletedLinesCount: findRemovedWidget?.getRemovedTextLines().length || 0,
addedLinesCount: addedDec?.length || 0,
deletedLinesCount: removedWidget?.getRemovedTextLines().length || 0,
type,
},
};
Expand All @@ -531,8 +534,8 @@ export class LivePreviewDiffDecorationModel extends Disposable {
}

public discardUnProcessed(): void {
const otherWidgets = this.partialEditWidgetList.filter((widget) => !widget.isHidden);
otherWidgets.forEach((widget) => {
const showingWidgets = this.partialEditWidgetList.filter((widget) => !widget.isHidden);
showingWidgets.forEach((widget) => {
this.handlePartialEditAction(EPartialEdit.discard, widget, false);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ export abstract class ReactInlineContentWidget extends Disposable implements IIn
}

resume(): void {
this._isHidden = false;
this.editor.addContentWidget(this);
if (this._isHidden) {
this._isHidden = false;
this.editor.addContentWidget(this);
}
}

getId(): string {
Expand Down

0 comments on commit 91809b3

Please sign in to comment.