Skip to content

Commit

Permalink
Implemented shortcut detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
will-lumley committed Feb 6, 2020
1 parent 009cc03 commit fd4e3cd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions RichEditor/Classes/RichEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RichEditor: NSView
public fileprivate(set) lazy var textStorage = NSTextStorage()
public fileprivate(set) lazy var layoutManager = NSLayoutManager()
public fileprivate(set) lazy var textContainer = NSTextContainer()
public fileprivate(set) lazy var textView = NSTextView(frame: CGRect(), textContainer: self.textContainer)
public fileprivate(set) lazy var textView = RichTextView(frame: CGRect(), textContainer: self.textContainer)
public fileprivate(set) lazy var scrollview = NSScrollView()
/*------------------------------------------------------------*/

Expand Down Expand Up @@ -414,7 +414,7 @@ extension RichEditor: NSTextViewDelegate
if currentLineStr == RichEditor.bulletPointMarker {
self.textView.replaceCharacters(in: currentLineRange, with: "")
}

//If our current line is a full bullet point line, append a brand spanking new bullet point line below our current line for our user
else {
let bulletPointStr = "\(currentLineStr)\n\(RichEditor.bulletPointMarker)"
Expand Down
46 changes: 46 additions & 0 deletions RichEditor/Classes/RichTextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// RichTextView.swift
// RichEditor
//
// Created by William Lumley on 6/2/20.
//

import Foundation

public class RichTextView: NSTextView
{
//MARK: - NSTextView
override init(frame frameRect: NSRect, textContainer container: NSTextContainer?)
{
super.init(frame: frameRect, textContainer: container)
}

required init?(coder: NSCoder)
{
super.init(coder: coder)
}

override init(frame frameRect: NSRect)
{
super.init(frame: frameRect)
}

override public func performKeyEquivalent(with event: NSEvent) -> Bool
{
//Only process our event if it's a keydown event
if event.type != .keyDown {
return true
}

//If we've pressed our command button, let's see what other button was pressed
if event.modifierFlags.contains(.command) {
switch event.charactersIgnoringModifiers {
case "b":
print("CMD + B")
default:()
}
}

return true
}
}

0 comments on commit fd4e3cd

Please sign in to comment.