From 6c99fab3dde9ceb296281e342fbed9f8ec724eaa Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 5 Jan 2016 15:28:32 +0000 Subject: [PATCH] Highlight the search term in search results Sometimes we don't get the search term back in the highlights list, so make sure we add it. --- src/components/structures/RoomView.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 334fc02e18..b9bc2c76c9 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -544,17 +544,20 @@ module.exports = React.createClass({ return; } - // postgres on synapse returns us precise details of the - // strings which actually got matched for highlighting. + // postgres on synapse returns us precise details of the strings + // which actually got matched for highlighting. + // + // In either case, we want to highlight the literal search term + // whether it was used by the search engine or not. + + var highlights = results.highlights; + if (highlights.indexOf(self.state.searchTerm) < 0) { + highlights = highlights.concat(self.state.searchTerm); + } // For overlapping highlights, // favour longer (more specific) terms first - var highlights = results.highlights.sort(function(a, b) { b.length - a.length }); - - // sqlite doesn't give us any highlights, so just try to highlight the literal search term - if (highlights.length == 0) { - highlights = [ self.state.searchTerm ]; - } + highlights = highlights.sort(function(a, b) { b.length - a.length }); self.setState({ searchHighlights: highlights,