Skip to content

Commit f46e019

Browse files
committed
fix: Remove blank line with 'On completion Delete', toggling in Live Preview
Partial fix for #3342
1 parent 3c63b39 commit f46e019

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

resources/sample_vaults/Tasks-Demo/Manual Testing/Task Toggling Scenarios/On Completion Delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
- [ ] #task Complete in **Live Preview** clicking checkbox 🏁 delete
3232
- Line after
3333

34-
==❌ This shows \#3342 - blank line remains, as of Tasks `7.18.4`.==
34+
✅ Whole line is removed.
3535

3636
## Reading Mode
3737

src/Obsidian/LivePreviewExtension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,22 @@ class LivePreviewExtension implements PluginValue {
9191
const toggled = task.toggleWithRecurrenceInUsersOrder();
9292
const toggledString = toggled.map((t) => t.toFileLineString()).join(state.lineBreak);
9393

94+
let to = line.to;
95+
96+
if (toggledString === '') {
97+
// We also need to remove any line break at the end of the line.
98+
const nextLine = line.number < state.doc.lines ? state.doc.line(line.number + 1) : null;
99+
if (nextLine) {
100+
// If not the last line, delete up to the start of the next line, including the line break
101+
to = nextLine.from;
102+
}
103+
}
104+
94105
// Creates a CodeMirror transaction in order to update the document.
95106
const transaction = state.update({
96107
changes: {
97108
from: line.from,
98-
to: line.to,
109+
to,
99110
insert: toggledString,
100111
},
101112
});

0 commit comments

Comments
 (0)