@@ -193,6 +193,7 @@ func (dv *DiffView) clearSyntaxCache() {
193193
194194// String returns the string representation of the DiffView.
195195func (dv *DiffView) String() string {
196+ dv.normalizeLineEndings()
196197 dv.replaceTabs()
197198 if err := dv.computeDiff(); err != nil {
198199 return err.Error()
@@ -227,6 +228,12 @@ func (dv *DiffView) String() string {
227228 }
228229}
229230
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")
235+}
236+
230237// replaceTabs replaces tabs in the before and after file contents with spaces
231238// according to the specified tab width.
232239func (dv *DiffView) replaceTabs() {
@@ -396,8 +403,7 @@ func (dv *DiffView) renderUnified() string {
396403 shouldWrite := func() bool { return printedLines >= 0 }
397404
398405 getContent := func(in string, ls LineStyle) (content string, leadingEllipsis bool) {
399− content = strings.ReplaceAll(in, "\r\n", "\n")
400− content = strings.TrimSuffix(content, "\n")
406+ content = strings.TrimSuffix(in, "\n")
401407 content = dv.hightlightCode(content, ls.Code.GetBackground())
402408 content = ansi.GraphemeWidth.Cut(content, dv.xOffset, len(content))
403409 content = ansi.Truncate(content, dv.codeWidth, "…")
@@ -520,8 +526,7 @@ func (dv *DiffView) renderSplit() string {
520526 shouldWrite := func() bool { return printedLines >= 0 }
521527
522528 getContent := func(in string, ls LineStyle) (content string, leadingEllipsis bool) {
523− content = strings.ReplaceAll(in, "\r\n", "\n")
524− content = strings.TrimSuffix(content, "\n")
529+ content = strings.TrimSuffix(in, "\n")
525530 content = dv.hightlightCode(content, ls.Code.GetBackground())
526531 content = ansi.GraphemeWidth.Cut(content, dv.xOffset, len(content))
527532 content = ansi.Truncate(content, dv.codeWidth, "…")