From f598eaa47b07d401da3db3323a4ac0f5571f39fa Mon Sep 17 00:00:00 2001 From: Vinzent Date: Mon, 21 Aug 2023 20:16:59 +0200 Subject: [PATCH] feat: show modal on tab key release close #25 --- src/main.ts | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main.ts b/src/main.ts index dbd4dcc..835e877 100644 --- a/src/main.ts +++ b/src/main.ts @@ -188,16 +188,9 @@ export default class CycleThroughPanes extends Plugin { name: "Go to previous tab", callback: async () => { this.setLeaves(); - const leaves = this.leaves; - if (this.settings.showModal) { - this.modal = new GeneralModal(leaves, this); - this.leafIndex = await this.modal.open(); - } else { - this.leafIndex = this.leafIndex + 1; - if (this.leafIndex >= this.leaves.length) - this.leafIndex = 0; - } - const leaf = leaves[this.leafIndex]; + + this.leafIndex = (this.leafIndex + 1) % this.leaves.length; + const leaf = this.leaves[this.leafIndex]; if (leaf) { this.queueFocusLeaf(leaf); @@ -209,15 +202,10 @@ export default class CycleThroughPanes extends Plugin { name: "Go to next tab", callback: async () => { this.setLeaves(); - const leaves = this.leaves; - if (this.settings.showModal) { - this.modal = new GeneralModal(leaves, this); - this.leafIndex = await this.modal.open(); - } else { - this.leafIndex = this.leafIndex - 1; - if (this.leafIndex < 0) this.leafIndex = leaves.length - 1; - } - const leaf = leaves[this.leafIndex]; + this.leafIndex = + (this.leafIndex - 1 + this.leaves.length) % + this.leaves.length; + const leaf = this.leaves[this.leafIndex]; if (leaf) { this.queueFocusLeaf(leaf); @@ -290,6 +278,17 @@ export default class CycleThroughPanes extends Plugin { this.modal = undefined; } + + if ( + e.code == "Tab" && + this.ctrlPressedTimestamp && + this.settings.showModal && + !this.modal && + this.leaves + ) { + this.modal = new GeneralModal(this.leaves, this); + this.modal.open(); + } } onunload() {