Skip to content

Commit 28fb70d

Browse files
committed
refactor: . Extract variable taskIsOnLastLine
1 parent d32ef65 commit 28fb70d

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
@@ -39,12 +39,13 @@ export const toggleDone = (checking: boolean, editor: Editor, view: MarkdownView
3939

4040
const replacementTextIsNonEmpty = insertion.text.length > 0;
4141
const taskWasNotOnLastLine = lineNumber < editor.lineCount() - 1;
42+
const taskIsOnLastLine = !taskWasNotOnLastLine;
4243
if (replacementTextIsNonEmpty) {
4344
editor.setLine(lineNumber, insertion.text);
4445
} else {
4546
// https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3342
4647
// If insertion.text is empty, delete the line instead, so we don't leave a trailing end-of-line character around.
47-
if (!taskWasNotOnLastLine) {
48+
if (taskIsOnLastLine) {
4849
// There is no end-of-line character on our line, which is the last line in the file.
4950
// console.log(`Deleting line "${editor.getLine(lineNumber)}", because insertion.text is empty.`);
5051
editor.setLine(lineNumber, insertion.text);

0 commit comments

Comments
 (0)