« get me outta code hell

Fix queue notes in a better way - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-11-11 22:13:15 -0400
committerFlorrie <towerofnix@gmail.com>2019-11-11 22:13:15 -0400
commit0d8d353ac4a232c72bef33a86fc3237383416134 (patch)
tree6fb78077267da9ef67c59b78b5c8ee63646b28df
parent7db503ec993285b6e3396b03a2a23d39f3f8c545 (diff)
Fix queue notes in a better way
Before, we were showing the notes window whenever a track with notes
played - even if the queue wasn't focused. This fixes that.
-rw-r--r--ui.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/ui.js b/ui.js
index 4f9b2e6..1789c35 100644
--- a/ui.js
+++ b/ui.js
@@ -703,10 +703,10 @@ class AppElement extends FocusElement {
 
     grouplikeListing.pathElement.on('select', item => this.reveal(item))
     grouplikeListing.on('menu', (item, el) => this.showMenuForItemElement(el, grouplikeListing))
-    grouplikeListing.on('selected', item => this.editNotesFile(item, grouplikeListing, false))
+    grouplikeListing.on('selected', item => this.editNotesFile(item, false))
     grouplikeListing.on('edit-notes', item => {
       this.reveal(item)
-      this.editNotesFile(item, grouplikeListing, true)
+      this.editNotesFile(item, true)
     })
   }
 
@@ -861,7 +861,7 @@ class AppElement extends FocusElement {
     items.splice(items.indexOf(item), 0, file)
   }
 
-  async editNotesFile(item, listing, focus) {
+  async editNotesFile(item, focus) {
     if (!item) {
       return
     }
@@ -874,7 +874,14 @@ class AppElement extends FocusElement {
       await this.createNotesFile(item)
     }
 
-    const doubleCheckItem = () => item === listing.currentItem
+    const doubleCheckItem = () => {
+      const listing = this.root.selectedElement.directAncestors.find(el => el instanceof GrouplikeListingElement)
+      return listing && listing.currentItem === item
+    }
+
+    if (!doubleCheckItem()) {
+      return
+    }
 
     const status = await this.textEditor.openItem(item, {doubleCheckItem})
 
@@ -1028,8 +1035,8 @@ class AppElement extends FocusElement {
         canProcessMetadata && isTrack(item) && {label: 'Process metadata', action: () => this.processMetadata(item, true)},
         isOpenable(item) && item.url.endsWith('.json') && {label: 'Open (JSON Playlist)', action: () => this.openSpecialOrThroughSystem(item)},
         isOpenable(item) && {label: 'Open (System)', action: () => this.openThroughSystem(item)},
-        !hasNotesFile && isPlayable(item) && {label: 'Create notes file', action: () => this.editNotesFile(item, listing, true)},
-        hasNotesFile && isPlayable(item) && {label: 'Edit notes file', action: () => this.editNotesFile(item, listing, true)},
+        !hasNotesFile && isPlayable(item) && {label: 'Create notes file', action: () => this.editNotesFile(item, true)},
+        hasNotesFile && isPlayable(item) && {label: 'Edit notes file', action: () => this.editNotesFile(item, true)},
         canControlQueue && isPlayable(item) && {label: 'Remove from queue', action: () => this.unqueue(item)},
         {divider: true},