Try to avoid style recalculation when typing on the comment box

I think this doesn't completely work.. It reduces the amount
of unnecessary DOM changes, but there are still some more.
This commit is contained in:
Bryan Housel
2019-04-19 10:02:25 -04:00
parent ca02f7ed06
commit ae06e28f9b
2 changed files with 27 additions and 14 deletions

View File

@@ -200,19 +200,26 @@ export function uiCommit(context) {
var prose = saveSection.selectAll('.commit-info')
.data([0]);
if (prose.enter().size()) { // first time, make sure to update user details in prose
_userDetails = null;
}
prose = prose.enter()
.append('p')
.attr('class', 'commit-info')
.text(t('commit.upload_explanation'))
.merge(prose);
// always check if this has changed, but only update prose.html()
// if needed, because it can trigger a style recalculation
osm.userDetails(function(err, user) {
if (err) return;
var userLink = d3_select(document.createElement('div'));
if (_userDetails === user) return; // no change
_userDetails = user;
var userLink = d3_select(document.createElement('div'));
if (user.image_url) {
userLink
.append('img')

View File

@@ -8,6 +8,7 @@ import { utilGetSetValue, utilNoAuto } from '../util';
export function uiFormFields(context) {
var moreCombo = uiCombobox(context, 'more-fields').minItems(1);
var _fieldsArr = [];
var _lastPlaceholder = '';
var _state = '';
var _klass = '';
@@ -49,17 +50,22 @@ export function uiFormFields(context) {
});
notShown = notShown.map(function(field) {
var titles = [];
var moreFields = notShown.map(function(field) {
var label = field.label();
titles.push(label);
return {
title: field.label(),
value: field.label(),
title: label,
value: label,
field: field
};
});
var placeholder = titles.slice(0,3).join(', ') + ((titles.length > 3) ? '…' : '');
var more = selection.selectAll('.more-fields')
.data((_state === 'hover' || notShown.length === 0) ? [] : [0]);
.data((_state === 'hover' || moreFields.length === 0) ? [] : [0]);
more.exit()
.remove();
@@ -82,20 +88,14 @@ export function uiFormFields(context) {
.append('input')
.attr('class', 'value')
.attr('type', 'text')
.attr('placeholder', placeholder)
.call(utilNoAuto)
.merge(input);
input
.call(utilGetSetValue, '')
.attr('placeholder', function() {
var placeholder = [];
for (var field in notShown) {
placeholder.push(notShown[field].title);
}
return placeholder.slice(0,3).join(', ') + ((placeholder.length > 3) ? '…' : '');
})
.call(moreCombo
.data(notShown)
.data(moreFields)
.on('accept', function (d) {
if (!d) return; // user entered something that was not matched
var field = d.field;
@@ -106,6 +106,12 @@ export function uiFormFields(context) {
}
})
);
// avoid updating placeholder excessively (triggers style recalc)
if (_lastPlaceholder !== placeholder) {
input.attr('placeholder', placeholder);
_lastPlaceholder = placeholder;
}
}