Skip to content

Commit 0a07e65

Browse files
committed
Handle empty block sequences correctly
1 parent 04c6a21 commit 0a07e65

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkgs/yaml_edit/lib/src/list_mutations.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ SourceEdit _removeFromBlockList(
312312
final yaml = yamlEdit.toString();
313313
final span = nodeToRemove.span;
314314

315+
final isEmptySpan = span.length == 0; // Just the '-'
316+
final end = getContentSensitiveEnd(nodeToRemove);
317+
315318
return removeBlockCollectionEntry(
316319
yaml,
317320
blockCollection: list,
@@ -320,10 +323,11 @@ SourceEdit _removeFromBlockList(
320323
isSingleEntry: listSize == 1,
321324
isLastEntry: index >= listSize - 1,
322325
nodeToRemoveOffset: (
323-
start: span.length == 0
324-
? span.start.offset
325-
: yaml.lastIndexOf('-', span.start.offset - 1),
326-
end: getContentSensitiveEnd(nodeToRemove)
326+
start: yaml.lastIndexOf(
327+
'-',
328+
isEmptySpan ? span.start.offset : span.start.offset - 1,
329+
),
330+
end: isEmptySpan ? end + 1 : end,
327331
),
328332
lineEnding: getLineEnding(yaml),
329333
nextBlockNodeInfo: () {

0 commit comments

Comments
 (0)