Skip to content

Add WriteLines to write multi-line text at the current indent [minor] - #181

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/179-write-lines
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/179-write-lines

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #179

What changed

WriteLine(string) and Write(string) pass their text straight to IndentedTextWriter, which indents only the first line. As the issue suggests, they stay as they are, and a new public method, CodeBlocker.WriteLines(string fragment), does the following:

  • splits the text at \r\n, \n and \r, and writes each line at the current indent, ending it with NewLineString. An LF writer never ends up with mixed line endings.
  • writes blank lines through NewLine(), so they carry no indentation.
  • leaves a line break inside a verbatim literal (@"...", $@"...") exactly as written. It uses the same VerbatimStringScanner as SplitLines, so the literal's value never changes.
  • leaves the last line open when the text has no trailing break, the same as Write, so isMidLine matches how the text ends. When it is called mid-line, the first segment finishes the line already under way.
  • does nothing for null or "".

It does not reuse SpliceFragment directly, because SplitLines splits only at NewLineString. With an LF writer, CRLF input would keep its \r.

README's API table and CLAUDE.md now list the method.

Tests

WriteLinesTests adds 8 cases:

  • the issue's repro, where every line lands at →
  • \r\n and \r input on an LF writer
  • a multi-line @"..." literal containing \r\n
  • interior blank lines
  • an open last line
  • a call made mid-line
  • null/empty (two cases)

With WriteLines reduced to Write(fragment), the 6 behavioural tests fail. The null/empty cases pass either way by design. With the change, the full suite passes: 257/257.


Generated by Claude Code

WriteLine and Write hand their text straight to IndentedTextWriter, which
indents only the first line, so every line after an embedded break landed
at column 0. WriteLines splits at CRLF, LF and CR, writes each line at the
current indent ending with NewLineString, keeps blank lines free of
indentation, leaves the last line open when the text has no trailing break,
and leaves line breaks inside a verbatim string literal as written.

Fixes #179

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5MyZsxEdt96yVWhKn
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 589a81a into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/179-write-lines branch November 4, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WriteLine/Write indent only the first line of multi-line text: every line after an embedded newline lands at column 0

2 participants