From 61819058d3b1fbcaf37f9c058530673caaa5b724 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 2 May 2019 14:21:57 -0400 Subject: [PATCH] Avoid frequent reflow from setting scrollTop (possibly re: #6289) --- modules/ui/entity_editor.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/ui/entity_editor.js b/modules/ui/entity_editor.js index 9b3ae46e1..55204e475 100644 --- a/modules/ui/entity_editor.js +++ b/modules/ui/entity_editor.js @@ -17,7 +17,7 @@ import { uiTagReference } from './tag_reference'; import { uiPresetEditor } from './preset_editor'; import { uiEntityIssues } from './entity_issues'; import { uiTooltipHtml } from './tooltipHtml'; -import { utilCleanTags, utilRebind } from '../util'; +import { utilCallWhenIdle, utilCleanTags, utilRebind } from '../util'; export function uiEntityEditor(context) { @@ -25,6 +25,7 @@ export function uiEntityEditor(context) { var _state = 'select'; var _coalesceChanges = false; var _modified = false; + var _scrolled = false; var _base; var _entityID; var _activePreset; @@ -83,7 +84,8 @@ export function uiEntityEditor(context) { // Enter var bodyEnter = body.enter() .append('div') - .attr('class', 'inspector-body'); + .attr('class', 'inspector-body') + .on('scroll.entity-editor', function() { _scrolled = true; }); bodyEnter .append('div') @@ -327,9 +329,14 @@ export function uiEntityEditor(context) { _coalesceChanges = false; // reset the scroll to the top of the inspector (warning: triggers reflow) - var body = d3_selectAll('.entity-editor-pane .inspector-body'); - if (!body.empty()) { - body.node().scrollTop = 0; + if (_scrolled) { + utilCallWhenIdle(function() { + var body = d3_selectAll('.entity-editor-pane .inspector-body'); + if (!body.empty()) { + _scrolled = false; + body.node().scrollTop = 0; + } + })(); } var presetMatch = context.presets().match(context.entity(_entityID), _base);