-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from qwertyyb/develop
fix: some issue
- Loading branch information
Showing
6 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// TableView.swift | ||
// YPaste | ||
// | ||
// Created by marchyang on 2019/10/22. | ||
// Copyright © 2019 qwertyyb. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import HotKey | ||
|
||
|
||
class TableView: NSTableView { | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "SearchField-KeyUp"), object: nil, queue: nil) { (notification) in | ||
if notification.userInfo!["keyCode"] as! UInt16 == Key.downArrow.carbonKeyCode { | ||
self.window?.makeFirstResponder(self) | ||
} | ||
} | ||
NSEvent.addLocalMonitorForEvents(matching: NSEvent.EventTypeMask.mouseMoved) { (event) -> NSEvent? in | ||
var location = event.locationInWindow | ||
var visibleRect = self.visibleRect | ||
let originY = visibleRect.origin.y | ||
visibleRect.origin.y = 0 | ||
guard visibleRect.contains(location) else { return event } | ||
location.y = self.frame.height - (visibleRect.height - location.y) - originY | ||
let row = self.row(at: location) | ||
if row == -1 { | ||
return event | ||
} | ||
self.window?.makeFirstResponder(self) | ||
self.selectRowIndexes(IndexSet.init(arrayLiteral: self.numberOfRows - row - 1), byExtendingSelection: false) | ||
return event | ||
} | ||
} | ||
|
||
override func draw(_ dirtyRect: NSRect) { | ||
super.draw(dirtyRect) | ||
|
||
// Drawing code here. | ||
} | ||
|
||
override func keyDown(with event: NSEvent) { | ||
if self.selectedRow == 0 && event.keyCode == Key.upArrow.carbonKeyCode { | ||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "TableView-ReachTop"), object: nil, userInfo: nil) | ||
} | ||
super.keyDown(with: event) | ||
} | ||
|
||
@objc override func mouseDown(with event: NSEvent) { | ||
super.mouseDown(with: event) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// SearchField.swift | ||
// YPaste | ||
// | ||
// Created by marchyang on 2019/10/22. | ||
// Copyright © 2019 qwertyyb. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import HotKey | ||
|
||
class SearchField: NSSearchField { | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
|
||
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "TableView-ReachTop"), object: nil, queue: nil) { (notification) in | ||
self.window?.makeFirstResponder(self) | ||
} | ||
} | ||
|
||
override func draw(_ dirtyRect: NSRect) { | ||
super.draw(dirtyRect) | ||
|
||
// Drawing code here. | ||
} | ||
|
||
override func keyUp(with event: NSEvent) { | ||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "SearchField-KeyUp"), object: nil, userInfo: ["keyCode": event.keyCode]) | ||
super.keyDown(with: event) | ||
} | ||
} |