Skip to content

Commit

Permalink
💩 Fix various bugs witht the search menu
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMyzrailGorynych committed Jul 20, 2024
1 parent bf7b474 commit e76a43d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/riotTags/app-view.tag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)();
}
Expand Down
1 change: 1 addition & 0 deletions src/riotTags/catnip/catnip-insert-mark.tag
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
};
Expand Down
10 changes: 6 additions & 4 deletions src/riotTags/search-and-recents.tag
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand All @@ -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));
}
};

Expand Down Expand Up @@ -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();
}
}
};
Expand Down

0 comments on commit e76a43d

Please sign in to comment.