From e43edee9bb8b2252e110a9388a3f0607b2e4ee86 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 29 Nov 2015 03:19:51 +0000 Subject: [PATCH] call highlighted search terms highlights, and uphold them if provided by synapse --- src/controllers/organisms/RoomView.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/controllers/organisms/RoomView.js b/src/controllers/organisms/RoomView.js index 1fe7bd08..e5fe6ce2 100644 --- a/src/controllers/organisms/RoomView.js +++ b/src/controllers/organisms/RoomView.js @@ -451,8 +451,26 @@ module.exports = { } } }).then(function(data) { + // for debugging: + // data.search_categories.room_events.highlights = ["hello", "everybody"]; + + var highlights; + if (data.search_categories.room_events.highlights && + data.search_categories.room_events.highlights.length > 0) + { + // postgres on synapse returns us precise details of the + // strings which actually got matched for highlighting. + // for overlapping highlights, favour longer (more specific) terms first + highlights = data.search_categories.room_events.highlights + .sort(function(a, b) { b.length - a.length }); + } + else { + // sqlite doesn't, so just highlight the literal search term + highlights = [ term ]; + } + self.setState({ - searchTerm: term, + highlights: highlights, searchResults: data, }); }, function(error) { @@ -490,7 +508,7 @@ module.exports = { } } if (EventTile.haveTileForEvent(mxEv)) { - ret.push(
  • ); + ret.push(
  • ); } if (resultList[i].context.events_after[0]) { var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_after[0]); @@ -530,7 +548,7 @@ module.exports = { var ts0 = this.state.room.timeline[i - 1].getTs(); var ts1 = this.state.room.timeline[i].getTs(); if (new Date(ts0).toDateString() !== new Date(ts1).toDateString()) { - dateSeparator = ; + dateSeparator =
  • ; continuation = false; } }