From 9095a45ba7d5280b63b89d338b9fc1911ebd72ac Mon Sep 17 00:00:00 2001 From: Fil Krynicki Date: Sat, 10 May 2014 17:05:15 -0400 Subject: [PATCH] Bug 1047 Fix Dialog links can no longer be highlighted if they appear in the middle of the word. This is achieved by confirming that the character before a match is not alphabetic, so that words following hyphens can still potentially match. --- apps/openmw/mwgui/dialogue.cpp | 3 ++- apps/openmw/mwgui/keywordsearch.hpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 6c43f47b4b..6ee329aa71 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -162,7 +162,8 @@ namespace MWGui { std::string::const_iterator i = text.begin (); KeywordSearchT::Match match; - while (i != text.end () && keywordSearch->search (i, text.end (), match)) + + while (i != text.end () && keywordSearch->search (i, text.end (), match, false)) { if (i != match.mBeg) addTopicLink (typesetter, 0, i - text.begin (), match.mBeg - text.begin ()); diff --git a/apps/openmw/mwgui/keywordsearch.hpp b/apps/openmw/mwgui/keywordsearch.hpp index a9fb6daaba..be118597cd 100644 --- a/apps/openmw/mwgui/keywordsearch.hpp +++ b/apps/openmw/mwgui/keywordsearch.hpp @@ -66,10 +66,19 @@ public: return false; } - bool search (Point beg, Point end, Match & match) + bool search (Point beg, Point end, Match & match, bool matchSubword = true) { + char prev = ' '; for (Point i = beg; i != end; ++i) { + // check if previous character marked start of new word + if (!matchSubword && isalpha(prev)) + { + prev = *i; + continue; + } + prev = *i; + // check first character typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (std::tolower (*i, mLocale));