Browse Source

Add Strong text shortcut

master
Matt Baer 4 years ago
parent
commit
c949b0b316
4 changed files with 28 additions and 0 deletions
  1. +5
    -0
      writeas/AppDelegate.swift
  2. +6
    -0
      writeas/Base.lproj/Main.storyboard
  3. +13
    -0
      writeas/ViewController.swift
  4. +4
    -0
      writeas/WindowController.swift

+ 5
- 0
writeas/AppDelegate.swift View File

@@ -85,6 +85,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
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) {
deselectAllFonts()
sender.state = NSOnState


+ 6
- 0
writeas/Base.lproj/Main.storyboard View File

@@ -322,6 +322,12 @@ DQ
</items>
</menu>
</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>
</menu>
</menuItem>


+ 13
- 0
writeas/ViewController.swift 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() {
saveDocument()



+ 4
- 0
writeas/WindowController.swift View File

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

func embolden() {
vc?.embolden()
}
}

Loading…
Cancel
Save