Skip to content

Commit

Permalink
fixed regression link dismiss no longer working after improved clear …
Browse files Browse the repository at this point in the history
…formatting to retain the links (#2389)
  • Loading branch information
giuspen committed Jan 6, 2025
1 parent 798bd52 commit 85fce26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/ct/ct_actions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_actions.h
*
* Copyright 2009-2024
* Copyright 2009-2025
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -325,7 +325,7 @@ class CtActions
// format actions
void save_tags_at_cursor_as_latest();
void apply_tags_latest();
void remove_text_formatting();
void remove_text_formatting() { _remove_text_formatting(false/*dismiss_link*/); }
void apply_tag_foreground();
void apply_tag_background();
void apply_tag_bold();
Expand Down Expand Up @@ -363,6 +363,7 @@ class CtActions
void _text_selection_change_case(gchar change_type);
int _find_previous_indent_margin();
void _apply_tag_hN(const char* tagPropScaleVal);
void _remove_text_formatting(const bool dismiss_link);

public:
void image_insert_png(Gtk::TextIter iter_insert,
Expand Down
27 changes: 15 additions & 12 deletions src/ct/ct_actions_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void CtActions::apply_tags_latest()
}

// Cleans the Selected Text from All Formatting Tags
void CtActions::remove_text_formatting()
void CtActions::_remove_text_formatting(const bool dismiss_link)
{
if (not _is_there_selected_node_or_error()) return;
if (not _is_curr_node_not_syntax_highlighting_or_error()) return;
Expand All @@ -112,17 +112,20 @@ void CtActions::remove_text_formatting()
std::vector<Glib::RefPtr<Gtk::TextTag>> curr_tags = it_sel_start.get_tags();
for (auto& curr_tag : curr_tags) {
const Glib::ustring tag_name = curr_tag->property_name();
if (str::startswith(tag_name, "weight_") or
str::startswith(tag_name, "foreground_") or
str::startswith(tag_name, "background_") or
str::startswith(tag_name, "style_") or
str::startswith(tag_name, "underline_") or
str::startswith(tag_name, "strikethrough_") or
str::startswith(tag_name, "indent_") or
str::startswith(tag_name, "scale_") or
str::startswith(tag_name, "invisible_") or
str::startswith(tag_name, "justification_") or
str::startswith(tag_name, "family_"))
if ( (not dismiss_link and
(str::startswith(tag_name, "weight_") or
str::startswith(tag_name, "foreground_") or
str::startswith(tag_name, "background_") or
str::startswith(tag_name, "style_") or
str::startswith(tag_name, "underline_") or
str::startswith(tag_name, "strikethrough_") or
str::startswith(tag_name, "indent_") or
str::startswith(tag_name, "scale_") or
str::startswith(tag_name, "invisible_") or
str::startswith(tag_name, "justification_") or
str::startswith(tag_name, "family_")))
or
(dismiss_link and str::startswith(tag_name, "link_")) )
{
Gtk::TextIter it_sel_end = curr_buffer->get_iter_at_offset(offset+1);
curr_buffer->remove_tag(curr_tag, it_sel_start, it_sel_end);
Expand Down
4 changes: 2 additions & 2 deletions src/ct/ct_actions_others.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_actions_others.cc
*
* Copyright 2009-2024
* Copyright 2009-2025
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -68,7 +68,7 @@ void CtActions::link_dismiss()
if (not _is_curr_node_not_read_only_or_error()) return;
_link_right_click_pre_action();
if (not _link_check_around_cursor().empty()) {
remove_text_formatting();
_remove_text_formatting(true/*dismiss_link*/);
}
}

Expand Down

0 comments on commit 85fce26

Please sign in to comment.