Esempio n. 1
0
        public static bool ReplaceSelection(this Gtk.TextBuffer buffer, string newText, bool keepSelection = true)
        {
            bool     retval = false;
            TextIter start;
            TextIter end;

            if (buffer.GetSelectionBounds(out start, out end))
            {
                TextMark startMark = buffer.CreateMark("start", start, false);
                TextMark endMark   = buffer.CreateMark("end", end, true);

                buffer.DeleteSelection(true, true);

                TextIter start2 = buffer.GetIterAtMark(startMark);
                buffer.Insert(ref start2, newText);

                if (keepSelection)
                {
                    TextIter start3 = buffer.GetIterAtMark(startMark);
                    TextIter end3   = buffer.GetIterAtMark(endMark);

                    buffer.SelectRange(start3, end3);
                }
                retval = true;
            }
            return(retval);
        }