Skip to content

Commit 97eb465

Browse files
committed
Truncate file name in the middle when it's too long
1 parent 6e6bc96 commit 97eb465

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ extension PromptToCodePanel {
7373
if isAttached {
7474
HStack(spacing: 4) {
7575
Text(viewStore.state.attachedToFilename)
76+
.lineLimit(1)
77+
.truncationMode(.middle)
7678
if let range = viewStore.state.selectionRange {
7779
Text(range.description)
7880
}
@@ -437,6 +439,37 @@ struct PromptToCodePanel_Preview: PreviewProvider {
437439
}
438440
}
439441

442+
#Preview("Prompt to Code Panel Super Long File Name") {
443+
PromptToCodePanel(store: .init(initialState: .init(
444+
code: """
445+
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in
446+
Text(viewModel.suggestion[index])
447+
.frame(maxWidth: .infinity, alignment: .leading)
448+
.multilineTextAlignment(.leading)
449+
}
450+
""",
451+
prompt: "",
452+
language: .builtIn(.swift),
453+
indentSize: 4,
454+
usesTabsForIndentation: false,
455+
projectRootURL: URL(fileURLWithPath: "path/to/file.txt"),
456+
documentURL: URL(
457+
fileURLWithPath: "path/to/file-name-is-super-long-what-should-we-do-with-it-hah.txt"
458+
),
459+
allCode: "",
460+
allLines: [],
461+
commandName: "Generate Code",
462+
description: "Hello world",
463+
isResponding: false,
464+
isAttachedToSelectionRange: true,
465+
selectionRange: .init(
466+
start: .init(line: 8, character: 0),
467+
end: .init(line: 12, character: 2)
468+
)
469+
), reducer: PromptToCode()))
470+
.frame(width: 450, height: 400)
471+
}
472+
440473
struct PromptToCodePanel_Error_Detached_Preview: PreviewProvider {
441474
static var previews: some View {
442475
PromptToCodePanel(store: .init(initialState: .init(

0 commit comments

Comments
 (0)