Quantcast
Channel: Replace Substring with Markdown on NSTextView in Swift - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Clifton Labrum for Replace Substring with Markdown on NSTextView in Swift

$
0
0

It looks like this works:

let range = content.selectedRange()
markdownText = content.string

if let index = Range(range, in: markdownText){
  content.replaceCharacters(in: range, with: "**\(markdownText[index])**")
}

It provides the selected text snippet I need to wrap it in ** **. @MartinR's linked SO post helped me see that I can convert the string index with Range().


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>