Skip to content

Commit ab2a4d1

Browse files
committed
feat: improve match goodness algorithm to show more useful hints
1 parent 9c39eea commit ab2a4d1

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,12 +893,37 @@ define(function (require, exports, module) {
893893

894894
// filter folders using fuzzy matching
895895
const matches = folderList
896-
.map(folder => stringMatcher.match(folder, query))
897-
.filter(result => result !== null && result !== undefined)
898-
.sort((a, b) => b.matchGoodness - a.matchGoodness)
899-
.slice(0, 5);
896+
.map(folder => {
897+
const result = stringMatcher.match(folder, query);
898+
if (result) {
899+
// get the last folder name (e.g., "assets/images/" -> "images")
900+
const folderPath = result.label || folder;
901+
const segments = folderPath.split('/').filter(s => s.length > 0);
902+
const lastSegment = segments[segments.length - 1] || '';
903+
result.folderName = lastSegment.toLowerCase();
904+
905+
// we need to boost the score significantly if the last folder segment starts with the query
906+
// This ensures folders like "images/" rank higher than "testing/maps/google/" when typing "image"
907+
// note: here testing/maps/google has all the chars of 'image'
908+
if (lastSegment.toLowerCase().startsWith(query.toLowerCase())) {
909+
// Use a large positive boost (matchGoodness is negative, so we subtract a large negative number)
910+
result.matchGoodness -= 10000;
911+
}
912+
// Also boost (but less) if the last segment contains the query as a substring
913+
else if (lastSegment.toLowerCase().includes(query.toLowerCase())) {
914+
result.matchGoodness -= 1000;
915+
}
916+
}
917+
return result;
918+
})
919+
.filter(result => result !== null && result !== undefined);
920+
921+
// Sort by matchGoodness first (prefix matches will have best scores),
922+
// then alphabetically by folder name, then by full path
923+
StringMatch.multiFieldSort(matches, { matchGoodness: 0, folderName: 1, label: 2 });
900924

901-
_renderFolderSuggestions(matches, $suggestions, $input);
925+
const topMatches = matches.slice(0, 5);
926+
_renderFolderSuggestions(topMatches, $suggestions, $input);
902927
}
903928

904929
/**

src/htmlContent/image-folder-dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h1 class="dialog-title">Select Folder to Save Image</h1>
1515
<div id="folder-suggestions"></div>
1616

1717
<p class="folder-help-text">
18-
💡 Tip: Type to filter folders or create a new path
18+
💡 Type folder path or leave empty to download in project root
1919
</p>
2020
</div>
2121
<div class="modal-footer">

0 commit comments

Comments
 (0)