@@ -42,11 +42,16 @@ export const toggleDone = (checking: boolean, editor: Editor, view: MarkdownView
42
42
} else {
43
43
// https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3342
44
44
// If insertion.text is empty, delete the line instead, so we don't leave a trailing end-of-line character around.
45
- // This behaves gracefully even if there is no end-of-line character on the last line in the file.
46
- const from = { line : lineNumber , ch : 0 } ;
47
- const to = { line : lineNumber + 1 , ch : 0 } ;
48
- // console.log(`Deleting line+EOL "${editor.getRange(from, to)}", because insertion.text is empty.`);
49
- editor . replaceRange ( '' , from , to ) ;
45
+ if ( lineNumber < editor . lineCount ( ) - 1 ) {
46
+ const from = { line : lineNumber , ch : 0 } ;
47
+ const to = { line : lineNumber + 1 , ch : 0 } ;
48
+ // console.log(`Deleting line+EOL "${editor.getRange(from, to)}", because insertion.text is empty.`);
49
+ editor . replaceRange ( '' , from , to ) ;
50
+ } else {
51
+ // There is no end-of-line character on our line, which is the last line in the file.
52
+ // console.log(`Deleting line "${editor.getLine(lineNumber)}", because insertion.text is empty.`);
53
+ editor . setLine ( lineNumber , insertion . text ) ;
54
+ }
50
55
}
51
56
52
57
/* Cursor positions are 0-based for both "line" and "ch" offsets.
0 commit comments