diff --git a/src/components/quickcommandUI/SelectList.vue b/src/components/quickcommandUI/SelectList.vue index b8ace27..b33d789 100644 --- a/src/components/quickcommandUI/SelectList.vue +++ b/src/components/quickcommandUI/SelectList.vue @@ -2,6 +2,7 @@ - + {{ item }} - + @@ -36,7 +36,7 @@ item.description }} - +
@@ -44,15 +44,15 @@
- {{ $q.platform.is.mac ? "⌘" : "Alt" }}+{{ count % 10 }} + {{ $q.platform.is.mac ? "⌘" : "Alt" }}+{{ count % countsPerPage }}
0) { - case false: + if (this.$q.platform.is.mac ? e.metaKey : e.altKey && !isNaN(e.key)) { + let index = e.key === "0" ? 10 : parseInt(e.key); + this.currentIndex = this.topIndex + index - 1; + return this.clickOK(); + } + switch (e.keyCode) { + case 38: // 上 this.currentIndex = Math.max(0, this.currentIndex - 1); break; - case true: + case 40: // 下 this.currentIndex = Math.min( this.matchedItemsSize - 1, this.currentIndex + 1 ); break; + case 13: // 回车 + return this.clickOK(); } this.$refs.scrollBar.scrollTo(this.currentIndex); - this.lastTimeStamp = e.timeStamp; }, - shortCutHandle(e) { + scrollHandler(e) { + this.topIndex = parseInt(e.target.scrollTop / this.itemHeight); + clearTimeout(this.timeoutId); + this.timeoutId = setTimeout(() => { + if (this.currentIndex < this.topIndex) + this.currentIndex = this.topIndex; + if (this.currentIndex > this.bottomIndex) + this.currentIndex = this.bottomIndex; + this.timeoutId = null; + }, 200); + }, + + mouseHandler(e) { e.preventDefault(); - if (!(this.$q.platform.is.mac ? e.metaKey : e.altKey) || isNaN(e.key)) - return; - let index = parseInt(e.key); - this.currentIndex = - Math.ceil(this.$refs.scrollBar.$el.scrollTop / 50) + - (index === 0 ? 10 : index) - - 1; - this.clickOK(); + this.$refs.scrollBar.$el.scrollBy( + 0, + (e.deltaY / this.itemHeight).toFixed() * this.itemHeight + ); }, setSubInput() { @@ -179,18 +193,16 @@ export default { clear() { utools.removeSubInput(); - document.removeEventListener("keydown", this.changeItemIndex); - document.removeEventListener("keydown", this.shortCutHandle); - document.removeEventListener("mousewheel", this.changeItemIndex, { + document.removeEventListener("keydown", this.keyHandler); + document.removeEventListener("wheel", this.mouseHandler, { passive: false, }); this.setUtoolsHeight(this.listMaxHeight); }, addListeners() { - document.addEventListener("keydown", this.changeItemIndex); - document.addEventListener("keydown", this.shortCutHandle); - document.addEventListener("mousewheel", this.changeItemIndex, { + document.addEventListener("keydown", this.keyHandler); + document.addEventListener("wheel", this.mouseHandler, { passive: false, }); }, @@ -202,4 +214,8 @@ export default { .q-card--dark { background: var(--q-dark-page); } +.q-item, +.shortcut { + user-select: none; +}