Speed up search by cacheing preset text values and not scrolling to focused node as often

This commit is contained in:
Quincy Morgan
2019-03-21 11:19:20 -04:00
parent f114945628
commit 705f15aadd
2 changed files with 18 additions and 7 deletions

View File

@@ -128,9 +128,16 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
return score;
};
var _textCache = {};
preset.t = function(scope, options) {
return t('presets.presets.' + id + '.' + scope, options);
var textID = 'presets.presets.' + id + '.' + scope;
if (_textCache[textID]) return _textCache[textID];
var text = t(textID, options);
_textCache[textID] = text;
return text;
};

View File

@@ -230,7 +230,7 @@ export function uiSearchAdd(context) {
}
}
if (!nextFocus.empty()) {
focusListItem(nextFocus);
focusListItem(nextFocus, true);
priorFocus.classed('focused', false);
}
@@ -253,7 +253,7 @@ export function uiSearchAdd(context) {
}
}
if (!nextFocus.empty()) {
focusListItem(nextFocus);
focusListItem(nextFocus, true);
priorFocus.classed('focused', false);
}
}
@@ -282,17 +282,21 @@ export function uiSearchAdd(context) {
popover.selectAll('.list .list-item.focused')
.classed('focused', false);
focusListItem(popover.selectAll('.list > .list-item:first-child'));
focusListItem(popover.selectAll('.list > .list-item:first-child'), false);
popoverContent.node().scrollTop = 0;
var resultCount = results.length;
message.text(t('modes.add_feature.' + (resultCount === 1 ? 'result' : 'results'), { count: resultCount }));
}
function focusListItem(selection) {
function focusListItem(selection, scrollingToShow) {
if (!selection.empty()) {
selection.classed('focused', true);
// scroll to keep the focused item visible
scrollPopoverToShow(selection);
if (scrollingToShow) {
// scroll to keep the focused item visible
scrollPopoverToShow(selection);
}
}
}