Skip to content

Commit

Permalink
fixed single click on line number to select line, double click for pa…
Browse files Browse the repository at this point in the history
…rgraph (#1363)
  • Loading branch information
giuspen committed Sep 23, 2023
1 parent 1567b69 commit db930b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ct/ct_main_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class CtMainWin : public Gtk::ApplicationWindow
void apply_scalable_properties(Glib::RefPtr<Gtk::TextTag> rTextTag, CtScalableTag* pCtScalableTag);
Glib::ustring sourceview_hovering_link_get_tooltip(const Glib::ustring& link);
bool apply_tag_try_automatic_bounds(Glib::RefPtr<Gtk::TextBuffer> text_buffer, Gtk::TextIter iter_start);
void apply_tag_try_automatic_bounds_triple_click(Glib::RefPtr<Gtk::TextBuffer> text_buffer, Gtk::TextIter iter_start);
void apply_tag_try_automatic_bounds_paragraph(Glib::RefPtr<Gtk::TextBuffer> text_buffer, Gtk::TextIter iter_start);

private:
Gtk::HBox& _init_status_bar();
Expand Down
4 changes: 2 additions & 2 deletions src/ct/ct_main_win_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ bool CtMainWin::apply_tag_try_automatic_bounds(Glib::RefPtr<Gtk::TextBuffer> tex
}

// Try to select the full paragraph
void CtMainWin::apply_tag_try_automatic_bounds_triple_click(Glib::RefPtr<Gtk::TextBuffer> text_buffer,
Gtk::TextIter iter_start)
void CtMainWin::apply_tag_try_automatic_bounds_paragraph(Glib::RefPtr<Gtk::TextBuffer> text_buffer,
Gtk::TextIter iter_start)
{
Gtk::TextIter iter_end = iter_start;
iter_end.forward_to_line_end();
Expand Down
6 changes: 1 addition & 5 deletions src/ct/ct_main_win_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,7 @@ void CtMainWin::_on_textview_event_after(GdkEvent* event)
_ctTextview.for_event_after_double_click_button1(event);
}
if (event->type == GDK_3BUTTON_PRESS and event->button.button == 1) {
if (curr_tree_iter().get_node_is_rich_text() and _pCtConfig->tripleClickParagraph) {
if (_ctTextview.get_todo_rotate_time() != event->button.time) {
_ctTextview.for_event_after_triple_click_button1(event);
}
}
_ctTextview.for_event_after_triple_click_button1(event);
}
else if (event->type == GDK_BUTTON_PRESS or event->type == GDK_KEY_PRESS) {
if (event->type == GDK_BUTTON_PRESS) {
Expand Down
28 changes: 21 additions & 7 deletions src/ct/ct_text_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,32 @@ void CtTextView::for_event_after_double_click_button1(GdkEvent* event)
window_to_buffer_coords(Gtk::TEXT_WINDOW_TEXT, (int)event->button.x, (int)event->button.y, x, y);
Gtk::TextIter iter_start;
get_iter_at_location(iter_start, x, y);
const auto pGutterLineNumbers = get_gutter(Gtk::TEXT_WINDOW_LEFT);
if (pGutterLineNumbers) {
const auto pGutterLNWindow = pGutterLineNumbers->get_window();
if (pGutterLNWindow and pGutterLNWindow->gobj() == event->button.window) {
// line number click
_pCtMainWin->apply_tag_try_automatic_bounds_paragraph(text_buffer, iter_start);
return;
}
}
_pCtMainWin->apply_tag_try_automatic_bounds(text_buffer, iter_start);
}

// Called after every Triple Click with button 1
void CtTextView::for_event_after_triple_click_button1(GdkEvent* event)
{
auto text_buffer = get_buffer();
int x, y;
window_to_buffer_coords(Gtk::TEXT_WINDOW_TEXT, (int)event->button.x, (int)event->button.y, x, y);
Gtk::TextIter iter_start;
get_iter_at_location(iter_start, x, y);
_pCtMainWin->apply_tag_try_automatic_bounds_triple_click(text_buffer, iter_start);
if (_pCtConfig->tripleClickParagraph and
_pCtMainWin->curr_tree_iter().get_node_is_rich_text() and
get_todo_rotate_time() != event->button.time)
{
auto text_buffer = get_buffer();
int x, y;
window_to_buffer_coords(Gtk::TEXT_WINDOW_TEXT, (int)event->button.x, (int)event->button.y, x, y);
Gtk::TextIter iter_start;
get_iter_at_location(iter_start, x, y);
_pCtMainWin->apply_tag_try_automatic_bounds_paragraph(text_buffer, iter_start);
}
}

#ifdef MD_AUTO_REPLACEMENT
Expand Down Expand Up @@ -304,7 +318,7 @@ void CtTextView::for_event_after_button_press(GdkEvent* event)
const auto pGutterLNWindow = pGutterLineNumbers->get_window();
if (pGutterLNWindow and pGutterLNWindow->gobj() == event->button.window) {
// line number click
_pCtMainWin->apply_tag_try_automatic_bounds_triple_click(text_buffer, text_iter);
_pCtMainWin->apply_tag_try_automatic_bounds(text_buffer, text_iter);
return;
}
}
Expand Down

0 comments on commit db930b2

Please sign in to comment.