diff --git a/src/source_base.cpp b/src/source_base.cpp index 0c152d4..40c1723 100644 --- a/src/source_base.cpp +++ b/src/source_base.cpp @@ -87,82 +87,85 @@ void Source::CommonView::search_forward() { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; -#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22)) +#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION > 24)) + gboolean has_wrapped_around; + if(gtk_source_search_context_forward(search_context, end.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { +#elif defined(GTK_SOURCE_MAJOR_VERSION) && GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22 && GTK_SOURCE_MINOR_VERSION <= 24 gboolean has_wrapped_around; if(gtk_source_search_context_forward2(search_context, end.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { - get_buffer()->select_range(match_start, match_end); - scroll_to(get_buffer()->get_insert()); - } #else if(gtk_source_search_context_forward(search_context, end.gobj(), match_start.gobj(), match_end.gobj())) { +#endif get_buffer()->select_range(match_start, match_end); scroll_to(get_buffer()->get_insert()); } -#endif } void Source::CommonView::search_backward() { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; -#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22)) +#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION > 24)) + gboolean has_wrapped_around; + if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { +#elif defined(GTK_SOURCE_MAJOR_VERSION) && GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22 && GTK_SOURCE_MINOR_VERSION <= 24 gboolean has_wrapped_around; if(gtk_source_search_context_backward2(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { - get_buffer()->select_range(match_start, match_end); - scroll_to(get_buffer()->get_insert()); - } #else if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { +#endif get_buffer()->select_range(match_start, match_end); scroll_to(get_buffer()->get_insert()); } -#endif } void Source::CommonView::replace_forward(const std::string &replacement) { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; -#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22)) +#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION > 24)) + gboolean has_wrapped_around; + if(gtk_source_search_context_forward(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { + auto offset = match_start.get_offset(); + gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); +#elif defined(GTK_SOURCE_MAJOR_VERSION) && GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22 && GTK_SOURCE_MINOR_VERSION <= 24 gboolean has_wrapped_around; if(gtk_source_search_context_forward2(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { auto offset = match_start.get_offset(); gtk_source_search_context_replace2(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); - Glib::ustring replacement_ustring = replacement; - get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset + replacement_ustring.size())); - scroll_to(get_buffer()->get_insert()); - } #else if(gtk_source_search_context_forward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { auto offset = match_start.get_offset(); gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); +#endif Glib::ustring replacement_ustring = replacement; get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset + replacement_ustring.size())); scroll_to(get_buffer()->get_insert()); } -#endif } void Source::CommonView::replace_backward(const std::string &replacement) { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; -#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22)) +#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION > 24)) + gboolean has_wrapped_around; + if(gtk_source_search_context_backward(search_context, end.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { + auto offset = match_start.get_offset(); + gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); +#elif defined(GTK_SOURCE_MAJOR_VERSION) && GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22 && GTK_SOURCE_MINOR_VERSION <= 24 gboolean has_wrapped_around; if(gtk_source_search_context_backward2(search_context, end.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) { auto offset = match_start.get_offset(); gtk_source_search_context_replace2(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); - get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset + replacement.size())); - scroll_to(get_buffer()->get_insert()); - } #else if(gtk_source_search_context_backward(search_context, end.gobj(), match_start.gobj(), match_end.gobj())) { auto offset = match_start.get_offset(); gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); +#endif get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset + replacement.size())); scroll_to(get_buffer()->get_insert()); } -#endif } void Source::CommonView::replace_all(const std::string &replacement) {