Skip to content

Commit 7ba5502

Browse files
committed
refactor: . Extract variable taskWasNotOnLastLine
1 parent c5223ba commit 7ba5502

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Commands/ToggleDone.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ export const toggleDone = (checking: boolean, editor: Editor, view: MarkdownView
3838
const insertion = toggleLine(line, path);
3939

4040
const replacementTextIsNonEmpty = insertion.text.length > 0;
41+
const taskWasNotOnLastLine = lineNumber < editor.lineCount() - 1;
4142
if (replacementTextIsNonEmpty) {
4243
editor.setLine(lineNumber, insertion.text);
4344
} else {
4445
// https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3342
4546
// If insertion.text is empty, delete the line instead, so we don't leave a trailing end-of-line character around.
46-
if (lineNumber < editor.lineCount() - 1) {
47+
if (taskWasNotOnLastLine) {
4748
const from = { line: lineNumber, ch: 0 };
4849
const to = { line: lineNumber + 1, ch: 0 };
4950
// console.log(`Deleting line+EOL "${editor.getRange(from, to)}", because insertion.text is empty.`);

0 commit comments

Comments
 (0)