Skip to content

Commit b118f89

Browse files
authored
fix (global color scheme): fix jumping when dragging in color picker (#3645)
* fix jumping when dragging color picker * add comment
1 parent 45a50e3 commit b118f89

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/plugins/global-settings/color-schemes/color-scheme-picker.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,25 @@ const ColorSchemePicker = props => {
236236
}
237237
}
238238

239-
const currentItem = cloneDeep( itemInEdit )
239+
setItemInEdit( prevItem => {
240+
// clone deep causes the color picker to jump when dragging, so we use a spread operator to create a new object
241+
const currentItem = { ...prevItem }
240242

241-
if ( ! schemeHasValue( currentItem.colorScheme ) && changeDefaultName ) {
242-
currentItem.name = currentItem?.key === 'scheme-default-1' ? 'Color Scheme 1' : 'Color Scheme 2'
243-
}
243+
if ( ! schemeHasValue( currentItem.colorScheme ) && changeDefaultName ) {
244+
currentItem.name = currentItem?.key === 'scheme-default-1' ? 'Color Scheme 1' : 'Color Scheme 2'
245+
}
244246

245-
currentItem.colorScheme[ property ][ currentState ] = color
247+
currentItem.colorScheme[ property ][ currentState ] = color
246248

247-
if ( property === 'backgroundColor' && isGradient( color ) ) {
248-
currentItem.colorScheme[ property ].desktopHover = ''
249-
currentItem.colorScheme[ property ].desktopParentHover = ''
250-
}
249+
if ( property === 'backgroundColor' && isGradient( color ) ) {
250+
currentItem.colorScheme[ property ].desktopHover = ''
251+
currentItem.colorScheme[ property ].desktopParentHover = ''
252+
}
251253

252-
setItemInEdit( currentItem )
254+
updateColorSchemes( currentItem )
253255

254-
updateColorSchemes( currentItem )
256+
return currentItem
257+
} )
255258
}
256259

257260
// For updating option to show the color scheme in color pickers

0 commit comments

Comments
 (0)