Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Closes #533: Preserve the casing of the original input when suggesting
Browse files Browse the repository at this point in the history
Save the original cased query to give it back as the keyword plus whatever is new.
  • Loading branch information
Mardak committed Jun 9, 2011
1 parent 752704f commit 5d0ed1a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions speakWords/bootstrap.js
Expand Up @@ -53,12 +53,15 @@ let sortedKeywords = [];
* Lookup a keyword to suggest for the provided query
*/
function getKeyword(query) {
// Remember the original query to preserve its original casing
let origQuery = query;

// Split the query into before and after the last space
let lastStart = query.lastIndexOf(" ") + 1;
let before = query.slice(0, lastStart);

// Suggest keywords for the last word of the query
query = query.slice(lastStart);
query = query.slice(lastStart).toLowerCase();

// Don't suggest a keyword for a blank query
if (query == "")
Expand All @@ -75,7 +78,7 @@ function getKeyword(query) {
for (let i = 0; i < sortedLen; i++) {
let keyword = keywords[i];
if (keyword.slice(0, queryLen) == query)
return before + keyword;
return origQuery + (before + keyword).slice(origQuery.length);
}
}

Expand Down Expand Up @@ -130,7 +133,7 @@ function addKeywordSuggestions(window) {
}

// See if we can suggest a keyword if it isn't the current query
let query = urlBar.textValue.toLowerCase();
let query = urlBar.textValue;
let keyword = getKeyword(query);
if (keyword == null || keyword == query)
return;
Expand Down

0 comments on commit 5d0ed1a

Please sign in to comment.