Skip to content

Commit

Permalink
score startsWith() matches more highly (closes #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Oct 28, 2024
1 parent 1ff0a82 commit 1f39faf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/init-addin.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 1f39faf

Please sign in to comment.