From e94facd21316f3ab8830ae352232bfd9506dd1bb Mon Sep 17 00:00:00 2001 From: Giuseppe Penone Date: Mon, 3 Jun 2024 21:45:50 +0100 Subject: [PATCH] fixed right click -> copy link not working if there is a text selection (#2362) --- src/ct/ct_actions.h | 1 + src/ct/ct_actions_others.cc | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ct/ct_actions.h b/src/ct/ct_actions.h index c95d4c965..0d89c4488 100644 --- a/src/ct/ct_actions.h +++ b/src/ct/ct_actions.h @@ -417,6 +417,7 @@ class CtActions Gtk::TextIter* iter_bound); bool _on_embfiles_sentinel_timeout(); void _exec_code(const bool is_all); + void _link_right_click_pre_action(); public: // others actions diff --git a/src/ct/ct_actions_others.cc b/src/ct/ct_actions_others.cc index 2ce654d1f..a7c6746eb 100644 --- a/src/ct/ct_actions_others.cc +++ b/src/ct/ct_actions_others.cc @@ -38,17 +38,27 @@ #include #endif // HAVE_VTE +void CtActions::_link_right_click_pre_action() +{ + if (_curr_buffer()->get_has_selection() and _pCtMainWin->hovering_link_iter_offset() >= 0) { + Gtk::TextIter target_iter = _curr_buffer()->get_iter_at_offset(_pCtMainWin->hovering_link_iter_offset()); + if (target_iter) _curr_buffer()->place_cursor(target_iter); + } +} + void CtActions::link_cut() { if (not _is_curr_node_not_read_only_or_error()) return; - if (!_link_check_around_cursor().empty()) { + _link_right_click_pre_action(); + if (not _link_check_around_cursor().empty()) { g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard"); } } void CtActions::link_copy() { - if (!_link_check_around_cursor().empty()) { + _link_right_click_pre_action(); + if (not _link_check_around_cursor().empty()) { g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard"); } } @@ -56,7 +66,8 @@ void CtActions::link_copy() void CtActions::link_dismiss() { if (not _is_curr_node_not_read_only_or_error()) return; - if (!_link_check_around_cursor().empty()) { + _link_right_click_pre_action(); + if (not _link_check_around_cursor().empty()) { remove_text_formatting(); } } @@ -64,7 +75,8 @@ void CtActions::link_dismiss() void CtActions::link_delete() { if (not _is_curr_node_not_read_only_or_error()) return; - if (!_link_check_around_cursor().empty()) { + _link_right_click_pre_action(); + if (not _link_check_around_cursor().empty()) { _curr_buffer()->erase_selection(true, _pCtMainWin->get_text_view().get_editable()); _pCtMainWin->get_text_view().grab_focus(); }