rename to split-line-attributes

This commit is contained in:
marc2332 committed 2023-12-09 16:51:41 +01:00
1 parent c10cefffb6
commit ce5d7bd11b
5 files changed
+26 -21

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ impl Writer<'_> {
}
// multiline handlers bump everything down
if attr_len > 1000 || self.out.indent.inline_attributes() {
if attr_len > 1000 || self.out.indent.split_line_attributes() {
opt_level = ShortOptimization::NoOpt;
}
+5 -2
View File
@@ -102,7 +102,7 @@ impl Writer<'_> {
}
// multiline handlers bump everything down
if attr_len > 1000 || self.out.indent.inline_attributes() {
if attr_len > 1000 || self.out.indent.split_line_attributes() {
opt_level = ShortOptimization::NoOpt;
}
@@ -254,7 +254,6 @@ impl Writer<'_> {
ElementAttr::EventTokens { name, tokens } => {
let out = self.retrieve_formatted_expr(tokens).to_string();
let mut lines = out.split('\n').peekable();
let first = lines.next().unwrap();
@@ -297,6 +296,10 @@ impl Writer<'_> {
beginning.is_empty()
}
pub fn is_empty_children(&self, children: &[BodyNode]) -> bool {
children.is_empty()
}
// check if the children are short enough to be on the same line
// We don't have the notion of current line depth - each line tries to be < 80 total
// returns the total line length if it's short
+5 -5
View File
@@ -8,11 +8,11 @@ pub enum IndentType {
pub struct IndentOptions {
width: usize,
indent_string: String,
inline_attributes: bool,
split_line_attributes: bool,
}
impl IndentOptions {
pub fn new(typ: IndentType, width: usize, inline_attributes: bool) -> Self {
pub fn new(typ: IndentType, width: usize, split_line_attributes: bool) -> Self {
assert_ne!(width, 0, "Cannot have an indent width of 0");
Self {
width,
@@ -20,7 +20,7 @@ impl IndentOptions {
IndentType::Tabs => "\t".into(),
IndentType::Spaces => " ".repeat(width),
},
inline_attributes,
split_line_attributes,
}
}
@@ -65,8 +65,8 @@ impl IndentOptions {
indent
}
pub fn inline_attributes(&self) -> bool {
self.inline_attributes
pub fn split_line_attributes(&self) -> bool {
self.split_line_attributes
}
}
+3 -1
View File
@@ -140,7 +140,9 @@ pub fn write_block_out(body: CallBody) -> Option<String> {
}
fn write_body(buf: &mut Writer, body: &CallBody) {
if buf.is_short_children(&body.roots).is_some() && !buf.out.indent.inline_attributes() {
let is_short = buf.is_short_children(&body.roots).is_some();
let is_empty = buf.is_empty_children(&body.roots);
if (is_short && !buf.out.indent.split_line_attributes()) || is_empty {
// write all the indents with spaces and commas between
for idx in 0..body.roots.len() - 1 {
let ident = &body.roots[idx];