From ae37003852f8d1ff930bfc188b1e58822eb44c27 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 17 Jan 2013 12:32:11 -0500 Subject: [PATCH] prefer taginfo suggestions that startwith input --- js/id/ui/inspector.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index a1aed91ec..3af39c1b7 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -213,13 +213,26 @@ iD.ui.inspector = function() { key = row.selectAll('.key'), value = row.selectAll('.value'); + function sort(value, data) { + var sameletter = [], + other = []; + for (var i = 0; i < data.length; i++) { + if (data[i].value.substring(0, value.length) === value) { + sameletter.push(data[i]); + } else { + other.push(data[i]); + } + } + return sameletter.concat(other); + } + key.call(d3.typeahead() .data(_.debounce(function(_, callback) { taginfo.keys({ geometry: geometry, query: key.property('value') }, function(err, data) { - if (!err) callback(data); + if (!err) callback(sort(key.property('value'), data)); }); }, 500))); @@ -230,7 +243,7 @@ iD.ui.inspector = function() { geometry: geometry, query: value.property('value') }, function(err, data) { - if (!err) callback(data); + if (!err) callback(sort(value.property('value'), data)); }); }, 500))); }