@@ -3,7 +3,7 @@ import * as path from "path"
33import * as fs from "fs"
44import * as childProcess from "child_process"
55import * as readline from "readline"
6- import { Fzf } from "fzf"
6+ import { byLengthAsc , Fzf } from "fzf"
77import { getBinPath } from "../ripgrep"
88
99async function executeRipgrepForFiles (
@@ -123,22 +123,16 @@ export async function searchWorkspaceFiles(
123123 // Run fzf search on all items
124124 const fzf = new Fzf ( searchItems , {
125125 selector : ( item ) => item . searchStr ,
126+ tiebreakers : [ byLengthAsc ] ,
127+ limit : limit ,
126128 } )
127129
128130 // Get all matching results from fzf
129- const fzfResults = fzf . find ( query )
130-
131- // First, sort all results by path length (shortest first)
132- fzfResults . sort ( ( a , b ) => {
133- return a . item . original . path . length - b . item . original . path . length
134- } )
135-
136- // Take the top N (limit) shortest results
137- const shortestResults = fzfResults . slice ( 0 , limit ) . map ( ( result ) => result . item . original )
131+ const fzfResults = fzf . find ( query ) . map ( ( result ) => result . item . original )
138132
139133 // Verify types of the shortest results
140134 const verifiedResults = await Promise . all (
141- shortestResults . map ( async ( result ) => {
135+ fzfResults . map ( async ( result ) => {
142136 const fullPath = path . join ( workspacePath , result . path )
143137 // Verify if the path exists and is actually a directory
144138 if ( fs . existsSync ( fullPath ) ) {
@@ -153,17 +147,6 @@ export async function searchWorkspaceFiles(
153147 } ) ,
154148 )
155149
156- // Final sort to put directories first within the shortest results
157- verifiedResults . sort ( ( a , b ) => {
158- if ( a . type === "folder" && b . type !== "folder" ) {
159- return - 1
160- }
161- if ( a . type !== "folder" && b . type === "folder" ) {
162- return 1
163- }
164- return 0 // Keep original sorting by path length
165- } )
166-
167150 return verifiedResults
168151 } catch ( error ) {
169152 console . error ( "Error in searchWorkspaceFiles:" , error )
0 commit comments