Reflow: per-line CR handling; do not wrap before a marker-like word

- The CRLF handling applied only when every line of the paragraph ended
  in CR, so the last paragraph of a CRLF file without a final newline
  (and mixed CRLF/LF paragraphs) still had CRs joined into the middle of
  lines. Each line's CR is now stripped; if any line had one, every new
  line but the last ends in CR, and the last keeps what the paragraph's
  last line had.
- Wrapping never starts a line with a word that reads as a list marker
  ('-', '*', '+', '1.', '2)'); the next reflow turned such a paragraph
  into a list.

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 790fbc90e1
commit b9dffd8645
2 changed files with 54 additions and 6 deletions
+31
View File
@@ -1592,6 +1592,37 @@ TEST(Audit_Reflow_BlankishSeparatorAndCrlf)
ASSERT_TRUE(h.Undo());
ASSERT_EQ(h.Text(), std::string("one two\r\nthree four\r\nfive\r\n\r\nnext\r\n"));
}
{
// CRLF file without a final line ending: the last line has no CR.
TestHarness h;
h.Buf().insert_text(0, 0, "aaa bbb\r\nccc ddd\r\neee");
h.Buf().SetCursor(0, 0);
ASSERT_TRUE(h.Exec(CommandId::ReflowParagraph));
ASSERT_EQ(h.Text(), std::string("aaa bbb ccc ddd eee"));
}
{
TestHarness h;
h.Buf().insert_text(0, 0, "aaa bbb\r\nccc ddd\r\neee");
h.Buf().SetCursor(0, 0);
ASSERT_TRUE(h.Exec(CommandId::ReflowParagraph, "", 8));
ASSERT_EQ(h.Text(), std::string("aaa bbb\r\nccc ddd\r\neee"));
}
}
// Reflow does not wrap right before a word that would then read as a list
// marker ("-", "1."), which turned the paragraph into a list next time.
TEST(Audit_Reflow_NoWrapBeforeMarkerWord)
{
TestHarness h;
h.Buf().insert_text(0, 0, "alpha beta - gamma delta\n");
h.Buf().SetCursor(0, 0);
ASSERT_TRUE(h.Exec(CommandId::ReflowParagraph, "", 11));
const std::string once = h.Text();
ASSERT_EQ(once, std::string("alpha beta -\ngamma delta\n"));
h.Buf().SetCursor(0, 0);
ASSERT_TRUE(h.Exec(CommandId::ReflowParagraph, "", 11));
ASSERT_EQ(h.Text(), once);
}