# CutBox.app

## Coverage Report

#### Created: 2024-03-12 03:40

    .../Source/App/SearchAndPreview/SearchTextView.swift

    Line

    Count

    Source (jump to first uncovered line)

    1

    //

    2

    //  SearchTextView.swift

    3

    //  CutBox

    4

    //

    5

    //  Created by Jason Milkins on 7/4/18.

    6

    //  Copyright © 2018-2023 ocodo. All rights reserved.

    7

    //

    8

    9

    import Cocoa

    10

    import Carbon.HIToolbox

    11

    12

    class SearchTextView: CutBoxBaseTextView {

    13

    14

        var keyDownEvent: NSEvent?

    15

    16

    78

        required init?(coder aCoder: NSCoder) {

    17

    78

            super.init(coder: aCoder)

    18

    78

        }

    19

    20

    2

        override init(frame frameRect: NSRect, textContainer aTextContainer: NSTextContainer!) {

    21

    2

            super.init(frame: frameRect, textContainer: aTextContainer)

    22

    2

        }

    23

    24

    4

        override func keyDown(with event: NSEvent?) {

    25

    4

            if let event = event {

    26

    4

                keyDownEvent = event

    27

    4

                super.keyDown(with: event)

    28

    4

            }

    29

    4

        }

    30

    31

    2

        private var augmentedSelectors: [Selector] { return [

    32

    2

            "moveRight:",

    33

    2

            "moveLeft:"

    34

    4

            ].map { Selector($0) }

    35

    2

        }

    36

    37

    1

        private var skippedSelectors: [Selector] { return [

    38

    1

            "deleteToBeginningOfLine:",

    39

    1

            "moveUp:",

    40

    1

            "moveDown:",

    41

    1

            "moveDownAndModifySelection:",

    42

    1

            "moveUpAndModifySelection:",

    43

    1

            "insertNewline:",

    44

    1

            "noop:"

    45

    7

            ].map { Selector($0) }

    46

    1

        }

    47

    48

        // MARK: Pass through noop and specific keyboard events to nextResponder

    49

    6

        override func doCommand(by selector: Selector?) {

    50

    6

            if let selector = selector {

    51

    6

                if let keyEvent = keyDownEvent {

    52

    4

                    switch (keyEvent.key, keyEvent.modifiers) {

    53

    4

                    case (kVK_ANSI_A, [.command]):

    54

    1

                        self.selectAll(self)

    55

    1

                        return

    56

    4

                    case (kVK_ANSI_X, [.command]):

    57

    1

                        self.cut(self)

    58

    1

                        return

    59

    4

                    case (kVK_ANSI_C, [.command]):

    60

    1

                        self.copy(self)

    61

    1

                        return

    62

    4

                    case (kVK_ANSI_V, [.command]):

    63

    1

                        self.paste(self)

    64

    1

                        return

    65

    4

                    default:

    66

    0

                        break

    67

    4

                    }

    68

    6

                }

    69

    6

    70

    6

                if augmentedSelectors.contains(selector) {

    71

    1

                    super.doCommand(by: selector)

    72

    1

                    self.nextResponder?.keyDown(with: keyDownEvent!)

    73

    1

                    keyDownEvent = nil

    74

    6

                } else if skippedSelectors.contains(selector) {

    75

    1

                    self.nextResponder?.keyDown(with: keyDownEvent!)

    76

    1

                    keyDownEvent = nil

    77

    6

                } else {

    78

    5

                    super.doCommand(by: selector)

    79

    5

                    keyDownEvent = nil

    80

    6

                }

    81

    6

            }

    82

    6

        }

    83

    }