Skip to content

Commit

Permalink
chore(context-pad): update position in next frame
Browse files Browse the repository at this point in the history
We'll otherwise force the browser into expensive re-flows.
  • Loading branch information
nikku committed Jul 4, 2024
1 parent c4ec98f commit dadec48
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lib/features/context-pad/ContextPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,29 +611,34 @@ ContextPad.prototype._getPosition = function(target) {
* Update context pad position.
*/
ContextPad.prototype._updatePosition = function() {
if (!this.isOpen()) {
return;
}

var html = this._current.html;
const updateFn = () => {
if (!this.isOpen()) {
return;
}

var position = this._getPosition(this._current.target);
var html = this._current.html;

if ('x' in position && 'y' in position) {
html.style.left = position.x + 'px';
html.style.top = position.y + 'px';
} else {
[
'top',
'right',
'bottom',
'left'
].forEach(function(key) {
if (key in position) {
html.style[ key ] = position[ key ] + 'px';
}
});
}
var position = this._getPosition(this._current.target);

if ('x' in position && 'y' in position) {
html.style.left = position.x + 'px';
html.style.top = position.y + 'px';
} else {
[
'top',
'right',
'bottom',
'left'
].forEach(function(key) {
if (key in position) {
html.style[ key ] = position[ key ] + 'px';
}
});
}
};

this._scheduler.schedule(updateFn, 'ContextPad#_updatePosition');
};

/**
Expand Down

0 comments on commit dadec48

Please sign in to comment.