Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ package enum QuickSearchResult: Sendable {
let prefixActions = actions.filter(\.isPrefixMatch).map(Self.menuAction)
let otherActions = actions.filter { !$0.isExactMatch && !$0.isPrefixMatch }.map(Self.menuAction)

return exactFiles + exactActions + prefixFiles + prefixActions
+ headings.map(Self.heading) + content + recentFiles + bookmarkedFiles + otherActions
return headings.map(Self.heading) + content
+ exactFiles + exactActions + prefixFiles + prefixActions + recentFiles + bookmarkedFiles + otherActions
}
}
4 changes: 2 additions & 2 deletions MarkEditMac/Modules/Tests/QuickSearchMenuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ final class QuickSearchMenuTests: XCTestCase {

let fileID = "file:\(file.absoluteString)"
let cases: [(String, QuickSearchFilter, [String])] = [
("new tab", .all, [fileID, "menu:0.0", "menu:1.0", "menu:1.1", "heading:1", "line:2"]),
("new tab", .all, ["heading:1", "line:2", fileID, "menu:0.0", "menu:1.0", "menu:1.1"]),
("", .all, [fileID, "heading:1"]),
("", .menuActions, actions.map(\.id)),
("nwt", .menuActions, actions.map(\.id)),
Expand Down Expand Up @@ -215,7 +215,7 @@ final class QuickSearchMenuTests: XCTestCase {
menuActions: actions
)

XCTAssertEqual(results.map(\.id), ["menu:1.0", "menu:1.1", "line:1", "menu:0.0"])
XCTAssertEqual(results.map(\.id), ["line:1", "menu:1.0", "menu:1.1", "menu:0.0"])

let matches = try MenuActionSearchResult.search("help", actions: actions)
XCTAssertEqual(matches.map(\.isExactMatch), [true, false, false])
Expand Down
12 changes: 7 additions & 5 deletions MarkEditMac/Modules/Tests/QuickSearchResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import XCTest
@testable import QuickSearchCore

final class QuickSearchResultTests: XCTestCase {
func testAllPromotesDirectPrefixesWithoutPromotingMenuNamesOrWeakMatches() throws {
func testAllRanksHeadingsThenContentBeforeGlobalMatches() throws {
let recent = URL(filePath: "/Notes/Release Plan.md")
let exact = URL(filePath: "/Notes/Plan.md")
let prefix = URL(filePath: "/Archive/Planning.md")
Expand All @@ -32,9 +32,11 @@ final class QuickSearchResultTests: XCTestCase {
menuActions: actions
)

let expected = [
"file:\(exact.absoluteString)", "menu:0.0", "file:\(prefix.absoluteString)", "menu:0.1", "heading:101",
] + (1...100).map { "line:\($0)" } + ["file:\(recent.absoluteString)", "menu:2.0", "menu:1.0"]
let expected = ["heading:101"] + (1...100).map { "line:\($0)" } + [
"file:\(exact.absoluteString)", "menu:0.0", "file:\(prefix.absoluteString)", "menu:0.1",
"file:\(recent.absoluteString)", "menu:2.0", "menu:1.0",
]

XCTAssertEqual(results.map(\.id), expected)
XCTAssertEqual(Set(results.map(\.id)).count, results.count)
}
Expand Down Expand Up @@ -303,7 +305,7 @@ extension QuickSearchResultTests {

let cases: [(String, QuickSearchFilter, [String])] = [
("plan", .all, [
recentIDs[0], bookmarkIDs[1], "menu:0.0", bookmarkIDs[2], "heading:1", "line:2", recentIDs[1],
"heading:1", "line:2", recentIDs[0], bookmarkIDs[1], "menu:0.0", bookmarkIDs[2], recentIDs[1],
]),
("plan", .recents, recentIDs),
("plan", .bookmarks, bookmarkIDs),
Expand Down
7 changes: 3 additions & 4 deletions MarkEditMac/Modules/Tests/QuickSearchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ extension QuickSearchTests {
return try XCTUnwrap(cell.subviews.compactMap { $0 as? NSTextField }.first).stringValue
}

XCTAssertEqual(titles, ["Plan.md", "Release Plan", "Project Planning", "A plan for launch."])
XCTAssertEqual(titles, ["Release Plan", "Project Planning", "A plan for launch.", "Plan.md"])
try await search("pp", count: 1)
let submit = #selector(NSResponder.insertNewline(_:))
snapshot = .init(
Expand Down Expand Up @@ -379,7 +379,6 @@ extension QuickSearchTests {
try await waitUntil { table.numberOfRows == 2 }
XCTAssertFalse(results.isHidden)
XCTAssertEqual(table.selectedRow, 0)
XCTAssertTrue(view.control(field, textView: NSTextView(), doCommandBy: #selector(NSResponder.moveDown(_:))))

return view
}
Expand All @@ -391,7 +390,7 @@ extension QuickSearchTests {

let table: NSTableView = try XCTUnwrap(firstView.firstDescendant())
try await waitUntil {
let cell = table.view(atColumn: 0, row: 1, makeIfNecessary: true)
let cell = table.view(atColumn: 0, row: 0, makeIfNecessary: true)
return cell?.subviews.compactMap { $0 as? NSTextField }.last?.stringValue == "Untitled:4"
&& controller.window?.isActivatingResult == false
}
Expand All @@ -400,7 +399,7 @@ extension QuickSearchTests {
XCTAssertEqual(controller.window?.isVisible, true)
XCTAssertTrue(navigatedLines.isEmpty)

XCTAssertTrue(firstView.control(NSControl(), textView: NSTextView(), doCommandBy: #selector(NSResponder.moveDown(_:))))
XCTAssertEqual(table.selectedRow, 0)
XCTAssertTrue(firstView.control(NSControl(), textView: NSTextView(), doCommandBy: submit))
try await waitUntil { !navigatedLines.isEmpty }
XCTAssertEqual(navigatedLines, [4])
Expand Down