Skip to content

Commit a2a9c87

Browse files
committed
Tweak display
1 parent 93257e8 commit a2a9c87

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanelView.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,16 @@ extension PromptToCodePanelView {
563563
CodeBlockInContent(
564564
store: store,
565565
language: language,
566-
codeForegroundColor: codeForegroundColor
566+
codeForegroundColor: codeForegroundColor,
567+
presentAllContent: !isGenerating
567568
)
568569
} else {
569570
ScrollView(.horizontal) {
570571
CodeBlockInContent(
571572
store: store,
572573
language: language,
573-
codeForegroundColor: codeForegroundColor
574+
codeForegroundColor: codeForegroundColor,
575+
presentAllContent: !isGenerating
574576
)
575577
}
576578
.modify {
@@ -603,6 +605,7 @@ extension PromptToCodePanelView {
603605
let store: StoreOf<PromptToCodeSnippetPanel>
604606
let language: CodeLanguage
605607
let codeForegroundColor: Color?
608+
let presentAllContent: Bool
606609

607610
@Environment(\.colorScheme) var colorScheme
608611
@AppStorage(\.promptToCodeCodeFont) var codeFont
@@ -619,7 +622,8 @@ extension PromptToCodePanelView {
619622
scenario: "promptToCode",
620623
font: codeFont.value.nsFont,
621624
droppingLeadingSpaces: hideCommonPrecedingSpaces,
622-
proposedForegroundColor: codeForegroundColor
625+
proposedForegroundColor: codeForegroundColor,
626+
skipLastOnlyRemovalSection: !presentAllContent
623627
)
624628
.frame(maxWidth: CGFloat.infinity)
625629
.scaleEffect(x: 1, y: -1, anchor: UnitPoint.center)

Tool/Sources/SharedUIComponents/AsyncDiffCodeBlock.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public struct AsyncDiffCodeBlock: View {
2424
let proposedForegroundColor: Color?
2525
/// Whether to drop common leading spaces of each line.
2626
let droppingLeadingSpaces: Bool
27+
/// Whether to render the last diff section that only contains removals.
28+
let skipLastOnlyRemovalSection: Bool
2729

2830
public init(
2931
code: String,
@@ -34,7 +36,8 @@ public struct AsyncDiffCodeBlock: View {
3436
font: NSFont,
3537
droppingLeadingSpaces: Bool,
3638
proposedForegroundColor: Color?,
37-
ignoreWholeLineChangeInDiff: Bool = true
39+
ignoreWholeLineChangeInDiff: Bool = true,
40+
skipLastOnlyRemovalSection: Bool = false
3841
) {
3942
self.code = code
4043
self.originalCode = originalCode
@@ -44,6 +47,7 @@ public struct AsyncDiffCodeBlock: View {
4447
self.font = font
4548
self.proposedForegroundColor = proposedForegroundColor
4649
self.droppingLeadingSpaces = droppingLeadingSpaces
50+
self.skipLastOnlyRemovalSection = skipLastOnlyRemovalSection
4751
}
4852

4953
var foregroundColor: Color {
@@ -90,6 +94,9 @@ public struct AsyncDiffCodeBlock: View {
9094
.onChange(of: proposedForegroundColor) { _ in
9195
storage.highlightStorage.highlight(debounce: true, for: self)
9296
}
97+
.onChange(of: skipLastOnlyRemovalSection) { _ in
98+
storage.skipLastOnlyRemovalSection = skipLastOnlyRemovalSection
99+
}
93100
}
94101
}
95102

@@ -170,7 +177,7 @@ extension AsyncDiffCodeBlock {
170177
class Storage {
171178
let diffStorage = DiffStorage()
172179
let highlightStorage = HighlightStorage()
173-
var ignoreWholeLineChangeInDiff: Bool = true
180+
var skipLastOnlyRemovalSection: Bool = false
174181

175182
var code: String? {
176183
get { highlightStorage.code }
@@ -209,7 +216,7 @@ extension AsyncDiffCodeBlock {
209216
new: highlightedCode,
210217
original: highlightedOriginalCode,
211218
commonPrecedingSpaceCount: commonPrecedingSpaceCount,
212-
ignoreWholeLineChange: ignoreWholeLineChangeInDiff,
219+
skipLastOnlyRemovalSection: skipLastOnlyRemovalSection,
213220
diffResult: diffResult
214221
)
215222
}
@@ -223,14 +230,21 @@ extension AsyncDiffCodeBlock {
223230
new highlightedCode: [NSAttributedString],
224231
original originalHighlightedCode: [NSAttributedString],
225232
commonPrecedingSpaceCount: Int,
226-
ignoreWholeLineChange: Bool,
233+
skipLastOnlyRemovalSection: Bool,
227234
diffResult: CodeDiff.SnippetDiff
228235
) -> [Line] {
229236
var lines = [Line]()
230237

231-
for section in diffResult.sections {
238+
for (index, section) in diffResult.sections.enumerated() {
232239
guard !section.isEmpty else { continue }
233-
240+
241+
if skipLastOnlyRemovalSection,
242+
index == diffResult.sections.count - 1,
243+
section.newSnippet.isEmpty
244+
{
245+
continue
246+
}
247+
234248
for (index, line) in section.oldSnippet.enumerated() {
235249
if line.diff == .unchanged { continue }
236250
let lineIndex = section.oldOffset + index

0 commit comments

Comments
 (0)