@@ -743,7 +743,8 @@ <h1 class="reveal" style="font-size:clamp(2rem,6vw,4.5rem)">Thank you!</h1>
743743 this . statusEl = document . getElementById ( 'noteStatus' ) ;
744744 this . isOpen = false ;
745745 this . storagePrefix = 'slide-notes-' ;
746- this . loadAllFromStorage ( ) ;
746+ this . originPrefix = 'slide-notes-origin-' ;
747+ this . syncStorageWithDOM ( ) ;
747748 this . setupKeyboard ( ) ;
748749 this . setupAutoSave ( ) ;
749750 this . setupSlideTracking ( ) ;
@@ -768,6 +769,7 @@ <h1 class="reveal" style="font-size:clamp(2rem,6vw,4.5rem)">Thank you!</h1>
768769 this . textarea . addEventListener ( 'input' , ( ) => {
769770 const idx = this . sp . currentSlide ;
770771 localStorage . setItem ( this . storagePrefix + idx , this . textarea . value ) ;
772+ // Mark as user-edited (origin stays the same — only changes on file reload)
771773 this . statusEl . textContent = 'Saved' ;
772774 clearTimeout ( this . _statusTimeout ) ;
773775 this . _statusTimeout = setTimeout ( ( ) => { this . statusEl . textContent = '' ; } , 1500 ) ;
@@ -784,6 +786,7 @@ <h1 class="reveal" style="font-size:clamp(2rem,6vw,4.5rem)">Thank you!</h1>
784786 }
785787 loadNoteForSlide ( idx ) {
786788 this . slideNumEl . textContent = idx + 1 ;
789+ // localStorage has already been synced with DOM in syncStorageWithDOM
787790 const stored = localStorage . getItem ( this . storagePrefix + idx ) ;
788791 if ( stored !== null ) {
789792 this . textarea . value = stored ;
@@ -793,14 +796,29 @@ <h1 class="reveal" style="font-size:clamp(2rem,6vw,4.5rem)">Thank you!</h1>
793796 this . textarea . value = notesEl ? notesEl . textContent . trim ( ) : '' ;
794797 }
795798 }
796- loadAllFromStorage ( ) {
799+ // Compare stored "origin" (DOM content at last load) with current DOM.
800+ // If DOM changed (file was updated externally), reset localStorage for that slide.
801+ // If DOM is the same, keep the user's localStorage edits.
802+ syncStorageWithDOM ( ) {
797803 this . sp . slides . forEach ( ( slide , idx ) => {
798- if ( localStorage . getItem ( this . storagePrefix + idx ) === null ) {
799- const notesEl = slide . querySelector ( '.speaker-notes' ) ;
800- if ( notesEl && notesEl . textContent . trim ( ) ) {
801- localStorage . setItem ( this . storagePrefix + idx , notesEl . textContent . trim ( ) ) ;
804+ const notesEl = slide . querySelector ( '.speaker-notes' ) ;
805+ const currentDOM = notesEl ? notesEl . textContent . trim ( ) : '' ;
806+ const storedOrigin = localStorage . getItem ( this . originPrefix + idx ) ;
807+ const storedEdit = localStorage . getItem ( this . storagePrefix + idx ) ;
808+
809+ if ( storedOrigin === null ) {
810+ // First time: seed both origin and edit from DOM
811+ if ( currentDOM ) {
812+ localStorage . setItem ( this . originPrefix + idx , currentDOM ) ;
813+ localStorage . setItem ( this . storagePrefix + idx , currentDOM ) ;
802814 }
815+ } else if ( storedOrigin !== currentDOM ) {
816+ // DOM changed externally (file was edited/saved/git pulled)
817+ // Reset: new DOM content wins
818+ localStorage . setItem ( this . originPrefix + idx , currentDOM ) ;
819+ localStorage . setItem ( this . storagePrefix + idx , currentDOM ) ;
803820 }
821+ // else: DOM unchanged, keep user's localStorage edits
804822 } ) ;
805823 }
806824 toggle ( ) {
@@ -823,6 +841,8 @@ <h1 class="reveal" style="font-size:clamp(2rem,6vw,4.5rem)">Thank you!</h1>
823841 slide . appendChild ( notesEl ) ;
824842 }
825843 notesEl . textContent = stored ;
844+ // Update origin so next load knows this was saved
845+ localStorage . setItem ( this . originPrefix + idx , stored ) ;
826846 }
827847 } ) ;
828848 }
0 commit comments