Skip to content

Commit 01d0747

Browse files
committed
[attr_line] shift start position needs to account for erased
1 parent 76c1114 commit 01d0747

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/base/ansi_scrubber.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ scrub_ansi_string(std::string& str, string_attrs_t* sa)
465465
}
466466
if (md[1] || md[3] || md[5]) {
467467
if (sa != nullptr) {
468-
shift_string_attrs(*sa, sf.sf_begin, -sf.length());
468+
shift_string_attrs(*sa, sf.sf_begin - erased, -sf.length());
469469
if (has_attrs) {
470470
for (auto tmp_sa_curr = tmp_sa_open;
471471
tmp_sa_curr < tmp_sa.size();

src/base/attr_line.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ line_range::shift(int32_t start, int32_t amount)
907907
this->lr_end = std::max(0, this->lr_end + amount);
908908
}
909909
} else if (this->lr_end != -1) {
910-
if (start <= this->lr_end) {
910+
if (start < this->lr_end) {
911911
if (amount < 0 && amount < (start - this->lr_end)) {
912912
this->lr_end = start + amount;
913913
} else {

test/test_ansi_scrubber.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ main(int argc, char* argv[])
4848
{
4949
printf("BEGIN test\n");
5050

51+
{
52+
auto input = std::string("\x1b[33mHello\x1b[0m");
53+
string_attrs_t sa;
54+
55+
auto lr = line_range{0, (int) input.size()};
56+
sa.emplace_back(lr, SA_ORIGINAL_LINE.value());
57+
58+
scrub_ansi_string(input, &sa);
59+
assert(sa[0].sa_range.lr_end == input.size());
60+
assert("Hello" == input);
61+
}
62+
5163
{
5264
auto input = std::string("\0Hello", 6);
5365
string_attrs_t sa;

0 commit comments

Comments
 (0)