Skip to content

Commit

Permalink
- hitting escape twice now exits the tag input field
Browse files Browse the repository at this point in the history
- hitting left and right while in the new tag input field no longer changes image focus
- refocusses the new tag input field when a tag has been submitted
  • Loading branch information
TomNCatz committed Sep 12, 2023
1 parent eb4460a commit 35ea774
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/DisplayObjects/GalleryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export class GalleryInfo
});
}
}
const newTagEl = currentVal.createEl("input");
const newTagEl = currentVal.createEl("input", {cls: "new-tag-input"});
newTagEl.name = "new-tag";
newTagEl.placeholder = "New Tag";
new SuggestionDropdown(newTagEl, () =>{
const files = this.plugin.app.vault.getMarkdownFiles();
Expand All @@ -171,7 +172,7 @@ export class GalleryInfo
{
return;
}
await this.plugin.app.fileManager.processFrontMatter(this.imgInfo, frontmatter => {
await this.plugin.app.fileManager.processFrontMatter(this.imgInfo, (frontmatter) => {
let tags = frontmatter.tags ?? []
if (!Array.isArray(tags))
{
Expand All @@ -187,6 +188,8 @@ export class GalleryInfo
frontmatter.tags = tags;
this.tagList.push(tag)
this.updateDisplay();

(document.querySelector("input[name='new-tag']") as HTMLInputElement).focus();
});
});
}
Expand Down
31 changes: 30 additions & 1 deletion src/DisplayObjects/SuggestionDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class SuggestionDropdown
});

this.target.addEventListener("keydown", (ev) => {this.#onKeyDown(ev)});
this.target.addEventListener("keyup", (ev) => {this.#onKeyUp(ev)});

this.target.addEventListener("blur", () => {this.#cleanUp()});
this.target.addEventListener("change", () => {this.#cleanUp()});
Expand All @@ -57,6 +58,10 @@ export class SuggestionDropdown
this.#submit();
break;
case "Escape":
if(!this.#showing)
{
this.target.blur();
}
this.cancel();
break;
case "ArrowRight":
Expand Down Expand Up @@ -98,8 +103,32 @@ export class SuggestionDropdown
}
}
break;
default: // new Notice(e.key)
default:
// new Notice(e.key)
return;
}

event.stopPropagation();
}

#onKeyUp(event:KeyboardEvent)
{
switch(event.key)
{
case "Enter":
case "Escape":
case "ArrowRight":
case "ArrowLeft":
case "ArrowUp":
case "ArrowDown":
case "Backspace":
break;
default:
// new Notice(e.key)
return;
}

event.stopPropagation();
}

#submit()
Expand Down

0 comments on commit 35ea774

Please sign in to comment.