diff --git a/include/internal/buffer/buffer.h b/include/internal/buffer/buffer.h index c9a61de..870224e 100644 --- a/include/internal/buffer/buffer.h +++ b/include/internal/buffer/buffer.h @@ -16,9 +16,13 @@ struct Buffer { uint64_t line = 0; bool modified; std::filesystem::path save_path = ""; + struct { uint64_t start{0}; uint64_t end{0}; + std::span values() const { + return {&start, 2}; + } } prev_range; Buffer(); diff --git a/include/internal/commands/suffixes.h b/include/internal/commands/suffixes.h index 454ad7f..82a4bbc 100644 --- a/include/internal/commands/suffixes.h +++ b/include/internal/commands/suffixes.h @@ -6,7 +6,7 @@ namespace bed::internal::commands { struct Suffix { std::string desc; - void (*handle)(BEd &); + void (*handle)(BEd &, std::span); static void register_suffixes(BEd &ctx); }; diff --git a/src/bed/handle.cc b/src/bed/handle.cc index 902747e..426296d 100644 --- a/src/bed/handle.cc +++ b/src/bed/handle.cc @@ -90,12 +90,12 @@ void BEd::handle(std::string_view cmd_, bool eof) { break; } if (suffix) - suffix->handle(*this); + suffix->handle(*this, active->prev_range.values()); return; } void BEd::suffix_handle(char s) { if (suffixes[s - 'a'].has_value()) - suffixes[s - 'a'].value().handle(*this); + suffixes[s - 'a'].value().handle(*this, active->prev_range.values()); } } // namespace bed diff --git a/src/internal/commands/commands.cc b/src/internal/commands/commands.cc index d33a336..fbfc6a1 100644 --- a/src/internal/commands/commands.cc +++ b/src/internal/commands/commands.cc @@ -6,18 +6,14 @@ namespace bed::internal::commands { void Suffix::register_suffixes(BEd &ctx) { ctx.suffixes['p' - 'a'] = Suffix{ .desc = "Prints current line.", - .handle = [](BEd &ctx) { - auto line = ctx.active->line; - ctx.active->print(ctx, line, line); - ctx.active->jump(line); + .handle = [](BEd &ctx, std::span addresses) { + ctx.active->print(ctx, addresses[0], addresses[1]); } }; ctx.suffixes['n' - 'a'] = Suffix{ .desc = "Prints current line with line number.", - .handle = [](BEd &ctx) { - auto line = ctx.active->line; - ctx.active->number_print(ctx, line, line); - ctx.active->jump(line); + .handle = [](BEd &ctx, std::span addresses) { + ctx.active->number_print(ctx, addresses[0], addresses[1]); } }; }