« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js28
1 files changed, 23 insertions, 5 deletions
diff --git a/ui.js b/ui.js
index 66a7745..3753ff0 100644
--- a/ui.js
+++ b/ui.js
@@ -110,6 +110,7 @@ const keyBindings = [
   ['isActOnPlayer', [0x1b, 'a']],
   ['isActOnPlayer', [0x1b, '!']],
 
+  ['isFocusTextEditor', [0x05]], // ^E
   ['isSaveTextEditor', [0x13]], // ^S
   ['isDeselectTextEditor', [0x18]], // ^X
   ['isDeselectTextEditor', telc.isEscape],
@@ -703,6 +704,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, false))
+    grouplikeListing.on('edit-notes', item => {
+      this.reveal(item)
+      this.editNotesFile(item, true)
+    })
   }
 
   showContextMenu(opts) {
@@ -832,6 +837,10 @@ class AppElement extends FocusElement {
       return
     }
 
+    if (getCorrespondingFileForItem(item, '.txt')) {
+      return
+    }
+
     let itemPath
     try {
       itemPath = url.fileURLToPath(item.url)
@@ -850,7 +859,6 @@ class AppElement extends FocusElement {
 
     const { items } = item[parentSymbol]
     items.splice(items.indexOf(item), 0, file)
-    await this.editNotesFile(item, true)
   }
 
   async editNotesFile(item, focus) {
@@ -858,6 +866,14 @@ class AppElement extends FocusElement {
       return
     }
 
+    // Creates it, if it doesn't exist.
+    // We only do this when we're manually selecting the file (and expect to
+    // focus it). Otherwise we'd create a notes file for every track hovered
+    // over!
+    if (focus) {
+      await this.createNotesFile(item)
+    }
+
     const doubleCheckItem = () => item === this.tabber.currentElement.currentItem
 
     const status = await this.textEditor.openItem(item, {doubleCheckItem})
@@ -1012,7 +1028,7 @@ 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.createNotesFile(item)},
+        !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},
@@ -1155,6 +1171,7 @@ class AppElement extends FocusElement {
         this.textInfoPane.h = 8
       } else {
         this.textEditor.w = this.textInfoPane.contentW
+        this.textEditor.rebuildUiLines()
         this.textInfoPane.h = Math.min(8, this.textEditor.getOptimalHeight() + 2)
       }
 
@@ -1295,8 +1312,6 @@ class AppElement extends FocusElement {
         }
         this.menubar.select()
       }
-    } else if (keyBuf.equals(Buffer.from([5]))) { // Ctrl-E
-      this.editMode = !this.editMode
     } else if (this.editMode && keyBuf.equals(Buffer.from([14]))) { // ctrl-N
       this.newEmptyTab()
     } else if (keyBuf.equals(Buffer.from([15]))) { // ctrl-O
@@ -1760,10 +1775,11 @@ class GrouplikeListingElement extends Form {
     for (const evtName of [
       'browse',
       'download',
-      'paste',
+      'edit-notes',
       'mark',
       'menu',
       'open',
+      'paste',
       'queue',
       'remove',
       'unqueue'
@@ -2688,6 +2704,8 @@ class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement {
       this.emit('remove')
     } else if (input.isMenu(keyBuf)) {
       this.emit('menu', this)
+    } else if (input.isFocusTextEditor(keyBuf)) {
+      this.emit('edit-notes')
     } else if (input.isFocusLabels(keyBuf)) {
       this.labelsSelected = true
       this.expandLabels = true