Force a UTF-8 ctype, stable buffer ids, redraw after deferred opens
- main: when the environment's locale is not UTF-8 (LANG unset, C/POSIX), switch LC_CTYPE to a UTF-8 locale so ncurses delivers and draws multibyte characters instead of dropping them. - Buffer::Id(): a process-unique id that survives moves and is fresh for copies. The terminal renderer's skip and cursor caches and the reload confirmation now key on it rather than the buffer's address, which is reused after a buffer is closed. - The reload confirmation is cancelled by any other command, like the quit confirmation. - TerminalFrontend redraws when a deferred open starts a prompt or sets a status (e.g. the swap recovery question), not only when a buffer opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
+14
-6
@@ -5383,6 +5383,13 @@ cmd_reflow_paragraph(CommandContext &ctx)
|
||||
}
|
||||
|
||||
|
||||
// Pending reload confirmation: the buffer (by Id(), since addresses are
|
||||
// reused once a buffer is closed) and its version when it was armed. Any
|
||||
// other command cancels it (see Execute).
|
||||
static std::uint64_t reload_confirm_id = 0;
|
||||
static std::uint64_t reload_confirm_version = 0;
|
||||
|
||||
|
||||
static bool
|
||||
cmd_reload_buffer(CommandContext &ctx)
|
||||
{
|
||||
@@ -5404,15 +5411,13 @@ cmd_reload_buffer(CommandContext &ctx)
|
||||
}
|
||||
// Reload discards unsaved edits (and their undo history and journal), so
|
||||
// a dirty buffer needs a second C-k l with no edit in between.
|
||||
static const Buffer *confirm_buf = nullptr;
|
||||
static std::uint64_t confirm_version = 0;
|
||||
if (buf->Dirty() && !(confirm_buf == buf && confirm_version == buf->Version())) {
|
||||
confirm_buf = buf;
|
||||
confirm_version = buf->Version();
|
||||
if (buf->Dirty() && !(reload_confirm_id == buf->Id() && reload_confirm_version == buf->Version())) {
|
||||
reload_confirm_id = buf->Id();
|
||||
reload_confirm_version = buf->Version();
|
||||
ctx.editor.SetStatus("Unsaved changes will be lost. C-k l again to reload anyway");
|
||||
return true;
|
||||
}
|
||||
confirm_buf = nullptr;
|
||||
reload_confirm_id = 0;
|
||||
std::string err;
|
||||
if (!buf->OpenFromFile(filename, err)) {
|
||||
ctx.editor.SetStatus(std::string("Reload failed: ") + err);
|
||||
@@ -5749,6 +5754,9 @@ Execute(Editor &ed, CommandId id, const std::string &arg, int count)
|
||||
if (ed.QuitConfirmPending() && id != CommandId::Quit && id != CommandId::KPrefix) {
|
||||
ed.SetQuitConfirmPending(false);
|
||||
}
|
||||
// Likewise a pending reload confirmation.
|
||||
if (id != CommandId::ReloadBuffer && id != CommandId::KPrefix)
|
||||
reload_confirm_id = 0;
|
||||
// Reset kill chain unless this is a kill-like command (so consecutive kills append)
|
||||
if (id != CommandId::KillToEOL && id != CommandId::KillLine && id != CommandId::KillRegion && id !=
|
||||
CommandId::CopyRegion && id != CommandId::DeleteWordPrev && id != CommandId::DeleteWordNext) {
|
||||
|
||||
Reference in New Issue
Block a user