Skip to content

Conversation

@beverlyck
Copy link

@beverlyck beverlyck commented Jun 29, 2021

When we modify update or set the text attribute, the "snap.util.attr" event triggers and that causes a chain of callbacks for the event. If the text value starts with with a prefix format like here,

Snap.svg/src/svg.js

Lines 1399 to 1401 in 6f02a26

* Prefixed values in format `"+=10"` supported. All four operations
* (`+`, `-`, `*` and `/`) could be used. Optionally you can use units for `+`
* and `-`: `"+=2em"`.

For example, + = 3 will throw an error on

Snap.svg/src/attradd.js

Lines 40 to 63 in 6f02a26

eve.on("snap.util.attr", function (val) {
var plus = Str(val).match(reAddon);
if (plus) {
var evnt = eve.nt(),
name = evnt.substring(evnt.lastIndexOf(".") + 1),
a = this.attr(name),
atr = {};
eve.stop();
var unit = plus[3] || "",
aUnit = a.match(reUnit),
op = operators[plus[1]];
if (aUnit && aUnit == unit) {
val = op(parseFloat(a), +plus[2]);
} else {
a = this.asPX(name);
val = op(this.asPX(name), this.asPX(name, plus[2] + unit));
}
if (isNaN(a) || isNaN(val)) {
return;
}
atr[name] = val;
this.attr(atr);
}
})(-10);

This PR added a check, if the reAddon matcher is successful and if the attr name is "text", it returns instead of stopping propagation and performing the prefix value operations.

…n text attribute is set or updated and begins with

a prefix values format (i.e.,`"+=10"`) or  any combination of the four operators, the reAddon plugin
throws errors and the text fails to update.
Comment on lines +47 to +49
if (name === "text") {
return;
}
Copy link
Author

@beverlyck beverlyck Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reAddon plugin change here but when I rebuilt from the source, the other files were changed.

@beverlyck beverlyck changed the base branch from master to dev June 29, 2021 22:09
@beverlyck beverlyck changed the base branch from dev to master June 29, 2021 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant