Have a look at the Gtk::TextView::scroll_to ( ... ) functions.


On 01/23/2017 06:28 AM, Bill William wrote:
I was trying to implement a Search bar for Gtk::TextView inside of Gtk::ScrollableWindow. Basically the code uses a text iterator to search forward in the code for a given text string. Example:


void TextEditor::SearchClicked(int direction) {
  static Glib::ustring lastsearch {""};
  static Gtk::TextIter it = textbuff->begin();

  Glib::ustring searchtext = searchbar.entry.get_text();
  if (lastsearch != searchtext) {
    it = textbuff->begin();
  }
  lastsearch = searchtext;

  cout << "clicked! " << direction << "\n";

  Gtk::TextIter it_match_begin;
  Gtk::TextIter it_match_end;

  bool found = false;
  if (!direction) {
    found = it.forward_search(searchtext,
Gtk::TextSearchFlags::TEXT_SEARCH_CASE_INSENSITIVE,
                    it_match_begin,
                    it_match_end);
  }
  else {
    found = it.backward_search(searchtext,
Gtk::TextSearchFlags::TEXT_SEARCH_CASE_INSENSITIVE,
                    it_match_begin,
                    it_match_end);
  }
  if (found) {
    textbuff->select_range(it_match_begin, it_match_end);
    if (!direction) {
      it = it_match_end;
    } else {
      it = it_match_begin;
    }
  }
}


Which works ok, except when the iterator goes beyond the current scroller positions in the ScrolledWindow, then you need to manually scroll the window down to see the highlighted text. Any ideas on how to fix this code so that it autoscrolls when it goes beyond the scrolledwindows visable area?




_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

--
Saying what we think gives us a wider conversational range than saying what we know.
   — Cullen Hightower
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to