Align a line or a paragraph
Paragraph alignment positions a whole block of text, so centering one line can also center the lines around it. Give a line its own paragraph when it needs independent alignment. Options.EnterKeyResponse controls whether Enter starts a new paragraph or adds a line break within the current one.
Why it happens: alignment is block-level in HTML
In HTML, text-align applies to a block-level container, <p>, <div>, <li>. It does not align an arbitrary "visual line". If three lines of text live inside a single <p> joined by <br>, setting text-align: center on that paragraph centers all three lines, because all three share the same block. To align only one of those lines, that line has to be its own block.
<!-- One paragraph, three lines: align centers every line -->
<p style="text-align:center">Sarah Lee<br>VP of Customer Success<br>+1 555 0100</p>
<!-- Three paragraphs: each can be aligned independently -->
<p style="text-align:center">Sarah Lee</p>
<p>VP of Customer Success</p>
<p>+1 555 0100</p>Same visible text. Different DOM. Different alignment behavior. The question becomes: when the user presses Enter at the end of a line, do you want the editor to produce a new block, or a soft line break? This is exactly the same MSHTML content model the WinForms edition sits on, so the answer is the same option under the same namespace.
The one option that controls it: EnterKeyResponse
Options.EnterKeyResponse takes one of two values from the EnterKeyResponses enum in SpiceLogic.HtmlEditor.Abstractions, the same namespace and the same enum the WinForms edition uses:
EnterKeyResponses.Paragraph - Enter starts a new paragraph; the editor emits </p><p>. Each line becomes its own block, so the alignment toolbar buttons affect only the paragraph containing the caret. This is what most users expect, and it is what a signature-block or template designer wants. It is not the shipped default, so set it explicitly.
EnterKeyResponses.LineBreak - the shipped default. Enter inserts a soft <br> inside the current paragraph. Everything typed stays inside one block, so the alignment buttons apply to the whole block at once. This is closer to a plain text-editor feel and useful for single-paragraph composer fields like reply boxes or short subject-line entries.
// Per-line alignment is what a signature-block designer needs:
NoteEditor.Options.EnterKeyResponse =
SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph;
// Force single-block behavior (Enter = <br>, alignment is paragraph-wide):
NoteEditor.Options.EnterKeyResponse =
SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak;' Per-line alignment is what a signature-block designer needs:
NoteEditor.Options.EnterKeyResponse =
SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph
' Force single-block behavior (Enter = <br>, alignment is paragraph-wide):
NoteEditor.Options.EnterKeyResponse =
SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreakFixing legacy templates: a single line trapped inside a paragraph
Some legacy templates have signature blocks already saved as one <p> with <br> separators. To align only the middle line, the user splits that paragraph so the middle line becomes its own block:
1. Place the caret at the start of the line that should be aligned and press Enter (with EnterKeyResponse = Paragraph).
2. Place the caret at the end of that line and press Enter again.
3. With the caret still on the now-isolated line, click the alignment toolbar button.
The middle line is now its own <p> and is the only one affected by the alignment command.
Letting the end user pick the mode
Expose a single checkbox in your host application's preferences, "Treat Enter as a line break (single paragraph mode)", and bind it to the option. The change applies to future Enter presses only; existing content is not rewritten:
<CheckBox x:Name="ChkUseLineBreaks"
Content="Treat Enter as a line break (single paragraph mode)"
Checked="ChkUseLineBreaks_CheckedChanged"
Unchecked="ChkUseLineBreaks_CheckedChanged" />private void ChkUseLineBreaks_CheckedChanged(object sender, RoutedEventArgs e)
{
NoteEditor.Options.EnterKeyResponse = ChkUseLineBreaks.IsChecked == true
? SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak
: SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph;
}Private Sub ChkUseLineBreaks_CheckedChanged(sender As Object, e As RoutedEventArgs)
If ChkUseLineBreaks.IsChecked = True Then
NoteEditor.Options.EnterKeyResponse = SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak
Else
NoteEditor.Options.EnterKeyResponse = SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph
End If
End SubThe result
A signature block built this way has each line in its own paragraph, with alignment applied per line, the way most users expect it to work, in both the WinForms and WPF editions.
Ask your AI to do this
Connect the SpiceLogic MCP server, then give your coding assistant this prompt.
I use the SpiceLogic WPF HTML Editor. Help me choose paragraph breaks or line breaks for a signature, and explain how that affects alignment. Confirm the exact API names, types and defaults with the SpiceLogic MCP documentation, then show the changes for my project.