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:
Claude
2026-09-24 09:16:04 -07:00
committed by Kyle Isom
parent 91ceb9bb01
commit 93901928da
8 changed files with 119 additions and 14 deletions
+41
View File
@@ -1198,3 +1198,44 @@ TEST(Audit_InsertText_RepeatCount)
ASSERT_TRUE(h.Undo());
ASSERT_EQ(h.Text(), std::string(""));
}
// A reload confirmation is cancelled by any other command, so a later C-k l
// (after, say, moving the cursor) asks again instead of discarding edits.
TEST(Audit_Reload_ConfirmationCancelledByOtherCommand)
{
TempDir d("reload_cancel");
const std::string file = (d.path / "r.txt").string();
std::ofstream(file) << "disk\n";
TestHarness h;
Editor &ed = h.EditorRef();
std::string err;
ASSERT_TRUE(ed.OpenFile(file, err));
ASSERT_TRUE(h.Exec(CommandId::InsertText, "EDIT "));
ASSERT_TRUE(h.Exec(CommandId::ReloadBuffer));
(void) h.Exec(CommandId::MoveRight);
ASSERT_TRUE(h.Exec(CommandId::ReloadBuffer));
ASSERT_EQ(h.Line(0), std::string("EDIT disk"));
ASSERT_TRUE(h.Exec(CommandId::ReloadBuffer));
ASSERT_EQ(h.Line(0), std::string("disk"));
}
// Buffer ids: copies get a fresh id, moves keep it, so caches keyed on the
// id never mistake a new buffer at a reused address for the old one.
TEST(Audit_BufferId_StableAcrossMovesUniqueForCopies)
{
Buffer a;
const std::uint64_t id = a.Id();
ASSERT_TRUE(id != 0);
Buffer b(a);
ASSERT_TRUE(b.Id() != id);
Buffer c(std::move(a));
ASSERT_EQ(c.Id(), id);
Buffer e;
e = std::move(c);
ASSERT_EQ(e.Id(), id);
Buffer f;
f = e;
ASSERT_TRUE(f.Id() != id);
}