Skip to content

Fix Eraser Tool: Remove Strokes Instead of Painting White Over Them #19

@TheZupZup

Description

@TheZupZup

Overview

Context: The InkCanvas widget (app/lib/widgets/ink_canvas.dart) has three tools: pen, highlighter, and eraser. The eraser is currently implemented as a white-colored pen stroke — it paints white on top of existing content. This breaks on any non-white background (lined, grid, or dotted templates), and it permanently embeds fake white strokes into the note's stroke data.

The correct behaviour is to remove (or trim) existing strokes that the eraser touches, not add new ones.

What needs to be done

MVP approach — stroke-level deletion

  • In _InkCanvasState, when the eraser tool is active, instead of adding a new InkStrokeData to _currentStrokes, check which existing strokes fall within the eraser's touch area (use bounding box or point proximity check)
  • Remove any stroke whose bounding box intersects the eraser path — use the bounding_box() method already on InkStroke in the Python model as a reference for the Flutter equivalent
  • Do NOT add any new stroke when erasing — just remove from the list and call setState()
  • The undo button (_undoLastStroke) should also undo an erase operation (i.e., restore the removed strokes)

Cleanup

  • Remove the BlendMode and transparency hack that currently makes the eraser look like a white stroke in _InkPainter
  • Remove InkTool.eraser from the stroke-drawing path in _InkPainter.paint() — eraser should never draw anything

Goal

Using the eraser removes ink strokes visually and from the data. Erasing on a lined template reveals the lines underneath (not a white smear). Undo correctly restores erased strokes.

Where to look

  • app/lib/widgets/ink_canvas.dart:
    • _InkCanvasState._onPointerMove() — where new stroke points are added
    • _InkCanvasState._undoLastStroke() — undo logic
    • _InkPainter.paint() — rendering (remove the eraser paint path)
    • InkStrokeData — the stroke model, has id and points

Testing steps

  • Draw a stroke in pen mode, switch to eraser, drag over the stroke — verify the stroke disappears
  • Switch to a lined template, draw a stroke, use the eraser — verify the lines show through (no white smear)
  • Erase a stroke then press Undo — verify the stroke reappears
  • Save the note, reopen it — verify erased strokes do not reappear

Related to: #8, #14

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions