Add Strong text shortcut

This commit is contained in:
Matt Baer 2017-08-04 17:46:04 -04:00
parent 14ec2eb2a5
commit c949b0b316
4 changed files with 28 additions and 0 deletions

View File

@ -85,6 +85,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state") UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state")
} }
@IBAction func formatStrong(_ sender: Any) {
let wc = NSApplication.shared().mainWindow?.windowController as? WindowController
wc?.embolden()
}
@IBAction func setFontSerif(_ sender: NSMenuItem) { @IBAction func setFontSerif(_ sender: NSMenuItem) {
deselectAllFonts() deselectAllFonts()
sender.state = NSOnState sender.state = NSOnState

View File

@ -322,6 +322,12 @@ DQ
</items> </items>
</menu> </menu>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="A2K-0R-RPV"/>
<menuItem title="Strong" keyEquivalent="b" id="iGK-Hg-zxc">
<connections>
<action selector="formatStrong:" target="Voe-Tx-rLC" id="Cpe-8G-6Yo"/>
</connections>
</menuItem>
</items> </items>
</menu> </menu>
</menuItem> </menuItem>

View File

@ -86,6 +86,19 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
} }
} }
func embolden() {
let selectedRange = writerText.selectedRange()
let selString = (self.writerText.textStorage?.string as! NSString).substring(with: selectedRange)
let repString = "**\(selString)**"
if self.writerText.shouldChangeText(in: selectedRange, replacementString: repString) {
self.writerText.replaceCharacters(in: NSRange(location: selectedRange.location, length: selectedRange.length), with: repString)
self.writerText.didChangeText()
if selString == "" {
writerText.setSelectedRange(NSRange(location: selectedRange.location + 2, length: 0))
}
}
}
func publish() { func publish() {
saveDocument() saveDocument()

View File

@ -27,4 +27,8 @@ class WindowController: NSWindowController {
func toggle(isNight: Bool) { func toggle(isNight: Bool) {
vc?.toggle(isNight: isNight) vc?.toggle(isNight: isNight)
} }
func embolden() {
vc?.embolden()
}
} }