slate-auto-replace not compatible with Slate 30.6
thesunny opened this issue · 3 comments
Do you want to request a feature or report a bug?
bug
What's the current behavior?
Doesn't work with Slate version 30+
What's the expected behavior?
Should work in newest version of Slate
May have jumped the gun here.
The documentation still uses transform
instead of change
but looking at the source code, I see change
in there.
I'm going to go test it out now and will report back.
After checking, this plugin does work with the latest version of Slate but the documentation is out of date.
The transform description should probably be changed to say change
instead of transform
:
A function to apply the desired transform. It will be called with change, e, matches, editor from the event handler. The matching (before and after) text is deleted but are accessible inside matches.before and matches.after.
Also recommend the example be updated
// Add the plugin to your set of plugins...
const plugins = [
AutoReplace({
trigger: 'space',
before: /^(>)$/,
transform: (change, e, matches, editor) => {
change.setBlock({ type: 'quote' })
}
})
]
Should the option itself be renamed from transform
to change
for consistency?
Hey @thesunny it's been working for me all along:
AutoReplace({
trigger: /(")/,
before: /(^)|[ ]$/,
transform: (transform, event, matches) => {
return transform.insertText("“") // smart double quote (left)
}
}),
I think of transform
in this case as an alias. Changing that might have require making breaking changes on all plugins and slate core as well... so I'm OK with it as-is.