Enhance UI feedback and improve file diff visualization

- Improve diff display in permission dialogs with better formatting
- Add visual indicators for focus changes in permission dialogs
- Increase diagnostics timeout from 5 to 10 seconds
- Fix write tool to show proper diffs for existing files
- Update status component to properly handle messages

🤖 Generated with termai
Co-Authored-By: termai <noreply@termai.io>
This commit is contained in:
Kujtim Hoxha 2025-04-04 14:36:57 +02:00
parent 6bb1c84f7f
commit c185dc84d6
5 changed files with 87 additions and 22 deletions

View file

@ -303,23 +303,46 @@ func GenerateDiff(oldContent, newContent string) string {
diffs = dmp.DiffCharsToLines(diffs, dmpStrings)
diffs = dmp.DiffCleanupSemantic(diffs)
buff := strings.Builder{}
// Add a header to make the diff more readable
buff.WriteString("Changes:\n")
for _, diff := range diffs {
text := diff.Text
switch diff.Type {
case diffmatchpatch.DiffInsert:
for line := range strings.SplitSeq(text, "\n") {
for _, line := range strings.Split(text, "\n") {
if line == "" {
continue
}
_, _ = buff.WriteString("+ " + line + "\n")
}
case diffmatchpatch.DiffDelete:
for line := range strings.SplitSeq(text, "\n") {
for _, line := range strings.Split(text, "\n") {
if line == "" {
continue
}
_, _ = buff.WriteString("- " + line + "\n")
}
case diffmatchpatch.DiffEqual:
if len(text) > 40 {
_, _ = buff.WriteString(" " + text[:20] + "..." + text[len(text)-20:] + "\n")
// Only show a small context for unchanged text
lines := strings.Split(text, "\n")
if len(lines) > 3 {
// Show only first and last line of context with a separator
if lines[0] != "" {
_, _ = buff.WriteString(" " + lines[0] + "\n")
}
_, _ = buff.WriteString(" ...\n")
if lines[len(lines)-1] != "" {
_, _ = buff.WriteString(" " + lines[len(lines)-1] + "\n")
}
} else {
for line := range strings.SplitSeq(text, "\n") {
// Show all lines for small contexts
for _, line := range lines {
if line == "" {
continue
}
_, _ = buff.WriteString(" " + line + "\n")
}
}