Fix a crash when lifting nested list #8

Merged
ocavue merged 1 commit from ocavue/fix_lift_crash into master 2022-07-20 11:19:06 +02:00
ocavue commented 2022-07-20 10:24:55 +02:00 (Migrated from github.com)

Close https://github.com/ProseMirror/prosemirror/issues/1299

In the case above, liftTarget will return null, which shouldn't be passed to tr.lift because tr.lift only accept number.

Before the JS=>TS update, liftTarge here used to return undefined. undefined and null have different behavior when passed to tr.lift. That's why we see this bug after the TS version.

> for (let d = 3; d > undefined; d--) { console.log(d) }
undefined
> for (let d = 3; d > null; d--) { console.log(d) }
3
2
1
undefined
>

I'm not sure if my fix is the perfect solution. In particular, from a user view, I still hope Mod-[ can lift the nested item. But at least this patch fixes the crash.

Close https://github.com/ProseMirror/prosemirror/issues/1299 In the case above, `liftTarget` will return `null`, which shouldn't be passed to `tr.lift` because `tr.lift` only accept number. Before the JS=>TS update, `liftTarge` here used to return `undefined`. `undefined` and `null` have different behavior when passed to `tr.lift`. That's why we see this bug after the TS version. ``` > for (let d = 3; d > undefined; d--) { console.log(d) } undefined > for (let d = 3; d > null; d--) { console.log(d) } 3 2 1 undefined > ``` I'm not sure if my fix is the perfect solution. In particular, from a user view, I still hope `Mod-[` can lift the nested item. But at least this patch fixes the crash.
marijnh commented 2022-07-20 11:19:18 +02:00 (Migrated from github.com)

Yeah, that looks like a reasonable fix. Thanks!

Yeah, that looks like a reasonable fix. Thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-schema-list!8
No description provided.