Cursor moving to the start of next line after action `Toggle Tasks`

Hi. I’d like to report inconsistent behaviors of the same action.

Notes: on macOS, run actions via hotkey; on iOS, run them via actionBar buttons

Steps to reproduce:

  • make a sample line task, and a next empty line
  • move the cursor to the task line
  • on iOS, show actionGroup `Editing` in actionBar
  • make the line a markdown task: run this action `Editing > Make Tasks`
  • run this action `Editing > Toggle Tasks`
    • on iOS, cursor moved to the start of next line
    • on macOS, cursor position is preserved

Workaround: to edit the script to move the cursor back to its last position, but that isn’t perfect.

Question: can it be the default behavior that cursor position is preserved after running actions, like it is now on macOS? or did I miss any settings option?

drafts - iOS cursor moving after action

The script action

// Toggle tasks marks on selected lines
const off = "[ ]";
const on = "[x]";

// grab state
let [lnStart, lnLen] = editor.getSelectedLineRange();
let lnText = editor.getTextInRange(lnStart, lnLen);
let [selStart, selLen] = editor.getSelectedRange();

// check if any incomplete tasks are in selection
if (lnText.includes(off)) {
	lnText = lnText.replaceAll(off, on);
}
else { // no incomplete tasks, mark undone
	lnText = lnText.replaceAll(on, off);
}
editor.setTextInRange(lnStart, lnLen, lnText);

Firstly, I updated the toggle tasks action to properly restore the selected range. In general, a well-behaved action like this should do that to ensure correctness. In this case there’s not change to the range size, or similar, but it should do it anyway…you’ll notice the action already grabbed the range to be able to use it to update, but just didn’t.

That said, this is a change in behavior, likely related to the recent editor performance improvements, and I’ll look at fixing it.

1 Like