Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·6 min read

Hiding the # in TaskPad headings, except where you edit them

A line that reads ## Shopping should look like a heading, not like Markdown. The two hash marks in front of it are noise once the text is big and bold. So I wanted them gone. The trouble with making something disappear from a text editor is that the text is still there, and sooner or later you need to change it. Change ## to ### and you are editing characters you cannot see.

This is the story of the small commit that settled that, and of the places in the code that all have to agree for it to work.

Project
TaskPad
Date
Oct 2026
Stack
C#, WPF, AvalonEdit
Commit
3ed66fd

What broke

TaskPad keeps your list as a plain .txt file and draws a visual layer over it. Checkboxes and badges are drawn over the real [ ] and ! characters, and the file on disk never changes. Headings follow the same rule: # Title through ###### Title are real characters in the file.

Before this commit the marks were visible. The colorizer painted them in a faint grey and scaled the line up, which is what the code in TaskColorizer does: Paint(o + info.Indent, o + info.Indent + info.Heading, Theme.FgFaint). It worked, but a faint ## in front of a large bold line still looks like leftover syntax. I wanted the marks gone.

The catch is what the code comment in the commit says in one sentence: heading markers stay visible on the caret line "so the level can be edited". A hidden marker cannot be edited. If I hid them on every line, the only way to change a heading from level 2 to level 3 would be to delete the whole line and retype it blind.

What the code showed

The editor already had a way to draw something in place of real characters. MarkerGenerator is an AvalonEdit VisualLineElementGenerator. The parser, LineParser, returns a list of tokens for each line, and the generator replaces each token with a drawn element. A checkbox token becomes a checkbox. A hidden bullet becomes an empty canvas of width zero.

Headings did not have a token at all. The parser noticed the # characters, recorded the level and moved on:

csharp
info.Heading = h;
info.ContentStart = Skip(t, i + h);
return info;

So the first change was to give the marks a token of their own, covering the hashes and the spaces after them:

csharp
info.Tokens.Add(new Tok(TokKind.HeadingMark, i, Skip(t, i + h) - i)); // "## " (hidden)

In the generator, a heading mark is drawn exactly like a hidden bullet, as an empty canvas. The real work is deciding when not to draw it. The generator gets a function that returns the caret's line number, and a tiny predicate uses it:

csharp
public MarkerGenerator(Func<int> caretLine = null) { _caretLine = caretLine; }

bool Skip(Tok t, DocumentLine line) =>
    t.Kind == TokKind.HeadingMark && _caretLine != null && _caretLine() == line.LineNumber;

That predicate has to be consulted in more than one place. GetFirstInterestedOffset tells AvalonEdit where the generator wants to take over, and if it still reports the heading mark on the caret line, the engine asks for an element there and the generator has to refuse. The construct method has its own check. Miss either, and the generator would still take over the marks on the line you are editing. I wrote Skip once and used it in both.

The fix

The generator only draws when asked, and AvalonEdit does not know the caret moved. Moving the caret from line 4 to line 5 changes nothing in the document, so nothing is redrawn, and the hash marks would stay in whatever state they were last drawn in.

So TabView listens to the caret and redraws exactly two lines, the one it left and the one it entered:

csharp
ta.Caret.PositionChanged += (s, e) =>
{
    int now = ta.Caret.Line;
    if (now == lastCaretLine) return;
    var doc = ed.Document;
    if (lastCaretLine <= doc.LineCount) ta.TextView.Redraw(doc.GetLineByNumber(lastCaretLine));
    ta.TextView.Redraw(doc.GetLineByNumber(now));
    lastCaretLine = now;
};

Three details in that block earn their place. The early return keeps typing within a line from triggering redraws on every keystroke. The lastCaretLine <= doc.LineCount check covers the case where you deleted lines and the old line number no longer exists. And only two lines are redrawn, not the whole view, so a long document costs the same as a short one.

The commit is 3ed66fd (Oct 2026), and it also bumped the version, so it shipped as v1.3.1. The diff touches four files: 26 lines added and 5 removed.

  1. 01

    Caret moves

    AvalonEdit raises PositionChanged

  2. 02

    Two lines redrawn

    the one you left and the one you entered

  3. 03

    Generator asked again

    Skip returns true on the caret line only

  4. 04

    Marks appear

    plain ## text, editable like any characters

  5. 05

    Caret leaves

    the line is redrawn and the marks vanish

Figure 1. What happens when you click into a heading.

One consequence follows from the design, and I only know it from reading the code, not from measuring. In that commit the hidden mark is an empty canvas of width zero, so when the caret enters a heading line, the marks come back and the text shifts to the right by their width. That is the price of showing the real characters instead of a separate level control.

What I would do differently

The repository has no tests, and this is exactly the kind of logic that deserves one. LineParser.Parse is a pure function from a string to tokens. A test that "## Title" yields a HeadingMark of length 3 and that "##Title" yields none would have taken minutes to write, and the second case is the one that guards against hiding characters that are not really a heading marker.

I would also pass the caret line as a value that the view updates, instead of a closure that reaches back into the editor. The Func<int> works, but it makes the generator depend on something it cannot see. It is the kind of coupling that is fine in a 1 MB app and annoying in a bigger one.

Where this fits

This was one of several fixes in the same evening of TaskPad's life, right between the installer and the session restore work. The rule behind it, that the visual layer may hide things but the file must stay honest, is the idea the whole editor is built on. The full TaskPad case study covers that layer model, the comments, deadlines and the single-exe packaging.

Open a list with a few headings and click through them to see the marks appear and disappear, or read the full project story for the rest of the editor.

Download TaskPad

#wpf#csharp#avalonedit#editor

Keep reading

Have a project in mind?