fix: reset button now resets to original content like reset all function

Fixed reset button behavior to match reset all functionality:

## 🔄 Reset Button Enhancement
- **Before**: Only cleared staged changes, kept current modified content
- **After**: Resets section to original content like "Reset All" function does

## 🎯 Consistent Behavior
- **Reset Button**: Now calls `sectionManager.resetSection()` for complete reset
- **Reset All**: Already used `resetSection()` for each section
- **Result**: Both reset functions now have identical behavior

## 🚀 Implementation Details
- **Section Reset**: Calls `resetSection()` to restore original markdown content
- **DOM Update**: Immediately updates display with `updateSectionContent()`
- **Staging State**: Updates staging state to reflect original content values
- **Preview Update**: Resets image preview and alt text input to original values
- **Change Indicator**: Clears "unsaved changes" warning

## 📝 Reset Button Workflow (New)
1. **Reset Section**: Restore section to original content and state
2. **Update Display**: Show original content immediately in document
3. **Parse Original**: Extract original image source and alt text
4. **Update Staging**: Set staging state to reflect original values
5. **Clear Changes**: Remove any staged modifications
6. **Update UI**: Reset preview and form inputs to original values

##  User Experience
- **Consistent**: Reset button behavior now matches user expectations
- **Complete**: Resets everything back to original (not just current changes)
- **Immediate**: Users see original content restored right away
- **Reliable**: Works the same way as "Reset All" function

Added comprehensive test suite with 4 tests covering complete reset functionality.
Reset button now provides true "revert to original" behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-02 17:07:42 +01:00
parent 14ea058e7f
commit 4f41b22335
2 changed files with 248 additions and 1 deletions

View File

@@ -2098,7 +2098,28 @@ class DOMRenderer {
});
const resetBtn = this.createButton('↺ Reset', 'ui-edit-reset', (e) => {
// Reset both section and staging state
// Reset section to original content (like reset all does)
this.sectionManager.resetSection(sectionId);
// Get the reset section to update staging state with original content
const resetSection = this.sectionManager.sections.get(sectionId);
if (resetSection) {
// Update DOM immediately to show reset content
this.updateSectionContent(sectionId, resetSection.currentMarkdown);
// Parse original image info from reset content
const originalImageMatch = resetSection.currentMarkdown.match(/!\[(.*?)\]\((.*?)\)/);
if (originalImageMatch) {
const [, originalAltText, originalImageSrc] = originalImageMatch;
// Update staging state to reflect original content
stagingState.originalMarkdown = resetSection.currentMarkdown;
stagingState.currentAltText = originalAltText;
stagingState.currentImageSrc = originalImageSrc;
}
}
// Clear any staged changes
stagingState.stagedImageSrc = null;
stagingState.stagedAltText = null;
stagingState.hasChanges = false;