From 1f39fafdea8fdd3fbd84f48375901719ff3fc53d Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Mon, 28 Oct 2024 15:20:19 -0500 Subject: [PATCH] score `startsWith()` matches more highly (closes #50) --- R/init-addin.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/init-addin.R b/R/init-addin.R index 03f8227..ae382bb 100644 --- a/R/init-addin.R +++ b/R/init-addin.R @@ -50,7 +50,16 @@ create = FALSE, placeholder = 'Type to filter or select a pal', onDropdownOpen = I("function($dropdown) {this.clear();}"), - onBlur = I("function() {this.clear();}") + onBlur = I("function() {this.clear();}"), + score = I("function(search) { + return function(item) { + const text = (item.value || item.text || '').toLowerCase(); + const searchLower = search.toLowerCase(); + if (text.startsWith(searchLower)) return 1; + if (text.includes(searchLower)) return 0.5; + return 0; + }; + }") ) ), shiny::verbatimTextOutput("result"),