void DoHighlight(TrieHit hit, Gtk.TextIter start, Gtk.TextIter end) { // Some of these checks should be replaced with fixes to // TitleTrie.FindMatches, probably. if (hit.Value == null) { Logger.Debug("DoHighlight: null pointer error for '{0}'.", hit.Key); return; } if (Manager.Find(hit.Key) == null) { Logger.Debug("DoHighlight: '{0}' links to non-existing note.", hit.Key); return; } Note hit_note = (Note)hit.Value; if (String.Compare(hit.Key.ToString(), hit_note.Title.ToString(), true) != 0) // == 0 if same string { Logger.Debug("DoHighlight: '{0}' links wrongly to note '{1}'.", hit.Key, hit_note.Title); return; } if (hit_note == this.Note) { return; } Gtk.TextIter title_start = start; title_start.ForwardChars(hit.Start); Gtk.TextIter title_end = start; title_end.ForwardChars(hit.End); // Only link against whole words/phrases if ((!title_start.StartsWord() && !title_start.StartsSentence()) || (!title_end.EndsWord() && !title_end.EndsSentence())) { return; } // Don't create links inside URLs if (Note.TagTable.HasLinkTag(title_start)) { return; } Logger.Debug("Matching Note title '{0}' at {1}-{2}...", hit.Key, hit.Start, hit.End); Buffer.RemoveTag(Note.TagTable.BrokenLinkTag, title_start, title_end); Buffer.ApplyTag(Note.TagTable.LinkTag, title_start, title_end); }
void TagApplied(object sender, Gtk.TagAppliedArgs args) { bool remove = false; if (args.Tag.Name == "gtkspell-misspelled") { // Remove misspelled tag for links & title foreach (Gtk.TextTag tag in args.StartChar.Tags) { if (tag != args.Tag && !NoteTagTable.TagIsSpellCheckable(tag)) { remove = true; break; } } // Remove misspelled tag for acronyms (in all caps) if (!args.StartChar.EndsWord() && System.Char.IsUpper(args.StartChar.Char, 0)) { Gtk.TextIter char_iter = args.StartChar; remove = true; while (!char_iter.EndsWord()) { if (Char.IsLower(char_iter.Char, 0)) { remove = false; break; } else { char_iter.ForwardChar(); } } } } else if (!NoteTagTable.TagIsSpellCheckable(args.Tag)) { remove = true; } if (remove) { Buffer.RemoveTag("gtkspell-misspelled", args.StartChar, args.EndChar); } }