Skip to content

Commit f8dbd92

Browse files
authored
Merge pull request #1332 from pjkaufman/master
Fix an Issue with Removing Trailing Spaces not Working on Empty Lists Items with No List Item Spaces
2 parents 4cfa384 + 888381d commit f8dbd92

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

__tests__/trailing-spaces.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,20 @@ ruleTest({
154154
3.${' '}
155155
`,
156156
},
157+
{ // accounts for https://github.com/platers/obsidian-linter/issues/1329
158+
testName: 'Make sure that we properly handle an empty list item when it is empty and has no spaces in it',
159+
before: dedent`
160+
Some text
161+
${''}
162+
-
163+
${''}
164+
`,
165+
after: dedent`
166+
Some text
167+
${''}
168+
-
169+
${''}
170+
`,
171+
},
157172
],
158173
});

src/utils/mdast.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ export function updateListItemText(text: string, func:(text: string) => string,
616616
startIndex++;
617617
}
618618

619-
startIndex++;
619+
if (startIndex < position.position.end.offset) {
620+
startIndex++;
621+
}
620622
} else {
621623
// get the actual start of the list item leaving only 1 whitespace between the indicator and the text
622624
while (startIndex > 0 && text.charAt(startIndex - 1).trim() === '') {

0 commit comments

Comments
 (0)