@@ -18,6 +18,7 @@ import { reactive } from "@odoo/owl";
18
18
import { _t } from "@web/core/l10n/translation" ;
19
19
import { isColorGradient , isCSSColor , RGBA_REGEX , rgbaToHex } from "@web/core/utils/colors" ;
20
20
import { ColorSelector } from "./color_selector" ;
21
+ import { backgroundImageCssToParts , backgroundImagePartsToCss } from "@html_editor/utils/image" ;
21
22
22
23
const RGBA_OPACITY = 0.6 ;
23
24
const HEX_OPACITY = "99" ;
@@ -442,25 +443,43 @@ export class ColorPlugin extends Plugin {
442
443
. replace ( mode === "color" ? TEXT_CLASSES_REGEX : BG_CLASSES_REGEX , "" )
443
444
. replace ( / \b t e x t - g r a d i e n t \b / g, "" ) // cannot be combined with setting a background
444
445
. replace ( / \s + / , " " ) ;
445
- oldClassName !== newClassName && element . setAttribute ( "class" , newClassName ) ;
446
- element . style [ "background-image" ] = "" ;
446
+ if ( oldClassName !== newClassName ) {
447
+ element . setAttribute ( "class" , newClassName ) ;
448
+ }
449
+ const oldBackgroundImage = element . style [ "background-image" ] ;
450
+ const parts = backgroundImageCssToParts ( oldBackgroundImage ) ;
451
+ delete parts . gradient ;
452
+ const newBackgroundImage = backgroundImagePartsToCss ( parts ) ;
453
+ if ( oldBackgroundImage !== newBackgroundImage ) {
454
+ setBackgroundImage ( element , newBackgroundImage ) ;
455
+ }
447
456
if ( mode === "backgroundColor" ) {
448
- element . style [ "background" ] = "" ;
457
+ element . style [ "background-color " ] = "" ;
449
458
}
459
+
450
460
if ( color . startsWith ( "text" ) || color . startsWith ( "bg-" ) ) {
451
461
element . style [ mode ] = "" ;
452
462
element . classList . add ( color ) ;
453
463
} else if ( isColorGradient ( color ) ) {
454
464
element . style [ mode ] = "" ;
465
+ parts . gradient = color ;
455
466
if ( mode === "color" ) {
456
- element . style [ "background" ] = "" ;
457
- this . delegateTo ( "apply_color_style" , element , "background-image" , color ) ;
467
+ element . style [ "background-color" ] = "" ;
458
468
element . classList . add ( "text-gradient" ) ;
459
- } else {
460
- this . delegateTo ( "apply_color_style" , element , "background-image" , color ) ;
461
469
}
470
+ this . delegateTo (
471
+ "apply_color_style" ,
472
+ element ,
473
+ "background-image" ,
474
+ backgroundImagePartsToCss ( parts )
475
+ ) ;
462
476
} else {
463
477
this . delegateTo ( "apply_color_style" , element , mode , color ) ;
464
478
}
465
479
}
466
480
}
481
+
482
+ function setBackgroundImage ( el , backgroundImage ) {
483
+ el . style . backgroundImage =
484
+ ! backgroundImage || backgroundImage === "none" ? "" : backgroundImage ;
485
+ }
0 commit comments