From 0c87bbac210970b0cb38dd0f53f49ab91142f527 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Fri, 9 Sep 2022 17:04:52 +0200 Subject: [PATCH] Faster Selector.autoSelect --- dev/Common/Selector.js | 20 +++++++++----------- dev/Stores/User/Messagelist.js | 12 ++++++++---- dev/View/User/MailBox/MessageList.js | 10 ++-------- dev/View/User/MailBox/MessageView.js | 16 +++++++--------- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/dev/Common/Selector.js b/dev/Common/Selector.js index 3402a0da6..13e445c47 100644 --- a/dev/Common/Selector.js +++ b/dev/Common/Selector.js @@ -55,17 +55,15 @@ export class Selector { this.listChecked.subscribe(items => { if (items.length) { - if (null === koSelectedItem()) { - if (koSelectedItem.valueHasMutated) { - koSelectedItem.valueHasMutated(); - } - } else { + if (koSelectedItem()) { koSelectedItem(null); + } else { + koSelectedItem.valueHasMutated?.(); } - } else if (this.autoSelect() && koFocusedItem()) { + } else if (this.autoSelect()) { koSelectedItem(koFocusedItem()); } - }, this); + }); let selectedItemUseCallback = true; @@ -78,9 +76,9 @@ export class Selector { } else if (selectedItemUseCallback) { this.itemSelected(); } - }, this); + }); - koFocusedItem.subscribe(item => item && (this.sLastUid = this.getItemUid(item)), this); + koFocusedItem.subscribe(item => item && (this.sLastUid = this.getItemUid(item))); /** * Below code is used to keep checked/focused/selected states when array is refreshed. @@ -176,7 +174,7 @@ export class Selector { this.iFocusedNextHelper = 0; } - if (!isChecked && !koSelectedItem() && koFocusedItem() && this.autoSelect()) { + if (this.autoSelect() && !isChecked && !koSelectedItem()) { koSelectedItem(koFocusedItem()); } } @@ -262,7 +260,7 @@ export class Selector { * @returns {boolean} */ autoSelect() { - return !!(this.oCallbacks.AutoSelect || (()=>1))(); + return !!(this.oCallbacks.AutoSelect || (()=>1))() && this.focusedItem(); } /** diff --git a/dev/Stores/User/Messagelist.js b/dev/Stores/User/Messagelist.js index d0fba3ab2..20853065d 100644 --- a/dev/Stores/User/Messagelist.js +++ b/dev/Stores/User/Messagelist.js @@ -35,7 +35,8 @@ const rl.route.off(); hasher.replaceHash(hash); rl.route.on(); - } + }, + disableAutoSelect = ko.observable(false).extend({ falseTimeout: 500 }); export const MessagelistUserStore = ko.observableArray().extend({ debounce: 0 }); @@ -59,8 +60,6 @@ addObservablesTo(MessagelistUserStore, { focusedMessage: null }); -MessagelistUserStore.disableAutoSelect = ko.observable(false).extend({ falseTimeout: 500 }); - // Computed Observables addComputablesTo(MessagelistUserStore, { @@ -162,6 +161,11 @@ MessagelistUserStore.notifyNewMessages = (folder, newMessages) => { } } +MessagelistUserStore.canAutoSelect = () => + !/is:unseen/.test(MessagelistUserStore.mainSearch()) + && !disableAutoSelect() + && SettingsUserStore.usePreviewPane(); + /** * @param {boolean=} bDropPagePosition = false * @param {boolean=} bDropCurrentFolderCache = false @@ -258,7 +262,7 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrentFolderCach MessageUserStore.message(null); } - MessagelistUserStore.disableAutoSelect(true); + disableAutoSelect(true); MessagelistUserStore(collection); MessagelistUserStore.isIncomplete(false); diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index b7fcfbd04..88392811e 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -175,7 +175,7 @@ export class MailMessageList extends AbstractViewRight { this.selector.on('ItemGetUid', message => (message ? message.generateUid() : '')); - this.selector.on('AutoSelect', () => this.useAutoSelect()); + this.selector.on('AutoSelect', () => MessagelistUserStore.canAutoSelect()); this.selector.on('UpOrDown', v => this.goToUpOrDown(v)); @@ -366,12 +366,6 @@ export class MailMessageList extends AbstractViewRight { return true; } - useAutoSelect() { - return !MessagelistUserStore.disableAutoSelect() - && !/is:unseen/.test(MessagelistUserStore.mainSearch()) - && SettingsUserStore.usePreviewPane(); - } - cancelSearch() { MessagelistUserStore.mainSearch(''); this.focusSearch(false); @@ -649,7 +643,7 @@ export class MailMessageList extends AbstractViewRight { MessagelistUserStore.mainSearch(sLastSearchValue); return false; } - if (MessageUserStore.message() && this.useAutoSelect()) { + if (MessageUserStore.message() && MessagelistUserStore.canAutoSelect()) { isFullscreen() || toggleFullscreen(); return false; } diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index d42a5faa2..8f930712d 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -57,7 +57,7 @@ import { MessageModel } from 'Model/Message'; const oMessageScrollerDom = () => elementById('messageItem') || {}, - currentMessage = () => MessageUserStore.message(); + currentMessage = MessageUserStore.message; export class MailMessageView extends AbstractViewRight { constructor() { @@ -85,7 +85,7 @@ export class MailMessageView extends AbstractViewRight { createCommand(() => { const message = currentMessage(); if (message) { - MessageUserStore.message(null); + currentMessage(null); rl.app.deleteMessagesFromFolder(folderType, message.folder, [message.uid], useFolder); } }, this.messageVisibility); @@ -219,24 +219,22 @@ export class MailMessageView extends AbstractViewRight { } closeMessage() { - MessageUserStore.message(null); + currentMessage(null); } messageEditCommand() { - if (currentMessage()) { - showMessageComposer([ComposeType.Draft, currentMessage()]); - } + currentMessage() && showMessageComposer([ComposeType.Draft, currentMessage()]); } goUpCommand() { fireEvent('mailbox.message-list.selector.go-up', - SettingsUserStore.usePreviewPane() || !!currentMessage() // bForceSelect + !!currentMessage() // bForceSelect ); } goDownCommand() { fireEvent('mailbox.message-list.selector.go-down', - SettingsUserStore.usePreviewPane() || !!currentMessage() // bForceSelect + !!currentMessage() // bForceSelect ); } @@ -338,7 +336,7 @@ export class MailMessageView extends AbstractViewRight { AppUserStore.focusedState(Scope.MessageList); } } else if (!preview) { - MessageUserStore.message(null); + currentMessage(null); } else { AppUserStore.focusedState(Scope.MessageList); }