diff --git a/CodeCompletion/CodeFormatter.cs b/CodeCompletion/CodeFormatter.cs index e235176da..615285f27 100644 --- a/CodeCompletion/CodeFormatter.cs +++ b/CodeCompletion/CodeFormatter.cs @@ -3387,6 +3387,23 @@ namespace CodeFormatters visit_node(diap.left); visit_node(diap.right); } + + public override void visit(if_expr_new _if_expr_new) + { + sb.Append("if"); //sb.Append(" "); + SetKeywordOffset("if"); + read_from_beg_pos = true; + visit_node(_if_expr_new.condition); + if (!in_one_row(_if_expr_new.condition)) + add_newline_after = true; + add_space_before = true; + visit_node(_if_expr_new.if_true); + if (_if_expr_new.if_false != null) + { + add_space_before = true; + visit_node(_if_expr_new.if_false); + } + } #endregion } } \ No newline at end of file diff --git a/TestSuite/formatter_tests/input/ifexpr1.pas b/TestSuite/formatter_tests/input/ifexpr1.pas new file mode 100644 index 000000000..2967b744f --- /dev/null +++ b/TestSuite/formatter_tests/input/ifexpr1.pas @@ -0,0 +1,3 @@ +begin +var b:=if i<2 then (2+4)*4 else 3+5; +end. \ No newline at end of file diff --git a/TestSuite/formatter_tests/input/ifexpr2.pas b/TestSuite/formatter_tests/input/ifexpr2.pas new file mode 100644 index 000000000..23b1b2994 --- /dev/null +++ b/TestSuite/formatter_tests/input/ifexpr2.pas @@ -0,0 +1,3 @@ +begin + var b := if a<2 then 2+3 else if a>3 then 2+5 else 3+4; +end. \ No newline at end of file diff --git a/TestSuite/formatter_tests/should/ifexpr1.pas b/TestSuite/formatter_tests/should/ifexpr1.pas new file mode 100644 index 000000000..0cd8a42be --- /dev/null +++ b/TestSuite/formatter_tests/should/ifexpr1.pas @@ -0,0 +1,3 @@ +begin + var b := if i < 2 then (2 + 4) * 4 else 3 + 5; +end. \ No newline at end of file diff --git a/TestSuite/formatter_tests/should/ifexpr2.pas b/TestSuite/formatter_tests/should/ifexpr2.pas new file mode 100644 index 000000000..86e6ad4aa --- /dev/null +++ b/TestSuite/formatter_tests/should/ifexpr2.pas @@ -0,0 +1,3 @@ +begin + var b := if a < 2 then 2 + 3 else if a > 3 then 2 + 5 else 3 + 4; +end. \ No newline at end of file