Selaa lähdekoodia

Add fix for cursor.next() when an instrument or voice is hidden (#460)

* Add failing test for cursor.next()
Jerko Steiner 6 vuotta sitten
vanhempi
commit
2d467dbbac
2 muutettua tiedostoa jossa 26 lisäystä ja 2 poistoa
  1. 3 2
      src/OpenSheetMusicDisplay/Cursor.ts
  2. 23 0
      test/Common/OSMD/OSMD_Test.ts

+ 3 - 2
src/OpenSheetMusicDisplay/Cursor.ts

@@ -58,13 +58,14 @@ export class Cursor {
     }
     this.graphic.Cursors.length = 0;
     const iterator: MusicPartManagerIterator = this.iterator;
-    if (iterator.EndReached || iterator.CurrentVoiceEntries === undefined || iterator.CurrentVoiceEntries.length === 0) {
+    const voiceEntries: VoiceEntry[] = iterator.CurrentVisibleVoiceEntries();
+    if (iterator.EndReached || iterator.CurrentVoiceEntries === undefined || voiceEntries.length === 0) {
       return;
     }
     let x: number = 0, y: number = 0, height: number = 0;
 
     // get all staff entries inside the current voice entry
-    const gseArr: VexFlowStaffEntry[] = iterator.CurrentVoiceEntries.map(ve => this.getStaffEntriesFromVoiceEntry(ve));
+    const gseArr: VexFlowStaffEntry[] = voiceEntries.map(ve => this.getStaffEntriesFromVoiceEntry(ve));
     // sort them by x position and take the leftmost entry
     const gse: VexFlowStaffEntry =
           gseArr.sort((a, b) => a.PositionAndShape.AbsolutePosition.x <= b.PositionAndShape.AbsolutePosition.x ? -1 : 1 )[0];

+ 23 - 0
test/Common/OSMD/OSMD_Test.ts

@@ -192,4 +192,27 @@ describe("OpenSheetMusicDisplay Main Export", () => {
             done
         ).catch(done);
     });
+
+    describe("cursor with hidden instrument", () => {
+        let osmd: OpenSheetMusicDisplay;
+        beforeEach(() => {
+            const div: HTMLElement = TestUtils.getDivElement(document);
+            osmd = TestUtils.createOpenSheetMusicDisplay(div);
+            const score: Document =
+                TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
+            return osmd.load(score)
+            .then(() => {
+                osmd.render();
+            });
+        });
+
+        it("should move cursor after instrument is hidden", () => {
+            osmd.Sheet.Instruments[1].Visible = false;
+            osmd.render();
+            osmd.cursor.show();
+            for (let i: number = 0; i < 100; i++) {
+                osmd.cursor.next();
+            }
+        });
+    });
 });