From 1a262fe68071f845297edec1e95052874d9a3f04 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 3 Oct 2020 22:00:34 +0200 Subject: [PATCH] attribute autocomplete should show prefix matches first and only after matches anywhere, #1284 --- src/services/attributes.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/attributes.js b/src/services/attributes.js index d839b58e7..d3e583fe2 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -109,7 +109,16 @@ function getAttributeNames(type, nameLike) { } } - names.sort(); + names.sort((a, b) => { + const aPrefix = a.toLowerCase().startsWith(nameLike); + const bPrefix = b.toLowerCase().startsWith(nameLike); + + if (aPrefix !== bPrefix) { + return aPrefix ? -1 : 1; + } + + return a < b ? -1 : 1; + }); return names; }