int32_t FindBar::find_next_match(const Gtk::TextIter& start) { if(matches_.empty()) { return -1; } int i = 0; for(auto match: matches_) { if(match.first.get_offset() > start.get_offset()) { return i; } ++i; } //If we got here then there were no matches after the cursor, so just return the first one out //of all of them return 0; }
void FindBar::replace_text(Gtk::TextIter& start, Gtk::TextIter& end, Glib::ustring& replacement) { auto buf = window_.current_buffer()->buffer(); if(buf->get_slice(start, end) == replacement) { return; } //Store the offset to the start of the selection set to be replaced auto offset = start.get_offset(); //Erase the selection buf->erase(start, end); //Build a new iterator from the stored offset, and insert the text there auto new_start = buf->get_iter_at_offset(offset); buf->insert(new_start, replacement); }
void FindBar::locate_matches(const unicode& string) { matches_.clear(); last_selected_match_ = -1; auto buf = window_.current_buffer()->buffer(); auto start = buf->begin(); Gtk::TextIter end; bool case_sensitive = case_sensitive_->get_active(); while(start.forward_search( string.encode(), (case_sensitive) ? Gtk::TextSearchFlags(0) : Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end)) { matches_.push_back(std::make_pair(start, end)); start = buf->get_iter_at_offset(end.get_offset()); } }