Skip to content

Commit 854d9be

Browse files
committed
refactor: . Merge if/else
1 parent 28fb70d commit 854d9be

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Commands/ToggleDone.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,16 @@ export const toggleDone = (checking: boolean, editor: Editor, view: MarkdownView
4242
const taskIsOnLastLine = !taskWasNotOnLastLine;
4343
if (replacementTextIsNonEmpty) {
4444
editor.setLine(lineNumber, insertion.text);
45-
} else {
45+
} else if (taskIsOnLastLine) {
4646
// https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3342
47-
// If insertion.text is empty, delete the line instead, so we don't leave a trailing end-of-line character around.
48-
if (taskIsOnLastLine) {
49-
// There is no end-of-line character on our line, which is the last line in the file.
50-
// console.log(`Deleting line "${editor.getLine(lineNumber)}", because insertion.text is empty.`);
51-
editor.setLine(lineNumber, insertion.text);
52-
} else {
53-
const from = { line: lineNumber, ch: 0 };
54-
const to = { line: lineNumber + 1, ch: 0 };
55-
// console.log(`Deleting line+EOL "${editor.getRange(from, to)}", because insertion.text is empty.`);
56-
editor.replaceRange('', from, to);
57-
}
47+
// There is no end-of-line character on our line, which is the last line in the file.
48+
// console.log(`Deleting line "${editor.getLine(lineNumber)}", because insertion.text is empty.`);
49+
editor.setLine(lineNumber, insertion.text);
50+
} else {
51+
const from = { line: lineNumber, ch: 0 };
52+
const to = { line: lineNumber + 1, ch: 0 };
53+
// console.log(`Deleting line+EOL "${editor.getRange(from, to)}", because insertion.text is empty.`);
54+
editor.replaceRange('', from, to);
5855
}
5956

6057
/* Cursor positions are 0-based for both "line" and "ch" offsets.

0 commit comments

Comments
 (0)