mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 06:08:26 +00:00
fix: autofmt on single line rsx calls
This commit is contained in:
parent
2b9888627b
commit
3d47cb48fa
5 changed files with 23 additions and 13 deletions
|
@ -47,7 +47,7 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let indent_level = {
|
let mut indent_level = {
|
||||||
// walk backwards from start until we find a new line
|
// walk backwards from start until we find a new line
|
||||||
let mut lines = contents[..start].lines().rev();
|
let mut lines = contents[..start].lines().rev();
|
||||||
match lines.next() {
|
match lines.next() {
|
||||||
|
@ -71,6 +71,10 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
|
||||||
|
|
||||||
if new.len() <= 80 && !new.contains('\n') {
|
if new.len() <= 80 && !new.contains('\n') {
|
||||||
new = format!(" {new} ");
|
new = format!(" {new} ");
|
||||||
|
|
||||||
|
// if the new string is not multiline, don't try to adjust the marker ending
|
||||||
|
// We want to trim off any indentation that there might be
|
||||||
|
indent_level = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let end_marker = end + bracket_end - indent_level * 4 - 1;
|
let end_marker = end + bracket_end - indent_level * 4 - 1;
|
||||||
|
|
|
@ -12,3 +12,5 @@ macro_rules! twoway {
|
||||||
}
|
}
|
||||||
|
|
||||||
twoway!("comments" => comments);
|
twoway!("comments" => comments);
|
||||||
|
|
||||||
|
twoway!("multi" => multi);
|
||||||
|
|
3
packages/autofmt/tests/wrong/multi.rsx
Normal file
3
packages/autofmt/tests/wrong/multi.rsx
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn app(cx: Scope) -> Element {
|
||||||
|
cx.render(rsx! { div { "hello world" } })
|
||||||
|
}
|
5
packages/autofmt/tests/wrong/multi.wrong.rsx
Normal file
5
packages/autofmt/tests/wrong/multi.wrong.rsx
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn app(cx: Scope) -> Element {
|
||||||
|
cx.render(rsx! {
|
||||||
|
div {"hello world" }
|
||||||
|
})
|
||||||
|
}
|
|
@ -30,15 +30,11 @@ fn app(cx: Scope) -> Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Home(cx: Scope) -> Element {
|
fn Home(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! { h1 { "Home" } })
|
||||||
h1 { "Home" }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn BlogList(cx: Scope) -> Element {
|
fn BlogList(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! { div { "Blog List" } })
|
||||||
div { "Blog List" }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn BlogPost(cx: Scope) -> Element {
|
fn BlogPost(cx: Scope) -> Element {
|
||||||
|
|
Loading…
Add table
Reference in a new issue