Skip to content

Long lines get silently truncated in the diff viewer #99

@fgrehm

Description

@fgrehm

What's happening

Any diff line longer than the viewport width gets cut off with no way to see the rest. No horizontal scrolling, no wrapping -- the content is just gone.

Weird thing is it happens in two places:

  1. delta is called with --max-line-length=<width>, so it clips before output even arrives.

    useSideBySide := sideBySide && !file.IsNew && !file.IsDelete
    args := []string{
    "--paging=never",
    fmt.Sprintf("-w=%d", width),
    fmt.Sprintf("--max-line-length=%d", width),
    }
    if useSideBySide {
    args = append(args, "--side-by-side")
    }
    deltac := exec.Command("delta", args...)
    deltac.Env = os.Environ()
    deltac.Stdin = strings.NewReader(file.String() + "\n")
    out, err := deltac.Output()

  2. Then there's a post-processing pass that truncates anything still wider than the viewport

    case diffContentMsg:
    // Truncate lines to viewport width to prevent ANSI escape overflow.
    lines := strings.Split(msg.text, "\n")
    for i, line := range lines {
    if lipgloss.Width(line) > m.vp.Width() && m.vp.Width() > 0 {
    lines[i] = ansi.Truncate(line, m.vp.Width(), "")
    }
    }
    diff := strings.Join(lines, "\n")
    if _, ok := m.cache[msg.cacheKey]; ok {
    m.cache[msg.cacheKey].diff = diff
    }
    m.vp.SetContent(diff)
    }

(The comment there says "to prevent ANSI escape overflow", so I get why it's there but the result is you can't read long lines at all 😬 )

To reproduce

Just use any diff with long lines and / or narrow your terminal a bit and the content just disappears at the right edge.

What I'd expect

Either:

  • word wraping: long lines continue on the next visual line (could use muesli/reflow/wrap which is already in go.mod)
  • or horizontal scrolling: left/right keybinds to pan the viewport

Happy to put up a PR if you have a preference on the approach 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions