Petr
Petr

Reputation: 14505

How to retrieve a selected text of Gtk TextView

I have a GTK TextView and I need to put selected text into a string, how can I do that?

There is event SelectionGet, but it doesn't seem to work. (Never triggered)

Upvotes: 0

Views: 1062

Answers (1)

Petr
Petr

Reputation: 14505

public string Selection
{
   get
   {
       Gtk.TextIter A;
       Gtk.TextIter B;
       if (textView.Buffer.GetSelectionBounds(out A, out B))
       {
           return textView.Buffer.GetText(A, B, true);
       }
       // return null when there is no selection
       return null;
   }
}

Upvotes: 1

Related Questions