diff --git a/src/internal/buffer/generic.cc b/src/internal/buffer/generic.cc index 2a0932e..7a822e4 100644 --- a/src/internal/buffer/generic.cc +++ b/src/internal/buffer/generic.cc @@ -221,6 +221,7 @@ void GenericBuffer::load(BEd &ctx, vase::Shard *text) { ctx.prev().start = 1; ctx.prev().end = text->lines + 1; } + ctx.current() = {name, lines()}; syntax::release(parse); parse = syntax::make_parser(root, lines(), ctx.languages["ruby"]); } @@ -240,6 +241,7 @@ void GenericBuffer::append(BEd &ctx, vase::Shard *text, uint64_t line) { ctx.prev().buffername = name; ctx.prev().start = line + 1; ctx.prev().end = line + text->lines + 1; + ctx.current() = {name, line + text->lines + 1}; root = vase::insert(&ctx.append, root, text, line); ctx.marks.insert(name, line, text->lines + 1); if (parse.lang) @@ -251,8 +253,10 @@ void GenericBuffer::remove(BEd &ctx, uint64_t start_line, uint64_t end_line) { snapshot(std::format("Remove lines {} to {}", start_line, end_line)); root = vase::erase(root, start_line, end_line); ctx.prev().buffername = name; - ctx.prev().start = std::min(start_line, lines()); - ctx.prev().end = std::min(start_line, lines()); + uint64_t l = std::min(start_line, lines()); + ctx.prev().start = l; + ctx.prev().end = l; + ctx.current() = {name, l}; ctx.marks.erase(name, start_line, end_line - start_line + 1); if (parse.lang) syntax::erase(parse, root, start_line, end_line - start_line + 1); @@ -268,6 +272,7 @@ void GenericBuffer::replace(BEd &ctx, vase::Shard *text, uint64_t start_line, ui ctx.prev().buffername = name; ctx.prev().start = start_line; ctx.prev().end = start_line + text->lines; + ctx.current() = {name, start_line + text->lines}; uint64_t new_count = text->lines + 1; uint64_t old_count = end_line - start_line + 1; root = vase::replace(root, text, start_line, end_line); @@ -293,6 +298,7 @@ void GenericBuffer::join(BEd &ctx, uint64_t start_line, uint64_t end_line) { ctx.prev().buffername = name; ctx.prev().start = start_line; ctx.prev().end = start_line; + ctx.current() = {name, start_line}; ctx.marks.collapse(name, start_line, end_line - start_line); if (parse.lang) syntax::erase(parse, root, start_line, end_line - start_line); @@ -329,11 +335,11 @@ void GenericBuffer::substitute( if (edit) edit->insert(line, new_lines); } + ctx.current() = {name, line + new_lines}; } ); if (edit) edit->commit(root); - ctx.prev().buffername = name; state = Modified; } } // namespace bed::internal::buffer diff --git a/src/internal/functions/extended.cc b/src/internal/functions/extended.cc index 5a6333a..ffaafe3 100644 --- a/src/internal/functions/extended.cc +++ b/src/internal/functions/extended.cc @@ -93,7 +93,6 @@ void Function::register_extented(BEd &ctx) { vase::Shard::release(text); throw; } - ctx.current() = {arg.buffername, arg.start + addr.end - addr.start + 1}; }, } ); diff --git a/src/internal/functions/posix.cc b/src/internal/functions/posix.cc index 03cd760..3e2d28c 100644 --- a/src/internal/functions/posix.cc +++ b/src/internal/functions/posix.cc @@ -47,7 +47,6 @@ void Function::register_posix(BEd &ctx) { ) { auto addr = std::get(addr_); ctx.buffer(addr.buffername).append(ctx, text, addr.number); - ctx.current() = {ctx.prev().buffername, ctx.prev().end}; vase::Shard::release(text); } } @@ -71,7 +70,6 @@ void Function::register_posix(BEd &ctx) { ) { auto addr = std::get(addr_); ctx.buffer(addr.buffername).replace(ctx, text, addr.start, addr.end); - ctx.current() = {ctx.prev().buffername, ctx.prev().end}; vase::Shard::release(text); } } @@ -95,7 +93,6 @@ void Function::register_posix(BEd &ctx) { ) { auto addr = std::get(addr_); ctx.buffer(addr.buffername).remove(ctx, addr.start, addr.end); - ctx.current() = {addr.buffername, addr.start}; } } ); @@ -145,7 +142,6 @@ void Function::register_posix(BEd &ctx) { throw; } ctx.io.write_line(std::format("{}", buf.bytes())); - ctx.current() = {addr, buf.lines()}; } } ); @@ -191,7 +187,6 @@ void Function::register_posix(BEd &ctx) { throw; } ctx.io.write_line(std::format("{}", buf.bytes())); - ctx.current() = {addr, buf.lines()}; } } ); @@ -289,7 +284,6 @@ void Function::register_posix(BEd &ctx) { if (addr.number) addr.number--; ctx.buffer(addr.buffername).append(ctx, text, addr.number); - ctx.current() = {ctx.prev().buffername, ctx.prev().end}; vase::Shard::release(text); } } @@ -313,7 +307,6 @@ void Function::register_posix(BEd &ctx) { ) { auto addr = std::get(addr_); ctx.buffer(addr.buffername).join(ctx, addr.start, addr.end); - ctx.current() = {addr.buffername, addr.start}; } } ); @@ -403,7 +396,6 @@ void Function::register_posix(BEd &ctx) { vase::Shard::release(text); throw; } - ctx.current() = {arg.buffername, arg.number + addr.end - addr.start + 1}; }, } ); @@ -567,7 +559,6 @@ void Function::register_posix(BEd &ctx) { try { buf.append(ctx, s, addr.number); ctx.io.write_line(std::format("{}", s ? s->length + 1 : 0)); - ctx.current() = {addr.buffername, addr.number + (s ? s->lines + 1 : 0)}; vase::Shard::release(s); } catch (...) { vase::Shard::release(s); @@ -642,7 +633,6 @@ void Function::register_posix(BEd &ctx) { vase::Shard::release(text); throw; } - ctx.current() = {arg.buffername, arg.number + addr.end - addr.start + 1}; }, } ); @@ -746,6 +736,9 @@ void Function::register_posix(BEd &ctx) { ctx.io.write_line(std::format(":{}:{}", addr.buffername, addr.start)); else ctx.io.write_line(std::format(":{}:{},{}", addr.buffername, addr.start, addr.end)); + ctx.prev().buffername = addr.buffername; + ctx.prev().start = addr.start; + ctx.prev().end = addr.end; ctx.current() = {addr.buffername, addr.end}; }, } diff --git a/src/internal/parser/operation.cc b/src/internal/parser/operation.cc index 1cddf16..8270c70 100644 --- a/src/internal/parser/operation.cc +++ b/src/internal/parser/operation.cc @@ -165,12 +165,13 @@ void Parser::operation() { j++; } std::string replacement(peek_str(j)); + std::string options; if (peek(j) != '\0') { advance(j + 1); } else { advance(j); + options = "p"; } - std::string options; if (peek() != '\0') { options = std::string(peek_str()); advance(peek_str().size()); diff --git a/src/internal/vase/regex/api.cc b/src/internal/vase/regex/api.cc index 121107d..47f0254 100644 --- a/src/internal/vase/regex/api.cc +++ b/src/internal/vase/regex/api.cc @@ -90,12 +90,7 @@ Shard *substitute( if (matches.empty()) return root; std::vector replace_parts = parse_replace(ap, replace); - struct Edit { - uint64_t line; - uint64_t old_lines; - uint64_t new_lines; - }; - uint64_t orig_line = start; + uint64_t current_line = 1; int64_t line_delta = 0; std::vector pieces; pieces.reserve(matches.size() * 2 + 1); @@ -109,7 +104,7 @@ Shard *substitute( Shard::release(remaining); pieces.push_back(keep); remaining = rest; - orig_line += keep ? keep->lines : 0; + current_line += keep ? keep->lines : 0; } auto [dropped, rest2] = Shard::split(remaining, match.end - match.start); Shard::release(remaining); @@ -152,13 +147,11 @@ Shard *substitute( } } Shard::release(dropped); - if (old_lines || new_lines) { - uint64_t report_line = (uint64_t)((int64_t)orig_line + line_delta); - if (on_edit) - on_edit(report_line, old_lines, new_lines); - line_delta += (int64_t)new_lines - (int64_t)old_lines; - } - orig_line += old_lines; + uint64_t report_line = (uint64_t)((int64_t)current_line + line_delta); + if (on_edit) + on_edit(report_line, old_lines, new_lines); + line_delta += (int64_t)new_lines - (int64_t)old_lines; + current_line += old_lines; cursor = match.end; } pieces.push_back(remaining);