public void HilightWord() { Gtk.TextIter prevEndCharIter = new Gtk.TextIter(); //Gtk.TextIter nextCharIter = new Gtk.TextIter (); if (!(endHilightIter.Equal(Gtk.TextIter.Zero))) { textBuffer.RemoveTag("hilight", startHilightIter, endHilightIter); } startHilightIter = startWordIter; endHilightIter = endWordIter; prevEndCharIter = endWordIter; prevEndCharIter.BackwardChar(); while (Regex.IsMatch(startHilightIter.Char, @"[\s-]", RegexOptions.None)) { startHilightIter.ForwardChar(); } while (Regex.IsMatch(prevEndCharIter.Char, @"\s", RegexOptions.None) && Regex.IsMatch(endHilightIter.Char, @"\S", RegexOptions.None)) { endHilightIter.BackwardChar(); prevEndCharIter.BackwardChar(); } textBuffer.ApplyTag(tag, startHilightIter, endHilightIter); textView.ScrollToIter(endWordIter, 0, false, 0, 0); if (!running) { statusBar.Push(0, "Stopped at position " + startWordIter.Offset); } }
public void PreviousWord(object o, EventArgs args) { if (startWordIter.Equal(Gtk.TextIter.Zero)) { startWordIter = textBuffer.StartIter; } endWordIter = startWordIter; while (startWordIter.BackwardChar() && !startWordIter.StartsWord()) { } curWord = startWordIter.GetText(endWordIter); curWord = Regex.Replace(curWord, @"--", "", RegexOptions.Multiline); curWord = curWord.TrimStart(new char[5] { ' ', '\n', '\t', '\r', '-' }); curWord = curWord.TrimEnd(new char[5] { ' ', '\n', '\t', '\r', '-' }); curWord = Regex.Replace(curWord, @"\s+", " ", RegexOptions.Multiline); //Console.WriteLine("Word: \"" + curWord +"\""); ShowWord(curWord); HilightWord(); slideLock = true; slider.Value = endWordIter.Offset; slideLock = false; }
public string GetNextWord() { Gtk.TextIter prevCharIter = new Gtk.TextIter(); Gtk.TextIter nextCharIter = new Gtk.TextIter(); Gtk.TextIter prevWordEndIter = new Gtk.TextIter(); string text; string word; bool bail = false; endPara = false; wao = 1; startWordIter = endWordIter; // Need to trap last word see gnomeRSVP if (!endWordIter.ForwardWordEnd()) { StopRsvp(null, null); } do { prevCharIter = endWordIter; prevCharIter.BackwardChar(); nextCharIter = endWordIter; nextCharIter.ForwardChar(); if (Regex.IsMatch(endWordIter.Char, @"^\S$", RegexOptions.None) && Regex.IsMatch(prevCharIter.Char, @"^\s$", RegexOptions.None)) { text = startWordIter.GetText(endWordIter); text = Regex.Replace(text, @"--", "", RegexOptions.Multiline); text = text.TrimStart(new char[4] { ' ', '\n', '\t', '-' }); text = Regex.Replace(text, @"\s+", " ", RegexOptions.Multiline); if (text.Length <= config.WordGroupSize) { if (endWordIter.InsideSentence()) { prevWordEndIter = prevCharIter; wao++; } } else { bail = true; nextCharIter.BackwardChar(); } } else if (endWordIter.EndsSentence()) { bail = true; do { } while (endWordIter.EndsSentence() && endWordIter.ForwardChar()); nextCharIter.BackwardChar(); if (!endWordIter.IsEnd) { if (nextCharIter.Char == "\n") { endPara = true; } } } endWordIter = nextCharIter; } while (!bail && !endWordIter.IsEnd); word = startWordIter.GetText(endWordIter); word = Regex.Replace(word, @"--", "", RegexOptions.Multiline); word = word.TrimStart(new char[4] { ' ', '\n', '\t', '-' }); word = Regex.Replace(word, @"\s+$", "", RegexOptions.Multiline); word = Regex.Replace(word, @"\s+", " ", RegexOptions.Multiline); if (word.Length > config.WordGroupSize && !prevWordEndIter.Equal(Gtk.TextIter.Zero)) { wao--; endWordIter = prevWordEndIter; } word = startWordIter.GetText(endWordIter); word = Regex.Replace(word, @"--", "", RegexOptions.Multiline); word = word.TrimStart(new char[4] { ' ', '\n', '\t', '-' }); word = Regex.Replace(word, @"\s+$", "", RegexOptions.Multiline); word = Regex.Replace(word, @"\s+", " ", RegexOptions.Multiline); if (endWordIter.IsEnd) { StopRsvp(null, null); } return(word); }