mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-21 02:23:30 +00:00
Speed up search by cacheing preset text values and not scrolling to focused node as often
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user