CutBox.app

Coverage Report

Created: 2024-03-12 03:40

.../Source/App/SearchAndPreview/SearchViewControllerMenuDelegate.swift
Line
Count
Source (jump to first uncovered line)
1
//
2
//  SearchViewControllerMenuDelegate.swift
3
//  CutBox
4
//
5
//  Created by Carlos Enumo on 30/09/22.
6
//  Copyright © 2023 ocodo. All rights reserved.
7
//
8
9
import Cocoa
10
11
extension SearchViewController: NSMenuDelegate {
12
13
1
    func menuWillOpen(_ menu: NSMenu) {
14
1
        let clicked = searchView.itemsList.clickedRow
15
1
16
1
        guard !searchView.itemsList.isRowSelected(clicked),
17
1
                let flags = CGEvent(source: nil)?.flags else { return }
18
1
19
1
        let proposedSelection: IndexSet
20
1
21
1
        if flags.contains(.maskShift), let last = orderedSelection.all().last {
22
0
            proposedSelection = searchView.itemsList.selectedRowIndexes
23
0
                .union(IndexSet(integersIn: min(clicked, last)...max(clicked, last)))
24
1
        } else if flags.contains(.maskCommand) {
25
0
            proposedSelection = searchView.itemsList.selectedRowIndexes.union(IndexSet(integer: clicked))
26
1
        } else {
27
1
            proposedSelection = IndexSet(integer: clicked)
28
1
        }
29
1
30
1
        let indexes = tableView(searchView.itemsList, selectionIndexesForProposedSelection: proposedSelection)
31
1
32
1
        searchView.itemsList.selectRowIndexes(indexes, byExtendingSelection: false)
33
1
    }
34
}