From 231ccb1e4356790fe49ce760384c899e9be473c6 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sun, 8 Oct 2023 13:57:46 +0200 Subject: [PATCH] Cleanup and simplify messageList `UpOrDown` handling --- dev/Common/Selector.js | 33 ++++-------- dev/View/User/MailBox/MessageList.js | 78 ++++++++++------------------ 2 files changed, 36 insertions(+), 75 deletions(-) diff --git a/dev/Common/Selector.js b/dev/Common/Selector.js index 340feca15..d22ab6a15 100644 --- a/dev/Common/Selector.js +++ b/dev/Common/Selector.js @@ -118,7 +118,8 @@ export class Selector { if (isArray(aItems)) { let temp, - isChecked; + isChecked, + next = this.iFocusedNextHelper || this.iSelectNextHelper; aItems.forEach(item => { const uid = this.getItemUid(item); @@ -143,24 +144,10 @@ export class Selector { selectedItemUseCallback = true; - if ( - (this.iSelectNextHelper || this.iFocusedNextHelper) && - aItems.length && - !koFocusedItem() - ) { - temp = null; - if (this.iFocusedNextHelper) { - temp = aItems[-1 === this.iFocusedNextHelper ? aItems.length - 1 : 0]; - } - - if (!temp && this.iSelectNextHelper) { - temp = aItems[-1 === this.iSelectNextHelper ? aItems.length - 1 : 0]; - } - + if (next && aItems.length && !koFocusedItem()) { + temp = aItems[-1 === next ? aItems.length - 1 : 0]; if (temp) { - if (this.iSelectNextHelper) { - koSelectedItem(temp); - } + this.iSelectNextHelper && koSelectedItem(temp); koFocusedItem(temp); @@ -267,10 +254,11 @@ export class Selector { * @param {boolean=} bForceSelect = false */ newSelectPosition(sEventKey, bShiftKey, bForceSelect) { - let isArrow = 'ArrowUp' === sEventKey || 'ArrowDown' === sEventKey, - result; + let result; - const pageStep = 10, + const up = 'ArrowUp' === sEventKey, + isArrow = up || 'ArrowDown' === sEventKey, + pageStep = 10, list = this.list(), listLen = list.length, focused = this.focusedItem(); @@ -282,8 +270,7 @@ export class Selector { } else if (listLen) { if (focused) { if (isArrow) { - let i = list.indexOf(focused), - up = 'ArrowUp' == sEventKey; + let i = list.indexOf(focused); if (bShiftKey) { shiftStart = -1 < shiftStart ? shiftStart : i; shiftStart == i diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index 2784b0090..113ca23c4 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -120,8 +120,7 @@ export class MailMessageList extends AbstractViewRight { return value ? i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', { SEARCH: value }) : '' }, - messageListPaginator: computedPaginatorHelper(MessagelistUserStore.page, - MessagelistUserStore.pageCount), + messageListPaginator: computedPaginatorHelper(MessagelistUserStore.page, MessagelistUserStore.pageCount), checkAll: { read: () => MessagelistUserStore.hasChecked(), @@ -257,47 +256,22 @@ export class MailMessageList extends AbstractViewRight { }); this.selector.on('UpOrDown', up => { - if (MessagelistUserStore.hasChecked()) { - return false; + if (!MessagelistUserStore.hasChecked()) { + clearTimeout(iGoToUpOrDownTimeout); + iGoToUpOrDownTimeout = setTimeout(() => { + let page = MessagelistUserStore.page(); + up ? --page : ++page; + if (page > 0 && page <= MessagelistUserStore.pageCount()) { + if (SettingsUserStore.usePreviewPane() || MessageUserStore.message()) { + this.selector.iSelectNextHelper = up ? -1 : 1; + } else { + this.selector.iFocusedNextHelper = up ? -1 : 1; + } + this.selector.unselect(); + this.gotoPage(page); + } + }, 350); } - - clearTimeout(iGoToUpOrDownTimeout); - iGoToUpOrDownTimeout = setTimeout(() => { - let prev, next, temp, current; - - this.messageListPaginator().find(item => { - if (item) { - if (current) { - next = item; - } - - if (item.current) { - current = item; - prev = temp; - } - - if (next) { - return true; - } - - temp = item; - } - - return false; - }); - - if (up ? prev : next) { - if (SettingsUserStore.usePreviewPane() || MessageUserStore.message()) { - this.selector.iSelectNextHelper = up ? -1 : 1; - } else { - this.selector.iFocusedNextHelper = up ? -1 : 1; - } - this.selector.unselect(); - this.gotoPage(up ? prev : next); - } - }, 350); - - return true; }); addEventListener('mailbox.message-list.selector.go-down', @@ -547,7 +521,7 @@ export class MailMessageList extends AbstractViewRight { page && hasher.setHash( mailBox( FolderUserStore.currentFolderFullNameHash(), - page.value, + page, MessagelistUserStore.listSearch(), MessagelistUserStore.threadUid() ) @@ -601,16 +575,16 @@ export class MailMessageList extends AbstractViewRight { toggleLeftPanel(); } else { ThemeStore.isMobile() && leftPanelDisabled(true); + + if (eqs(event, '.messageList') && ScopeMessageView === AppUserStore.focusedState()) { + AppUserStore.focusedState(ScopeMessageList); + } + + let el = eqs(event, '.e-paginator a'); + el && this.gotoPage(ko.dataFor(el)?.value); + + eqs(event, '.checkboxCheckAll') && this.checkAll(!this.checkAll()); } - - if (eqs(event, '.messageList') && ScopeMessageView === AppUserStore.focusedState()) { - AppUserStore.focusedState(ScopeMessageList); - } - - let el = eqs(event, '.e-paginator a'); - el && this.gotoPage(ko.dataFor(el)); - - eqs(event, '.checkboxCheckAll') && this.checkAll(!this.checkAll()); }, dblclick: event => { let el = eqs(event, '.messageListItem');