From e76a43df11b49b34b14ba4018cd05ea9e2f10ee0 Mon Sep 17 00:00:00 2001 From: Cosmo Myzrail Gorynych Date: Sat, 20 Jul 2024 18:39:30 +1200 Subject: [PATCH] :hankey: Fix various bugs witht the search menu --- src/riotTags/app-view.tag | 15 ++++++++------- src/riotTags/catnip/catnip-insert-mark.tag | 1 + src/riotTags/search-and-recents.tag | 10 ++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/riotTags/app-view.tag b/src/riotTags/app-view.tag index c257a5b7..93cde246 100644 --- a/src/riotTags/app-view.tag +++ b/src/riotTags/app-view.tag @@ -124,6 +124,10 @@ app-view.flexcol script. const fs = require('fs-extra'); const {saveProject, getProjectCodename} = require('src/node_requires/resources/projects'); + const resources = require('src/node_requires/resources'); + + this.editorMap = resources.editorMap; + this.iconMap = resources.resourceToIconMap; this.namespace = 'appView'; this.mixin(require('src/node_requires/riotMixins/voc').default); @@ -188,12 +192,8 @@ app-view.flexcol window.signals.off('assetRemoved', checkDeletedTabs); }); - const resources = require('src/node_requires/resources'); - this.editorMap = resources.editorMap; - this.iconMap = resources.resourceToIconMap; - - this.recentAssets = localStorage[`lastOpened_${getProjectCodename()}`] ? - JSON.parse(localStorage[`lastOpened_${getProjectCodename()}`]) : + this.recentAssets = localStorage[`recentlyOpened_${getProjectCodename()}`] ? + JSON.parse(localStorage[`recentlyOpened_${getProjectCodename()}`]) : []; this.openAsset = (asset, noOpen) => () => { // Check whether the asset is not yet opened @@ -228,10 +228,11 @@ app-view.flexcol this.recentAssets.splice(this.recentAssets.indexOf(asset.uid), 1); } this.recentAssets.unshift(asset.uid); + this.recentAssets = this.recentAssets.filter(a => resources.exists(null, a)); if (this.recentAssets.length > 10) { this.recentAssets.length = 10; } - localStorage[`lastOpened_${getProjectCodename()}`] = JSON.stringify(this.recentAssets); + localStorage[`recentlyOpened_${getProjectCodename()}`] = JSON.stringify(this.recentAssets); this.changeTab(asset)(); } diff --git a/src/riotTags/catnip/catnip-insert-mark.tag b/src/riotTags/catnip/catnip-insert-mark.tag index 67eb92c8..44931146 100644 --- a/src/riotTags/catnip/catnip-insert-mark.tag +++ b/src/riotTags/catnip/catnip-insert-mark.tag @@ -100,6 +100,7 @@ catnip-insert-mark(onclick="{toggleMenu}" class="{dragover: shouldDragover(), me const items = Array.isArray(refs) ? refs : [refs]; if (items.length) { items[0].focus(); + e.preventDefault(); } } }; diff --git a/src/riotTags/search-and-recents.tag b/src/riotTags/search-and-recents.tag index 893fc76c..2e2ff426 100644 --- a/src/riotTags/search-and-recents.tag +++ b/src/riotTags/search-and-recents.tag @@ -29,7 +29,7 @@ search-and-recents.aNav(class="{opts.class}") // Recent items li( role="menuitem" tabindex="0" ref="lastItems" - onpointerdown="{openAssetById}" onkeydown="{menuKeyDown}" + onpointerdown="{openAsset}" onkeydown="{menuKeyDown}" if="{!searchVal.trim()}}" each="{uid in recentAssets}" ) svg.feather @@ -40,7 +40,7 @@ search-and-recents.aNav(class="{opts.class}") span.small.dim {vocGlob.assetTypes[getById(uid).type][0]} .toright.small.dim {voc.recent} script. - const {searchAssets, resourceToIconMap, getById} = require('src/node_requires/resources'); + const {searchAssets, resourceToIconMap, getById, exists} = require('src/node_requires/resources'); const {getProjectCodename} = require('src/node_requires/resources/projects'); this.namespace = 'globalSearch'; @@ -58,9 +58,10 @@ search-and-recents.aNav(class="{opts.class}") setTimeout(() => { this.refs.search.focus(); }, 0); - this.recentAssets = localStorage[`lastOpened_${getProjectCodename()}`] ? - JSON.parse(localStorage[`lastOpened_${getProjectCodename()}`]) : + this.recentAssets = localStorage[`recentlyOpened_${getProjectCodename()}`] ? + JSON.parse(localStorage[`recentlyOpened_${getProjectCodename()}`]) : []; + this.recentAssets = this.recentAssets.filter(a => exists(null, a)); } }; @@ -93,6 +94,7 @@ search-and-recents.aNav(class="{opts.class}") const items = Array.isArray(refs) ? refs : [refs]; if (items.length) { items[0].focus(); + e.preventDefault(); } } };