Open ricardo opened 3 years ago
also replacing with a different document (for example resetting to original one in a viewmodel) can result quite easily in an invalid selection, resulting in the above exception.
also replacing with a different document (for example resetting to original one in a viewmodel) can result quite easily in an invalid selection, resulting in the above exception.
We are also running into this problem a lot, especially now that you cannot set the editor value
, but have to fallback to remove/add all nodes again when you want to re-initialize an editor
I believe this is a duplicate of #3641
Problem When dealing with complex replacements and selection operations, it's very common to get invalid ranges, which cause the editor to crash with an error
Cannot resolve a DOM point from Slate point
.Example code:
I know this would be partially the fault of an unreliable editor built on top of Slate, which could result in such invalid ranges, but I believe Slate could provide better ways to deal with these invalid ranges.
Solution Suggested approaches:
console.warn
warning if the selection is invalid, and do nothing with the command. E.g if it's a select operation, don't perform the operation and throw a descriptive warning.Alternatives Given Slate is still in beta, and there are some open issues around inconsistencies in ranges selecion/removal, I'd say the first option under the proposed solutions would be best - doing nothing in case there's an invalid range and throw a descriptive warning.