This action moves the checked items of a list to the end of the list, maintaining the structure of the draft. So if you have multiple lists in your document, they are treated each of their own.
Example 1:
- [ ] item 1
- [ ] item 4
- [x] item 2
- [x] item 3
Example 2:
- [ ] item A
- [ ] item D
- [x] item B
- [x] item C
Example 3:
- [ ] item 1
- [ ] item 4
- [x] item 2
- [x] item 3
I think your current logic would benefit from a tweak to account for the case of the last line of a multi-list draft not ending in a non-checklist entry.
Without rewriting some of your core code to address this edge case, at the start, you could carry out a check on the last line, append a newline if necessary, keep a note if you do, and then remove the newline at the end of the processing if one was added.
For the following code:
if (device.model === "iPhone") {
app.hideActionList();
}
You may also want to check out if editor.activate() might give you another option for what you want to do?