Dont drop trailing escape codes when stripping trailing whitespace
This commit is contained in:
@@ -254,7 +254,14 @@ type line_builder struct {
|
|||||||
func (self *line_builder) reset() string {
|
func (self *line_builder) reset() string {
|
||||||
ans := self.buf.String()
|
ans := self.buf.String()
|
||||||
if len(ans) > self.last_text_pos {
|
if len(ans) > self.last_text_pos {
|
||||||
ans = ans[:self.last_text_pos]
|
prefix := ans[:self.last_text_pos]
|
||||||
|
suffix := ans[self.last_text_pos:]
|
||||||
|
prefix = strings.TrimRightFunc(prefix, unicode.IsSpace)
|
||||||
|
if len(prefix) != self.last_text_pos {
|
||||||
|
ans = prefix + suffix
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ans = strings.TrimRightFunc(ans, unicode.IsSpace)
|
||||||
}
|
}
|
||||||
sz := self.buf.Len()
|
sz := self.buf.Len()
|
||||||
self.buf.Reset()
|
self.buf.Reset()
|
||||||
@@ -316,7 +323,6 @@ func (self *wrapper) newline_prefix() {
|
|||||||
|
|
||||||
func (self *wrapper) end_current_line() {
|
func (self *wrapper) end_current_line() {
|
||||||
line := self.current_line.reset()
|
line := self.current_line.reset()
|
||||||
line = strings.TrimRightFunc(line, unicode.IsSpace)
|
|
||||||
if strings.HasSuffix(line, self.indent) && wcswidth.Stringwidth(line) == self.indent_width {
|
if strings.HasSuffix(line, self.indent) && wcswidth.Stringwidth(line) == self.indent_width {
|
||||||
line = line[:len(line)-len(self.indent)]
|
line = line[:len(line)-len(self.indent)]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ func TestFormatWithIndent(t *testing.T) {
|
|||||||
tx("testing\n\ntwo", "testing\n\n__two")
|
tx("testing\n\ntwo", "testing\n\n__two")
|
||||||
tx("testing\n \ntwo", "testing\n\n__two")
|
tx("testing\n \ntwo", "testing\n\n__two")
|
||||||
|
|
||||||
tx("123456 \x1b[31m789a", "123456\n\x1b[39m__\x1b[31m789a")
|
tx("123456 \x1b[31m789a", "123456\x1b[31m\n\x1b[39m__\x1b[31m789a")
|
||||||
tx("12 \x1b[31m789 abcd", "12 \x1b[31m789\n\x1b[39m__\x1b[31mabcd")
|
tx("12 \x1b[31m789 abcd", "12 \x1b[31m789\n\x1b[39m__\x1b[31mabcd")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user