@@ -753,20 +753,6 @@ textview_curses::handle_mouse(mouse_event& me)
753753 }
754754 }
755755 this ->tc_text_selection_active = false ;
756- if (this ->tc_press_line .is <main_content>()
757- && mouse_line.is <main_content>()
758- && me.is_click_in (mouse_button_t ::BUTTON_RIGHT , 0 , INT_MAX ))
759- {
760- auto * lov = this ->get_overlay_source ();
761- if (lov != nullptr
762- && (!lov->get_show_details_in_overlay ()
763- || this ->tc_selection_at_press
764- == this ->get_selection ()))
765- {
766- this ->set_show_details_in_overlay (
767- !lov->get_show_details_in_overlay ());
768- }
769- }
770756 if (this ->vc_enabled ) {
771757 if (this ->tc_selection_start ) {
772758 this ->toggle_user_mark (&BM_USER ,
@@ -785,36 +771,55 @@ textview_curses::handle_mouse(mouse_event& me)
785771 auto cursor_sf = line_sf.sub_cell_range (
786772 mc.mc_line_range .lr_start + me.me_x ,
787773 mc.mc_line_range .lr_start + me.me_x );
788- auto link_iter = find_string_attr_containing (
789- al. get_attrs (), & VC_HYPERLINK , cursor_sf. sf_begin );
790- if (link_iter != al. get_attrs (). end ()) {
791- auto href = link_iter-> sa_value . get <std::string>( );
792- auto * ta = dynamic_cast <text_anchors*>( this -> tc_sub_source );
793-
794- if (me. me_button == mouse_button_t :: BUTTON_LEFT
795- && ta != nullptr && startswith (href, " # " )
796- && ! startswith (href, " #/frontmatter " ))
774+ auto consumed = false ;
775+ if ( this -> tc_on_click ) {
776+ consumed
777+ = this -> tc_on_click (* this , al, cursor_sf. sf_begin , me );
778+ }
779+ if (!consumed) {
780+ if (this -> tc_press_line . is <main_content>()
781+ && me. is_click_in (
782+ mouse_button_t :: BUTTON_RIGHT , 0 , INT_MAX ))
797783 {
798- auto row_opt = ta->row_for_anchor (href);
784+ auto * lov = this ->get_overlay_source ();
785+ if (lov != nullptr
786+ && (!lov->get_show_details_in_overlay ()
787+ || this ->tc_selection_at_press
788+ == this ->get_selection ()))
789+ {
790+ this ->set_show_details_in_overlay (
791+ !lov->get_show_details_in_overlay ());
792+ }
793+ }
794+ auto link_iter = find_string_attr_containing (
795+ al.get_attrs (), &VC_HYPERLINK , cursor_sf.sf_begin );
796+ if (link_iter != al.get_attrs ().end ()) {
797+ auto href = link_iter->sa_value .get <std::string>();
798+ auto * ta
799+ = dynamic_cast <text_anchors*>(this ->tc_sub_source );
800+
801+ if (me.me_button == mouse_button_t ::BUTTON_LEFT
802+ && ta != nullptr && startswith (href, " #" )
803+ && !startswith (href, " #/frontmatter" ))
804+ {
805+ auto row_opt = ta->row_for_anchor (href);
799806
800- if (row_opt.has_value ()) {
801- this ->set_selection (row_opt.value ());
807+ if (row_opt.has_value ()) {
808+ this ->set_selection (row_opt.value ());
809+ }
810+ } else {
811+ this ->tc_selected_text = selected_text_info{
812+ me.me_x ,
813+ mc.mc_line ,
814+ link_iter->sa_range ,
815+ al.get_attrs (),
816+ al.to_string_fragment (link_iter).to_string (),
817+ href,
818+ };
819+ this ->set_needs_update ();
802820 }
803- } else {
804- this ->tc_selected_text = selected_text_info{
805- me.me_x ,
806- mc.mc_line ,
807- link_iter->sa_range ,
808- al.get_attrs (),
809- al.to_string_fragment (link_iter).to_string (),
810- href,
811- };
812- this ->set_needs_update ();
813821 }
814822 }
815- if (this ->tc_on_click ) {
816- this ->tc_on_click (*this , al, cursor_sf.sf_begin , me);
817- }
818823 }
819824 if (mouse_line.is <overlay_content>()) {
820825 const auto & oc = mouse_line.get <overlay_content>();
0 commit comments