Browse Source

Fixes #438: improved detection and handling of closing curly bracket in special circumstances

pipelines/235045657
eidheim 5 years ago
parent
commit
19887dff27
  1. 10
      src/source.cpp
  2. 14
      tests/source_key_test.cpp

10
src/source.cpp

@ -2542,6 +2542,16 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey *event) {
}
}
}
/**
* Handle pressing enter after '{' in special expressions like:
* enum class A { a,
* b }
*/
else if(close_iter.get_line() > condition_iter.get_line() && close_iter.get_line_offset() > condition_iter.get_line_offset()) {
get_buffer()->insert_at_cursor('\n' + get_line_before(get_tabs_end_iter(condition_iter.get_line() + 1)));
scroll_to(get_buffer()->get_insert());
return true;
}
}
// Check if one should add semicolon after '}'

14
tests/source_key_test.cpp

@ -588,6 +588,20 @@ int main() {
g_assert(buffer->get_insert()->get_iter().get_line_offset() == 4);
}
{
buffer->set_text(" enum class A { a,\n"
" b };");
auto iter = buffer->begin();
iter.forward_chars(16);
buffer->place_cursor(iter);
view.on_key_press_event(&event);
g_assert(buffer->get_text() == " enum class A {\n"
" a,\n"
" b };");
g_assert(buffer->get_insert()->get_iter().get_line() == 1);
g_assert(buffer->get_insert()->get_iter().get_line_offset() == 17);
}
{
buffer->set_text(" else");
view.on_key_press_event(&event);

Loading…
Cancel
Save