diff --git a/kdevplatform/language/interfaces/abbreviations.cpp b/kdevplatform/language/interfaces/abbreviations.cpp --- a/kdevplatform/language/interfaces/abbreviations.cpp +++ b/kdevplatform/language/interfaces/abbreviations.cpp @@ -222,7 +222,8 @@ } else if (lastMatchIndex == 0) { return StartMatch; } else { - return OtherMatch; + // prefer matches closer to the end of the path + return OtherMatch + segments.size() - pathIndex; } } diff --git a/plugins/quickopen/tests/test_quickopen.cpp b/plugins/quickopen/tests/test_quickopen.cpp --- a/plugins/quickopen/tests/test_quickopen.cpp +++ b/plugins/quickopen/tests/test_quickopen.cpp @@ -233,6 +233,20 @@ QStringLiteral("/bar/FOOxBAR.h") }); } + { + const StringList a = { + QStringLiteral("/home/user/src/code/user/something"), + QStringLiteral("/home/user/src/code/home/else"), + }; + const StringList b = { + QStringLiteral("/home/user/src/code/home/else"), + QStringLiteral("/home/user/src/code/user/something"), + }; + QTest::newRow("prefer_multimatch_a_home") << a << QStringLiteral("home") << b; + QTest::newRow("prefer_multimatch_b_home") << b << QStringLiteral("home") << b; + QTest::newRow("prefer_multimatch_a_user") << a << QStringLiteral("user") << a; + QTest::newRow("prefer_multimatch_b_user") << b << QStringLiteral("user") << a; + } } void TestQuickOpen::testProjectFileFilter()