From 4546160a6578c11f3a8bc5f56b98dba0de43eef6 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Sun, 28 Oct 2012 12:18:24 +0100 Subject: [PATCH] Fix highlighting in search suggestions The provided suggestions should highlight the part that the user has already typed as bold text. Currently this only works for the first operator. For suggestions of any further operator no hightlighting is done. Change-Id: I0764d412c2fb7913d53b359409d32c208837c6e3 Signed-off-by: Edwin Kempin --- .../gerrit/client/SearchSuggestOracle.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchSuggestOracle.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchSuggestOracle.java index 172a2af901..f84bb4d791 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchSuggestOracle.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchSuggestOracle.java @@ -93,17 +93,12 @@ public class SearchSuggestOracle extends HighlightSuggestOracle { @Override protected void onRequestSuggestions(Request request, Callback done) { final String query = request.getQuery(); - int lastSpace = query.lastIndexOf(' '); - final String lastWord; - // NOTE: this method is not called if the query is empty. - if (lastSpace == query.length() - 1) { + + final String lastWord = getLastWord(query); + if (lastWord == null) { // Starting a new word - don't show suggestions yet. done.onSuggestionsReady(request, null); return; - } else if (lastSpace == -1) { - lastWord = query; - } else { - lastWord = query.substring(lastSpace + 1); } final ArrayList r = new ArrayList(); @@ -118,6 +113,22 @@ public class SearchSuggestOracle extends HighlightSuggestOracle { done.onSuggestionsReady(request, new Response(r)); } + private String getLastWord(final String query) { + final int lastSpace = query.lastIndexOf(' '); + if (lastSpace == query.length() - 1) { + return null; + } + if (lastSpace == -1) { + return query; + } + return query.substring(lastSpace + 1); + } + + @Override + protected String getQueryPattern(final String query) { + return super.getQueryPattern(getLastWord(query)); + } + private static class SearchSuggestion implements SuggestOracle.Suggestion { private final String suggestion; private final String fullQuery;