From 41273a4d0725cd0f098184e01fee4e1a2516ae87 Mon Sep 17 00:00:00 2001 From: yuin Date: Sat, 12 Oct 2024 23:05:37 +0900 Subject: [PATCH] Fix EOF rendering --- _test/extra.txt | 13 ++++++++++++- text/segment.go | 10 ++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/_test/extra.txt b/_test/extra.txt index 63e3c8f..66359bb 100644 --- a/_test/extra.txt +++ b/_test/extra.txt @@ -821,7 +821,7 @@ text" />

//= = = = = = = = = = = = = = = = = = = = = = = =// -66: EOF should be rendered as a newline with an unclosed block +66: EOF should be rendered as a newline with an unclosed block(w/ TAB) //- - - - - - - - -// > ``` > 0 @@ -831,3 +831,14 @@ text" />

//= = = = = = = = = = = = = = = = = = = = = = = =// + +67: EOF should be rendered as a newline with an unclosed block +//- - - - - - - - -// +> ``` +> 0 +//- - - - - - - - -// +
+
 0
+
+
+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/text/segment.go b/text/segment.go index 3198d84..83c875b 100644 --- a/text/segment.go +++ b/text/segment.go @@ -44,12 +44,14 @@ func NewSegmentPadding(start, stop, n int) Segment { // Value returns a value of the segment. func (t *Segment) Value(buffer []byte) []byte { + var result []byte if t.Padding == 0 { - return buffer[t.Start:t.Stop] + result = buffer[t.Start:t.Stop] + } else { + result = make([]byte, 0, t.Padding+t.Stop-t.Start+1) + result = append(result, bytes.Repeat(space, t.Padding)...) + result = append(result, buffer[t.Start:t.Stop]...) } - result := make([]byte, 0, t.Padding+t.Stop-t.Start+1) - result = append(result, bytes.Repeat(space, t.Padding)...) - result = append(result, buffer[t.Start:t.Stop]...) if t.EOB && len(result) > 0 && result[len(result)-1] != '\n' { result = append(result, '\n') }