First commit on the local Gitea server, made after moving the tree off the Windows machine. Build outputs, node_modules and the AI models stay out (see .gitignore); everything the installer build needs is tracked. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
3.7 KiB
Highlighter Tool Fix Summary
Problem Description
The highlighter tool was deleting all existing annotations on the current tab as soon as it started drawing. This was happening because the highlighter drawing logic was only redrawing highlight strokes from history, effectively "clearing" all other annotation types (pen, eraser) from the visible canvas.
Root Cause
In the performDraw function in app.js (lines 1900-1947), when currentTool === 'highlight', the code was:
- Clearing the visible canvas
- Only redrawing highlight strokes from
strokeHistory - Not preserving pen or eraser strokes
This meant that when you started using the highlighter, it would clear the canvas and only show highlight strokes, making it appear as if all other annotations were deleted.
Solution Implemented
1. Fixed performDraw Function
File: app.js (lines 1900-1947)
Before:
// Draw all saved strokes from history for live preview
const passageKey = getCurrentStrokePassageKey();
if (strokeHistory[passageKey]) {
for (const stroke of strokeHistory[passageKey]) {
if (stroke.type === 'highlight' && stroke.points && stroke.points.length > 1) {
// Only drawing highlight strokes
}
}
}
After:
// Draw all saved strokes from history for live preview (ALL strokes, not just highlights)
const passageKey = getCurrentStrokePassageKey();
if (strokeHistory[passageKey]) {
for (const stroke of strokeHistory[passageKey]) {
if (stroke.points && stroke.points.length > 1) {
visibleCtx.save();
visibleCtx.globalAlpha = stroke.type === 'highlight' ? 0.3 : 1.0;
visibleCtx.globalCompositeOperation = stroke.type === 'erase' ? 'destination-out' : 'source-over';
visibleCtx.strokeStyle = stroke.type === 'highlight' ? 'rgba(255,255,0,0.30)' : stroke.color;
// ... rest of drawing logic
}
}
}
2. Fixed redrawAllStrokes Function
File: app.js (lines 2707-2745)
Before:
ctx.globalCompositeOperation = 'source-over';
After:
ctx.globalCompositeOperation = stroke.type === 'erase' ? 'destination-out' : 'source-over';
Key Changes Made
- Removed stroke type filtering: The highlighter now redraws ALL strokes from history, not just highlight strokes
- Added proper composite operations: Eraser strokes now use
destination-outwhile pen and highlight strokes usesource-over - Preserved stroke properties: Each stroke type maintains its correct alpha, color, and composite operation settings
Testing
A test file test-highlighter-fix.html was created to verify the fix works correctly. The test demonstrates:
- Pen annotations remain visible when switching to highlighter tool
- Highlighter annotations work correctly without affecting other tools
- Eraser marks are preserved when switching between tools
- All tools can be used interchangeably without losing annotations
Result
The highlighter tool now works exactly like the pen and eraser tools:
- ✅ Can draw unlimited annotations without interfering with other functions
- ✅ Preserves all existing annotations when starting to draw
- ✅ Maintains proper visual appearance for each stroke type
- ✅ Works seamlessly with the undo/redo system
- ✅ Persists annotations correctly across tab switches
Files Modified
app.js- Main application file with the fixtest-highlighter-fix.html- Test file to verify the fixHIGHLIGHTER_FIX_SUMMARY.md- This documentation
Impact
This fix ensures that the highlighter tool behaves consistently with other annotation tools and provides a smooth, non-destructive annotation experience for users.