Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix expression editor decoration #4261

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions apps/builder/app/builder/shared/expression-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,32 @@ class VariableWidget extends WidgetType {

const variableMatcher = new MatchDecorator({
regexp: /(\$ws\$dataSource\$\w+)/g,
decoration: (match, view) => {

decorate: (add, from, _to, match, view) => {
// Your logic here
istarkov marked this conversation as resolved.
Show resolved Hide resolved
const startPos = match.index;

const name = match[1];
const [data] = view.state.facet(VariablesData);
return Decoration.replace({
widget: new VariableWidget(data.aliases.get(name) ?? name),
});
const [{ aliases }] = view.state.facet(VariablesData);

// The regexp may match variables not in scope, but the key problem we're solving is this:
// We have an alias $ws$dataSource$321 -> SomeVar, which we display as '[SomeVar]' ([] means decoration in the editor).
// If the user types a symbol (e.g., 'a') immediately after '[SomeVar]',
// the raw text becomes $ws$dataSource$321a, but we want to display '[SomeVar]a'.
const dataSourceId = [...aliases.keys()].find((key) => name.includes(key));

if (dataSourceId === undefined) {
return;
}
const endPos = startPos + dataSourceId.length;

add(
from,
endPos,
Decoration.replace({
widget: new VariableWidget(aliases.get(dataSourceId)!),
})
);
},
});

Expand Down