Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line folding #87

Merged
merged 11 commits into from
Jun 27, 2024
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
list.
([#69](https://github.com/dart-lang/yaml_edit/issues/69))

- Fix error thrown when inserting in nested list using `spliceList` method
([#83](https://github.com/dart-lang/yaml_edit/issues/83))
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to file this as a separate PR, if you want. Then we get to land it quickly :D

Tagging it along here is harmless though.


- Fix error thrown when string has spaces when applying `ScalarStyle.FOLDED`.
([#41](https://github.com/dart-lang/yaml_edit/issues/41)). Resolves
([[#86](https://github.com/dart-lang/yaml_edit/issues/86)]).

## 2.2.1

- Require Dart 3.0
Expand Down
2 changes: 1 addition & 1 deletion lib/src/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class YamlEditor {
final end = getContentSensitiveEnd(_contents);
final lineEnding = getLineEnding(_yaml);
final edit = SourceEdit(
start, end - start, yamlEncodeBlockString(valueNode, 0, lineEnding));
start, end - start, yamlEncodeBlock(valueNode, 0, lineEnding));

return _performEdit(edit, path, valueNode);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/src/list_mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ SourceEdit updateInList(
final listIndentation = getListIndentation(yaml, list);
final indentation = listIndentation + getIndentation(yamlEdit);
final lineEnding = getLineEnding(yaml);
valueString = yamlEncodeBlockString(
wrapAsYamlNode(newValue), indentation, lineEnding);
valueString =
yamlEncodeBlock(wrapAsYamlNode(newValue), indentation, lineEnding);

/// We prefer the compact nested notation for collections.
///
Expand All @@ -52,7 +52,7 @@ SourceEdit updateInList(

return SourceEdit(offset, end - offset, valueString);
} else {
valueString = yamlEncodeFlowString(newValue);
valueString = yamlEncodeFlow(newValue);
return SourceEdit(offset, currValue.span.length, valueString);
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ SourceEdit _appendToBlockList(
final newIndentation = listIndentation + getIndentation(yamlEdit);
final lineEnding = getLineEnding(yaml);

var valueString = yamlEncodeBlockString(item, newIndentation, lineEnding);
var valueString = yamlEncodeBlock(item, newIndentation, lineEnding);
if (isCollection(item) && !isFlowYamlCollectionNode(item) && !isEmpty(item)) {
valueString = valueString.substring(newIndentation);
}
Expand All @@ -151,7 +151,7 @@ SourceEdit _appendToBlockList(

/// Formats [item] into a new node for flow lists.
String _formatNewFlow(YamlList list, YamlNode item, [bool isLast = false]) {
var valueString = yamlEncodeFlowString(item);
var valueString = yamlEncodeFlow(item);
if (list.isNotEmpty) {
if (isLast) {
valueString = ', $valueString';
Expand Down
14 changes: 7 additions & 7 deletions lib/src/map_mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SourceEdit _addToBlockMap(
final yaml = yamlEdit.toString();
final newIndentation =
getMapIndentation(yaml, map) + getIndentation(yamlEdit);
final keyString = yamlEncodeFlowString(wrapAsYamlNode(key));
final keyString = yamlEncodeFlow(wrapAsYamlNode(key));
final lineEnding = getLineEnding(yaml);

var formattedValue = ' ' * getMapIndentation(yaml, map);
Expand Down Expand Up @@ -83,7 +83,7 @@ SourceEdit _addToBlockMap(
}
}

var valueString = yamlEncodeBlockString(newValue, newIndentation, lineEnding);
var valueString = yamlEncodeBlock(newValue, newIndentation, lineEnding);
if (isCollection(newValue) &&
!isFlowYamlCollectionNode(newValue) &&
!isEmpty(newValue)) {
Expand All @@ -100,8 +100,8 @@ SourceEdit _addToBlockMap(
/// map.
SourceEdit _addToFlowMap(
YamlEditor yamlEdit, YamlMap map, YamlNode keyNode, YamlNode newValue) {
final keyString = yamlEncodeFlowString(keyNode);
final valueString = yamlEncodeFlowString(newValue);
final keyString = yamlEncodeFlow(keyNode);
final valueString = yamlEncodeFlow(newValue);

// The -1 accounts for the closing bracket.
if (map.isEmpty) {
Expand Down Expand Up @@ -131,8 +131,8 @@ SourceEdit _replaceInBlockMap(
getMapIndentation(yaml, map) + getIndentation(yamlEdit);

final keyNode = getKeyNode(map, key);
var valueAsString = yamlEncodeBlockString(
wrapAsYamlNode(newValue), newIndentation, lineEnding);
var valueAsString =
yamlEncodeBlock(wrapAsYamlNode(newValue), newIndentation, lineEnding);
if (isCollection(newValue) &&
!isFlowYamlCollectionNode(newValue) &&
!isEmpty(newValue)) {
Expand Down Expand Up @@ -163,7 +163,7 @@ SourceEdit _replaceInBlockMap(
SourceEdit _replaceInFlowMap(
YamlEditor yamlEdit, YamlMap map, Object? key, YamlNode newValue) {
final valueSpan = map.nodes[key]!.span;
final valueString = yamlEncodeFlowString(newValue);
final valueString = yamlEncodeFlow(newValue);

return SourceEdit(valueSpan.start.offset, valueSpan.length, valueString);
}
Expand Down
Loading