Skip to content

Disregarding the trailing slash when sorting directory paths

Eduardo Cruz requested to merge ecruz/kio:fix_kurlcompletion_ordering into master

This MR is dependent on another MR in KCompletion, without it, this won't compile.

When completing directory paths, the framework is considering the trailing slash when sorting the suggested entries. The presence of the trailing slash actually affects the sorting order of the strings and generates improper behavior.

Say we have a folder named "folder" and another named "folder_BACKUP". When ordering the strings without the trailing slash, we get the order: 1- "folder" 2- "folder_BACKUP"

However if we order the strings "folder/" and "folder_BACKUP/" (with the trailing slash), we get the order: 1- "folder_BACKUP/" 2- "folder/"

This generates a bug where we type in an exact directory path to "folder" but we get a suggestion to "folder_BACKUP" and that's where we are taken when we press enter when using "Automatic" or "Dropdown List & Automatic" completion modes. See picture below:

before_after_sorting_bug

I investigated the code and found out that the sorting was being performed on the KCompletionMatchesWrapper::list() method. So my approach was to make an injection that reaches down there.

I have created the new member KCompletionPrivate::sorterFunction, a pointer to a custom sorter function. Classes deriving from KCompletion may inject its own sorting logic via the protected setter KCompletion::setSorterFunction(). With this new feature, KUrlCompletion is now providing it's own sorting function that disregards the trailing slash for directory paths and the bug is thus fixed.

BUG: 442717

Edited by Eduardo Cruz

Merge request reports