@@ -193,6 +193,7 @@ func (dv *DiffView) clearSyntaxCache() {
194// String returns the string representation of the DiffView.
194// String returns the string representation of the DiffView.
195func (dv *DiffView) String() string {
195func (dv *DiffView) String() string {
196+ dv.normalizeLineEndings()
196 dv.replaceTabs()
197 dv.replaceTabs()
197 if err := dv.computeDiff(); err != nil {
198 if err := dv.computeDiff(); err != nil {
198 return err.Error()
199 return err.Error()
@@ -227,6 +228,12 @@ func (dv *DiffView) String() string {
231+// normalizeLineEndings ensures the file contents use Unix-style line endings.
232+func (dv *DiffView) normalizeLineEndings() {
233+ dv.before.content = strings.ReplaceAll(dv.before.content, "\r\n", "\n")
234+ dv.after.content = strings.ReplaceAll(dv.after.content, "\r\n", "\n")
230// replaceTabs replaces tabs in the before and after file contents with spaces
237// replaceTabs replaces tabs in the before and after file contents with spaces
231// according to the specified tab width.
238// according to the specified tab width.
232func (dv *DiffView) replaceTabs() {
239func (dv *DiffView) replaceTabs() {
@@ -396,8 +403,7 @@ func (dv *DiffView) renderUnified() string {
396 shouldWrite := func() bool { return printedLines >= 0 }
403 shouldWrite := func() bool { return printedLines >= 0 }
398 getContent := func(in string, ls LineStyle) (content string, leadingEllipsis bool) {
405 getContent := func(in string, ls LineStyle) (content string, leadingEllipsis bool) {
399− content = strings.ReplaceAll(in, "\r\n", "\n")
406+ content = strings.TrimSuffix(in, "\n")
400− content = strings.TrimSuffix(content, "\n")
401 content = dv.hightlightCode(content, ls.Code.GetBackground())
407 content = dv.hightlightCode(content, ls.Code.GetBackground())
402 content = ansi.GraphemeWidth.Cut(content, dv.xOffset, len(content))
408 content = ansi.GraphemeWidth.Cut(content, dv.xOffset, len(content))
403 content = ansi.Truncate(content, dv.codeWidth, "…")
409 content = ansi.Truncate(content, dv.codeWidth, "…")
@@ -520,8 +526,7 @@ func (dv *DiffView) renderSplit() string {
520 shouldWrite := func() bool { return printedLines >= 0 }
526 shouldWrite := func() bool { return printedLines >= 0 }
522 getContent := func(in string, ls LineStyle) (content string, leadingEllipsis bool) {
528 getContent := func(in string, ls LineStyle) (content string, leadingEllipsis bool) {
523− content = strings.ReplaceAll(in, "\r\n", "\n")
529+ content = strings.TrimSuffix(in, "\n")
524− content = strings.TrimSuffix(content, "\n")
525 content = dv.hightlightCode(content, ls.Code.GetBackground())
530 content = dv.hightlightCode(content, ls.Code.GetBackground())
526 content = ansi.GraphemeWidth.Cut(content, dv.xOffset, len(content))
531 content = ansi.GraphemeWidth.Cut(content, dv.xOffset, len(content))
527 content = ansi.Truncate(content, dv.codeWidth, "…")
532 content = ansi.Truncate(content, dv.codeWidth, "…")