Skip to content

Commit e89bed9

Browse files
committed
Make style-path helpers generic over fill & stroke
1 parent e5285da commit e89bed9

File tree

5 files changed

+219
-139
lines changed

5 files changed

+219
-139
lines changed

src/containers/fill-color-indicator.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {isBitmap} from '../lib/format';
1616
import GradientTypes from '../lib/gradient-types';
1717

1818
import FillColorIndicatorComponent from '../components/fill-color-indicator.jsx';
19-
import {applyFillColorToSelection,
19+
import {applyColorToSelection,
2020
applyGradientTypeToSelection,
2121
getRotatedColor,
2222
swapColorsInSelection,
@@ -45,11 +45,12 @@ class FillColorIndicator extends React.Component {
4545
}
4646
handleChangeFillColor (newColor) {
4747
// Apply color and update redux, but do not update svg until picker closes.
48-
const isDifferent = applyFillColorToSelection(
48+
const isDifferent = applyColorToSelection(
4949
newColor,
5050
this.props.colorIndex,
5151
this.props.gradientType === GradientTypes.SOLID,
5252
isBitmap(this.props.format),
53+
false, // applyToStroke
5354
this.props.textEditTarget);
5455
this._hasChanged = this._hasChanged || isDifferent;
5556
this.props.onChangeFillColor(newColor, this.props.colorIndex);
@@ -59,6 +60,7 @@ class FillColorIndicator extends React.Component {
5960
const isDifferent = applyGradientTypeToSelection(
6061
gradientType,
6162
isBitmap(this.props.format),
63+
false, // applyToStroke
6264
this.props.textEditTarget);
6365
this._hasChanged = this._hasChanged || isDifferent;
6466
const hasSelectedItems = getSelectedLeafItems().length > 0;
@@ -92,6 +94,7 @@ class FillColorIndicator extends React.Component {
9294
if (getSelectedLeafItems().length) {
9395
const isDifferent = swapColorsInSelection(
9496
isBitmap(this.props.format),
97+
false, // applyToStroke
9598
this.props.textEditTarget);
9699
this.props.setSelectedItems();
97100
this._hasChanged = this._hasChanged || isDifferent;

src/containers/stroke-color-indicator.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Formats from '../lib/format';
1010
import {isBitmap} from '../lib/format';
1111

1212
import StrokeColorIndicatorComponent from '../components/stroke-color-indicator.jsx';
13-
import {applyStrokeColorToSelection, applyStrokeWidthToSelection} from '../helper/style-path';
13+
import {applyColorToSelection, applyStrokeWidthToSelection} from '../helper/style-path';
1414

1515
class StrokeColorIndicator extends React.Component {
1616
constructor (props) {
@@ -40,8 +40,13 @@ class StrokeColorIndicator extends React.Component {
4040
this.props.onChangeStrokeWidth(0);
4141
}
4242
// Apply color and update redux, but do not update svg until picker closes.
43-
this._hasChanged =
44-
applyStrokeColorToSelection(newColor, isBitmap(this.props.format), this.props.textEditTarget) ||
43+
this._hasChanged = applyColorToSelection(
44+
newColor,
45+
0, // colorIndex,
46+
true, // isSolidGradient
47+
isBitmap(this.props.format),
48+
true, // applyToStroke
49+
this.props.textEditTarget) ||
4550
this._hasChanged;
4651
this.props.onChangeStrokeColor(newColor);
4752
}

src/containers/stroke-width-indicator.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {changeStrokeColor} from '../reducers/stroke-color';
77
import {changeStrokeWidth} from '../reducers/stroke-width';
88
import StrokeWidthIndicatorComponent from '../components/stroke-width-indicator.jsx';
99
import {getSelectedLeafItems} from '../helper/selection';
10-
import {applyStrokeColorToSelection, applyStrokeWidthToSelection, getColorsFromSelection, MIXED}
10+
import {applyColorToSelection, applyStrokeWidthToSelection, getColorsFromSelection, MIXED}
1111
from '../helper/style-path';
1212
import Modes from '../lib/modes';
1313
import Formats from '../lib/format';
@@ -25,7 +25,13 @@ class StrokeWidthIndicator extends React.Component {
2525
if ((!this.props.strokeWidth || this.props.strokeWidth === 0) && newWidth > 0) {
2626
let currentColor = getColorsFromSelection(getSelectedLeafItems(), isBitmap(this.props.format)).strokeColor;
2727
if (currentColor === null) {
28-
changed = applyStrokeColorToSelection('#000', isBitmap(this.props.format), this.props.textEditTarget) ||
28+
changed = applyColorToSelection(
29+
'#000',
30+
0, // colorIndex,
31+
true, // isSolidGradient
32+
isBitmap(this.props.format),
33+
true, // applyToStroke
34+
this.props.textEditTarget) ||
2935
changed;
3036
currentColor = '#000';
3137
} else if (currentColor !== MIXED) {

0 commit comments

Comments
 (0)