{"id":19686,"date":"2017-11-30T16:01:33","date_gmt":"2017-11-30T21:01:33","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=19686"},"modified":"2017-11-30T16:01:33","modified_gmt":"2017-11-30T21:01:33","slug":"why-the-selection-changes-when-you-do-syntax-highlighting-in-a-nstextview","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/11\/30\/why-the-selection-changes-when-you-do-syntax-highlighting-in-a-nstextview\/","title":{"rendered":"Why the Selection Changes When You Do Syntax Highlighting in a NSTextView"},"content":{"rendered":"<p><a href=\"https:\/\/christiantietze.de\/posts\/2017\/11\/syntax-highlight-nstextstorage-insertion-point-change\/\">Christian Tietze<\/a>:<\/p>\n<blockquote cite=\"https:\/\/christiantietze.de\/posts\/2017\/11\/syntax-highlight-nstextstorage-insertion-point-change\/\"><p>In short: when you type and the attributes of the line change, the insertion point is moved to the end of the line. That sucks.<\/p><p>TL;DR: Do not perform style changes inside of <code>NSTextStorage.processEditing()<\/code> or <code>NSTextStorageDelegate<\/code> methods but subscribe to <code>NSText.didChangeNotification<\/code> or <code>NSTextDelegate<\/code> or <code>NSTextViewDelegate.textDidChange(_:)<\/code>.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Christian Tietze: In short: when you type and the attributes of the line change, the insertion point is moved to the end of the line. That sucks.TL;DR: Do not perform style changes inside of NSTextStorage.processEditing() or NSTextStorageDelegate methods but subscribe to NSText.didChangeNotification or NSTextDelegate or NSTextViewDelegate.textDidChange(_:).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,30,1529,337,71],"class_list":["post-19686","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-mac","tag-macos-10-13","tag-markdown","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=19686"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19686\/revisions"}],"predecessor-version":[{"id":19687,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19686\/revisions\/19687"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=19686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=19686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=19686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}