Add support for creating a new empty buffer (C-k i).
- Introduced `BufferNew` command to create and switch to a new unnamed buffer. - Registered `BufferNew` in the command registry and updated keymap and help text. - Implemented `cmd_buffer_new()` to handle buffer creation and switching logic.
This commit is contained in:
14
Command.cc
14
Command.cc
@@ -1585,6 +1585,19 @@ cmd_buffer_close(const CommandContext &ctx)
|
||||
}
|
||||
|
||||
|
||||
// Create a new empty, unnamed buffer and switch to it
|
||||
static bool
|
||||
cmd_buffer_new(const CommandContext &ctx)
|
||||
{
|
||||
// Create an empty buffer and add it to the editor
|
||||
Buffer empty;
|
||||
std::size_t idx = ctx.editor.AddBuffer(std::move(empty));
|
||||
ctx.editor.SwitchTo(idx);
|
||||
ctx.editor.SetStatus("New buffer");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// --- Editing ---
|
||||
static bool
|
||||
cmd_insert_text(CommandContext &ctx)
|
||||
@@ -4378,6 +4391,7 @@ InstallDefaultCommands()
|
||||
CommandId::BufferSwitchStart, "buffer-switch-start", "Begin buffer switch prompt",
|
||||
cmd_buffer_switch_start, false, false
|
||||
});
|
||||
CommandRegistry::Register({CommandId::BufferNew, "buffer-new", "Open new empty buffer", cmd_buffer_new});
|
||||
CommandRegistry::Register({CommandId::BufferNext, "buffer-next", "Switch to next buffer", cmd_buffer_next});
|
||||
CommandRegistry::Register({CommandId::BufferPrev, "buffer-prev", "Switch to previous buffer", cmd_buffer_prev});
|
||||
CommandRegistry::Register({
|
||||
|
||||
@@ -31,6 +31,7 @@ enum class CommandId {
|
||||
VisualFontPickerToggle,
|
||||
// Buffers
|
||||
BufferSwitchStart, // begin buffer switch prompt
|
||||
BufferNew, // create a new empty, unnamed buffer (C-k i)
|
||||
BufferClose,
|
||||
BufferNext,
|
||||
BufferPrev,
|
||||
|
||||
@@ -31,6 +31,7 @@ HelpText::Text()
|
||||
" C-k c Close current buffer\n"
|
||||
" C-k d Kill to end of line\n"
|
||||
" C-k e Open file (prompt)\n"
|
||||
" C-k i New empty buffer\n"
|
||||
" C-k f Flush kill ring\n"
|
||||
" C-k g Jump to line\n"
|
||||
" C-k h Show this help\n"
|
||||
|
||||
@@ -42,6 +42,9 @@ KLookupKCommand(const int ascii_key, const bool ctrl, CommandId &out) -> bool
|
||||
case 'a':
|
||||
out = CommandId::MarkAllAndJumpEnd;
|
||||
return true;
|
||||
case 'i':
|
||||
out = CommandId::BufferNew; // C-k i new empty buffer
|
||||
return true;
|
||||
case 'k':
|
||||
out = CommandId::CenterOnCursor; // C-k k center current line
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user