formula: better regexp (no need to escape object closing brackets)

This commit is contained in:
jean-emmanuel 2018-10-16 12:29:03 +02:00
parent 2ca4ff2715
commit 20128b3327
3 changed files with 4 additions and 3 deletions

View file

@ -20,6 +20,7 @@
- right-click doesn't modify current selection when `mod` or `shift` is pressed
- formulas
- added `extend(x, y)` function for merging two objects
- objects' closing brackets (`}`) don't need to be escaped with a backslash anymore
## 0.37.4

View file

@ -76,7 +76,6 @@ Where FORMULA is a valid [MathJS](http://mathjs.org/docs/expressions/syntax.html
- property inheritance calls (`@{...}`) are always resolved before formulas
- arrays / matrices indexes are **zero-based** (ie `["a","b"][0]` returns `"a"`)
- strings can be multiline when enclosed in backticks instead of double quotes (``` ` ` ```)
- inner closing brackets (`}`) must be escaped with a backslash (`\}`) except for `@{}` and `OSC{}` calls which are always resolved before formulas
Additionnal functions:

View file

@ -456,9 +456,10 @@ class Widget extends EventEmitter {
})
try {
propValue = propValue.replace(/#\{(?:[^}\\]|\\.)+\}/g, (m)=>{
propValue = propValue.replace(/#\{(?:[^{}]|\{[^{}]*\})*\}/g, (m)=>{
// one bracket nesting allowed, if we need two: #\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}
// unescape brackets
// unescape brackets (not needed anymore, just here for backward compatibility)
m = m.replace(/\\(\{|\})/g, '$1')
// espace multiline strings