Browse Source

Minor cleanup of extend_selection()

merge-requests/404/merge
eidheim 5 years ago
parent
commit
31d86b22ba
  1. 31
      src/source.cpp

31
src/source.cpp

@ -1164,6 +1164,11 @@ void Source::View::extend_selection() {
Gtk::TextIter start, end; Gtk::TextIter start, end;
get_buffer()->get_selection_bounds(start, end); get_buffer()->get_selection_bounds(start, end);
// If entire buffer is selected, do nothing
if(start == get_buffer()->begin() && end == get_buffer()->end())
return;
auto start_stored = start; auto start_stored = start;
auto end_stored = end; auto end_stored = end;
@ -1566,11 +1571,6 @@ void Source::View::extend_selection() {
start = start_stored; start = start_stored;
end = end_stored; end = end_stored;
if(start == get_buffer()->begin() && end == get_buffer()->end()) {
get_buffer()->select_range(start, end);
return;
}
// Select following line with code (for instance when inside comment) // Select following line with code (for instance when inside comment)
// Forward start to non-empty line // Forward start to non-empty line
forward_to_code(start); forward_to_code(start);
@ -1780,28 +1780,29 @@ void Source::View::extend_selection() {
} }
} }
// Select sentence
end_sentence_iter.forward_char(); end_sentence_iter.forward_char();
if((end_sentence_iter != end_stored || start_sentence_iter != start_stored) && if((start_sentence_iter != start_stored || end_sentence_iter != end_stored) &&
((*start == '{' && *end == '}') || (start.is_start() && end.is_end()))) { ((*start == '{' && *end == '}') || (start.is_start() && end.is_end()))) {
start = start_sentence_iter; get_buffer()->select_range(start_sentence_iter, end_sentence_iter);
end = end_sentence_iter; return;
select_matching_brackets = false;
} }
} }
if(select_matching_brackets) if(select_matching_brackets)
start.forward_char(); start.forward_char();
if(start == start_stored && end == end_stored) { // In case of no change due to inbalanced brackets if(start != start_stored || end != end_stored) {
previous_extended_selections.pop_back();
if(!start.backward_char() && !end.forward_char())
return;
get_buffer()->select_range(start, end); get_buffer()->select_range(start, end);
extend_selection();
return; return;
} }
get_buffer()->select_range(start, end); // In case of no change due to inbalanced brackets
previous_extended_selections.pop_back();
if(!start.backward_char() && !end.forward_char())
return; return;
get_buffer()->select_range(start, end);
extend_selection();
} }
void Source::View::shrink_selection() { void Source::View::shrink_selection() {

Loading…
Cancel
Save