Sfoglia il codice sorgente

fix(Cursor): Fix cursor resetting to first note after re-render (#25)

fix #25

patch by @conde2
sschmidTU 3 anni fa
parent
commit
9cb08d1926

+ 7 - 1
src/OpenSheetMusicDisplay/Cursor.ts

@@ -185,7 +185,13 @@ export class Cursor implements IPlaybackListener {
     this.updateCurrentPage(); // attach cursor to new page DOM if necessary
 
     // this.graphic?.Cursors?.length = 0;
-    const iterator: MusicPartManagerIterator = this.iterator;
+    let iterator: MusicPartManagerIterator;
+    if (this.openSheetMusicDisplay.PlaybackManager) {
+      iterator = this.openSheetMusicDisplay.PlaybackManager.CursorIterator;
+    } else {
+      iterator = this.iterator;
+    }
+
     // TODO when measure draw range (drawUpToMeasureNumber) was changed, next/update can fail to move cursor. but of course it can be reset before.
 
     const voiceEntries: VoiceEntry[] = iterator.CurrentVisibleVoiceEntries();

+ 8 - 3
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -866,7 +866,7 @@ export class OpenSheetMusicDisplay {
         if (enable) {
             for (let i: number = 0; i < this.cursorsOptions.length; i++){
                 // save previous cursor state
-                const hidden: boolean = this.cursors[i]?.Hidden;
+                const hidden: boolean = this.cursors[i]?.Hidden ?? false;
                 const previousIterator: MusicPartManagerIterator = this.cursors[i]?.Iterator;
                 this.cursors[i]?.hide();
 
@@ -886,10 +886,15 @@ export class OpenSheetMusicDisplay {
 
                 // restore old cursor state
                 if (this.rules.RestoreCursorAfterRerender) {
-                    this.cursors[i].hidden = hidden;
                     if (previousIterator) {
                         this.cursors[i].iterator = previousIterator;
-                        this.cursors[i].update();
+                        // this.cursors[i].update();
+                    }
+
+                    if (hidden) {
+                        this.cursors[i].hide();
+                    } else {
+                        this.cursors[i].show();
                     }
                 }
             }