-
Notifications
You must be signed in to change notification settings - Fork 198
[diffs/edit] Fix empty-new FileDiff edit #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,11 +281,21 @@ export class DiffHunksRenderer<LAnnotation = undefined> { | |
| * Enter edit-session mode: hunk updates preserve the current region | ||
| * skeleton instead of recomputing hunks, and rendering happens locally | ||
| * with the token transformer forced on (worker-pool requests/results are | ||
| * suspended for this renderer). Called on every editor attach, including | ||
| * a re-attach after recycle. | ||
| * suspended for this renderer). An empty additions document gets one row so | ||
| * the editor has a line for its caret. Called on every editor attach, | ||
| * including a re-attach after recycle. | ||
| */ | ||
| public beginEditSession(): void { | ||
| this.editSessionActive = true; | ||
| const diff = this.diffCache; | ||
| if (diff != null && !diff.isPartial && diff.additionLines.length === 0) { | ||
| Object.assign( | ||
| diff, | ||
| recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions) | ||
| ); | ||
| this.markEditSessionPass(diff); | ||
| this.clearRenderCache(); | ||
| } | ||
| } | ||
|
|
||
| /** Leave edit-session mode. The exit recompute is the host's concern. */ | ||
|
|
@@ -652,7 +662,7 @@ export class DiffHunksRenderer<LAnnotation = undefined> { | |
| ); | ||
| result.code.additionLines[0] = createPlainAdditionLineElement( | ||
| 0, | ||
| textDocument | ||
| textDocument.getLineText(0) | ||
| ); | ||
| this.markEditSessionPass(diff); | ||
| } else if (this.editSessionActive) { | ||
|
|
@@ -1110,6 +1120,14 @@ export class DiffHunksRenderer<LAnnotation = undefined> { | |
| expandedHunks: forcePlainText ? true : undefined, | ||
| collapsedContextThreshold, | ||
| }); | ||
| if ( | ||
| this.editSessionActive && | ||
| diff.additionLines.length === 1 && | ||
| diff.additionLines[0] === '' && | ||
| result.code.additionLines[0] == null | ||
| ) { | ||
| result.code.additionLines[0] = createPlainAdditionLineElement(0, ''); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this fallback runs for an empty-new diff in unified mode with deleted lines, the synthetic row is created with the helper's default Useful? React with 👍 / 👎.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 4aa6f2a |
||
| } | ||
| return { result, options }; | ||
| } | ||
|
|
||
|
|
@@ -2339,14 +2357,17 @@ function realignAdditionHastLines( | |
| realigned[index] ??= hastLines[index]; | ||
| } | ||
| for (let index = prefix; index < nextLines.length; index++) { | ||
| realigned[index] ??= createPlainAdditionLineElement(index, textDocument); | ||
| realigned[index] ??= createPlainAdditionLineElement( | ||
| index, | ||
| textDocument.getLineText(index) | ||
| ); | ||
| } | ||
| return realigned; | ||
| } | ||
|
|
||
| function createPlainAdditionLineElement( | ||
| lineIndex: number, | ||
| textDocument: DiffsTextDocument | ||
| lineText: string | ||
| ): HASTElement { | ||
| return { | ||
| type: 'element', | ||
|
|
@@ -2366,7 +2387,7 @@ function createPlainAdditionLineElement( | |
| children: [ | ||
| { | ||
| type: 'text', | ||
| value: textDocument.getLineText(lineIndex), | ||
| value: lineText, | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an editor is attached to a diff whose new file starts empty and is then detached without any user edit, this shim sets
editSessionDirty. The detach path callsfinishEditSessionForDiff, which recomputes through the edit pipeline and preserves the synthetic['']addition line, so a previously deletion-only/empty-new diff keeps rendering a green blank addition row after editing ends. Only mark the session dirty after an actual document change, or restore the original zero-line addition shape on session exit.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 4aa6f2a, empty caret-host rows are now removed during session exit, with split and unified regression coverage.