didChangeAutomaticCapitalizationNotification not triggered












0















What am I doing wrong? I don't get this notification. I have this function:



 @objc func onAutocorrection (_ notification: Foundation.Notification) {
Swift.print("(notification)")
}


later in the same class I do use it as follows:



NotificationCenter.default.addObserver(
self,
selector: #selector(onAutocorrection(_:)),
name: NSSpellChecker.didChangeAutomaticCapitalizationNotification,
object: nil)


The addObserver is executed, but the function is never called even when the application is capitalising in an NSTextView.



Why? Many thanks in advance!










share|improve this question























  • What do you do to trigger the notification?

    – Willeke
    Nov 24 '18 at 1:09











  • I type in a NSTextView. I start with lower caps glibberish, I get the little popover suggesting the same characters, but starting capitalist. I press space. I tried as well a few of the other “related” notifications, but onAutocorrection is never called.

    – Wizard of Kneup
    Nov 24 '18 at 3:42













  • I found this related question: stackoverflow.com/questions/6971396/notification-of-autocorrect

    – Wizard of Kneup
    Nov 24 '18 at 13:47






  • 1





    In the header, NSSpellCheckerDidChangeAutomaticCapitalizationNotification is described as "These notifications are made available via the default notification center when the global user preference settings mentioned above are changed.". Mentioned above are isAutomaticCapitalizationEnabled and its siblings.

    – Willeke
    Nov 24 '18 at 22:42











  • Is that an internal header you are referring to? I cannot see this comment. In any case, thank you Willeke. It seems that I simply misunderstood the meaning of the notification. Looks like the delegate function I used in my answer is indeed the right way to detect autocapitalise. It does work but I am not sure that I didn't affect some internals. Return key seems to work different, but I cannot reproduce it.

    – Wizard of Kneup
    Nov 25 '18 at 4:42
















0















What am I doing wrong? I don't get this notification. I have this function:



 @objc func onAutocorrection (_ notification: Foundation.Notification) {
Swift.print("(notification)")
}


later in the same class I do use it as follows:



NotificationCenter.default.addObserver(
self,
selector: #selector(onAutocorrection(_:)),
name: NSSpellChecker.didChangeAutomaticCapitalizationNotification,
object: nil)


The addObserver is executed, but the function is never called even when the application is capitalising in an NSTextView.



Why? Many thanks in advance!










share|improve this question























  • What do you do to trigger the notification?

    – Willeke
    Nov 24 '18 at 1:09











  • I type in a NSTextView. I start with lower caps glibberish, I get the little popover suggesting the same characters, but starting capitalist. I press space. I tried as well a few of the other “related” notifications, but onAutocorrection is never called.

    – Wizard of Kneup
    Nov 24 '18 at 3:42













  • I found this related question: stackoverflow.com/questions/6971396/notification-of-autocorrect

    – Wizard of Kneup
    Nov 24 '18 at 13:47






  • 1





    In the header, NSSpellCheckerDidChangeAutomaticCapitalizationNotification is described as "These notifications are made available via the default notification center when the global user preference settings mentioned above are changed.". Mentioned above are isAutomaticCapitalizationEnabled and its siblings.

    – Willeke
    Nov 24 '18 at 22:42











  • Is that an internal header you are referring to? I cannot see this comment. In any case, thank you Willeke. It seems that I simply misunderstood the meaning of the notification. Looks like the delegate function I used in my answer is indeed the right way to detect autocapitalise. It does work but I am not sure that I didn't affect some internals. Return key seems to work different, but I cannot reproduce it.

    – Wizard of Kneup
    Nov 25 '18 at 4:42














0












0








0








What am I doing wrong? I don't get this notification. I have this function:



 @objc func onAutocorrection (_ notification: Foundation.Notification) {
Swift.print("(notification)")
}


later in the same class I do use it as follows:



NotificationCenter.default.addObserver(
self,
selector: #selector(onAutocorrection(_:)),
name: NSSpellChecker.didChangeAutomaticCapitalizationNotification,
object: nil)


The addObserver is executed, but the function is never called even when the application is capitalising in an NSTextView.



Why? Many thanks in advance!










share|improve this question














What am I doing wrong? I don't get this notification. I have this function:



 @objc func onAutocorrection (_ notification: Foundation.Notification) {
Swift.print("(notification)")
}


later in the same class I do use it as follows:



NotificationCenter.default.addObserver(
self,
selector: #selector(onAutocorrection(_:)),
name: NSSpellChecker.didChangeAutomaticCapitalizationNotification,
object: nil)


The addObserver is executed, but the function is never called even when the application is capitalising in an NSTextView.



Why? Many thanks in advance!







cocoa nstextview






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 19:30









Wizard of KneupWizard of Kneup

677625




677625













  • What do you do to trigger the notification?

    – Willeke
    Nov 24 '18 at 1:09











  • I type in a NSTextView. I start with lower caps glibberish, I get the little popover suggesting the same characters, but starting capitalist. I press space. I tried as well a few of the other “related” notifications, but onAutocorrection is never called.

    – Wizard of Kneup
    Nov 24 '18 at 3:42













  • I found this related question: stackoverflow.com/questions/6971396/notification-of-autocorrect

    – Wizard of Kneup
    Nov 24 '18 at 13:47






  • 1





    In the header, NSSpellCheckerDidChangeAutomaticCapitalizationNotification is described as "These notifications are made available via the default notification center when the global user preference settings mentioned above are changed.". Mentioned above are isAutomaticCapitalizationEnabled and its siblings.

    – Willeke
    Nov 24 '18 at 22:42











  • Is that an internal header you are referring to? I cannot see this comment. In any case, thank you Willeke. It seems that I simply misunderstood the meaning of the notification. Looks like the delegate function I used in my answer is indeed the right way to detect autocapitalise. It does work but I am not sure that I didn't affect some internals. Return key seems to work different, but I cannot reproduce it.

    – Wizard of Kneup
    Nov 25 '18 at 4:42



















  • What do you do to trigger the notification?

    – Willeke
    Nov 24 '18 at 1:09











  • I type in a NSTextView. I start with lower caps glibberish, I get the little popover suggesting the same characters, but starting capitalist. I press space. I tried as well a few of the other “related” notifications, but onAutocorrection is never called.

    – Wizard of Kneup
    Nov 24 '18 at 3:42













  • I found this related question: stackoverflow.com/questions/6971396/notification-of-autocorrect

    – Wizard of Kneup
    Nov 24 '18 at 13:47






  • 1





    In the header, NSSpellCheckerDidChangeAutomaticCapitalizationNotification is described as "These notifications are made available via the default notification center when the global user preference settings mentioned above are changed.". Mentioned above are isAutomaticCapitalizationEnabled and its siblings.

    – Willeke
    Nov 24 '18 at 22:42











  • Is that an internal header you are referring to? I cannot see this comment. In any case, thank you Willeke. It seems that I simply misunderstood the meaning of the notification. Looks like the delegate function I used in my answer is indeed the right way to detect autocapitalise. It does work but I am not sure that I didn't affect some internals. Return key seems to work different, but I cannot reproduce it.

    – Wizard of Kneup
    Nov 25 '18 at 4:42

















What do you do to trigger the notification?

– Willeke
Nov 24 '18 at 1:09





What do you do to trigger the notification?

– Willeke
Nov 24 '18 at 1:09













I type in a NSTextView. I start with lower caps glibberish, I get the little popover suggesting the same characters, but starting capitalist. I press space. I tried as well a few of the other “related” notifications, but onAutocorrection is never called.

– Wizard of Kneup
Nov 24 '18 at 3:42







I type in a NSTextView. I start with lower caps glibberish, I get the little popover suggesting the same characters, but starting capitalist. I press space. I tried as well a few of the other “related” notifications, but onAutocorrection is never called.

– Wizard of Kneup
Nov 24 '18 at 3:42















I found this related question: stackoverflow.com/questions/6971396/notification-of-autocorrect

– Wizard of Kneup
Nov 24 '18 at 13:47





I found this related question: stackoverflow.com/questions/6971396/notification-of-autocorrect

– Wizard of Kneup
Nov 24 '18 at 13:47




1




1





In the header, NSSpellCheckerDidChangeAutomaticCapitalizationNotification is described as "These notifications are made available via the default notification center when the global user preference settings mentioned above are changed.". Mentioned above are isAutomaticCapitalizationEnabled and its siblings.

– Willeke
Nov 24 '18 at 22:42





In the header, NSSpellCheckerDidChangeAutomaticCapitalizationNotification is described as "These notifications are made available via the default notification center when the global user preference settings mentioned above are changed.". Mentioned above are isAutomaticCapitalizationEnabled and its siblings.

– Willeke
Nov 24 '18 at 22:42













Is that an internal header you are referring to? I cannot see this comment. In any case, thank you Willeke. It seems that I simply misunderstood the meaning of the notification. Looks like the delegate function I used in my answer is indeed the right way to detect autocapitalise. It does work but I am not sure that I didn't affect some internals. Return key seems to work different, but I cannot reproduce it.

– Wizard of Kneup
Nov 25 '18 at 4:42





Is that an internal header you are referring to? I cannot see this comment. In any case, thank you Willeke. It seems that I simply misunderstood the meaning of the notification. Looks like the delegate function I used in my answer is indeed the right way to detect autocapitalise. It does work but I am not sure that I didn't affect some internals. Return key seems to work different, but I cannot reproduce it.

– Wizard of Kneup
Nov 25 '18 at 4:42












1 Answer
1






active

oldest

votes


















0














It looks like I misunderstood the notification. It is not meant to be triggered when automatic capitalisation happens but when the systems preference of your Mac is changing.
See the comment of ever helpful Willeke and see Notification of autocorrect



In order to get to the intended result of reacting to autocapitalisation did I implement this function in the NSTextViewDelegate:



public func textView(_ view: NSTextView, didCheckTextIn range: NSRange, types checkingTypes: NSTextCheckingTypes, options: [NSSpellChecker.OptionKey : Any] = [:], results: [NSTextCheckingResult], orthography: NSOrthography, wordCount: Int) -> [NSTextCheckingResult] {
if !range.contains(0){
return results
}
var newResult = [NSTextCheckingResult]()
for result in results {
if let textToChange = view.string[range].components(separatedBy: " ").first, let replacement = result.replacementString?.components(separatedBy: " ").first {
let firstLetterCap = textToChange.capitalizingFirstLetter()
if replacement == firstLetterCap {
continue //don't add to results
}
}
newResult.append(result)
}
return newResult
}


This function will prevent that the first character will be capitalised.



Ultimately, I check whether the capitalised version of the first word of the range that must include position "0" is equal to the first word of the replacement string. And if it is then I remove that result/suggestion from the result list.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452074%2fdidchangeautomaticcapitalizationnotification-not-triggered%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It looks like I misunderstood the notification. It is not meant to be triggered when automatic capitalisation happens but when the systems preference of your Mac is changing.
    See the comment of ever helpful Willeke and see Notification of autocorrect



    In order to get to the intended result of reacting to autocapitalisation did I implement this function in the NSTextViewDelegate:



    public func textView(_ view: NSTextView, didCheckTextIn range: NSRange, types checkingTypes: NSTextCheckingTypes, options: [NSSpellChecker.OptionKey : Any] = [:], results: [NSTextCheckingResult], orthography: NSOrthography, wordCount: Int) -> [NSTextCheckingResult] {
    if !range.contains(0){
    return results
    }
    var newResult = [NSTextCheckingResult]()
    for result in results {
    if let textToChange = view.string[range].components(separatedBy: " ").first, let replacement = result.replacementString?.components(separatedBy: " ").first {
    let firstLetterCap = textToChange.capitalizingFirstLetter()
    if replacement == firstLetterCap {
    continue //don't add to results
    }
    }
    newResult.append(result)
    }
    return newResult
    }


    This function will prevent that the first character will be capitalised.



    Ultimately, I check whether the capitalised version of the first word of the range that must include position "0" is equal to the first word of the replacement string. And if it is then I remove that result/suggestion from the result list.






    share|improve this answer






























      0














      It looks like I misunderstood the notification. It is not meant to be triggered when automatic capitalisation happens but when the systems preference of your Mac is changing.
      See the comment of ever helpful Willeke and see Notification of autocorrect



      In order to get to the intended result of reacting to autocapitalisation did I implement this function in the NSTextViewDelegate:



      public func textView(_ view: NSTextView, didCheckTextIn range: NSRange, types checkingTypes: NSTextCheckingTypes, options: [NSSpellChecker.OptionKey : Any] = [:], results: [NSTextCheckingResult], orthography: NSOrthography, wordCount: Int) -> [NSTextCheckingResult] {
      if !range.contains(0){
      return results
      }
      var newResult = [NSTextCheckingResult]()
      for result in results {
      if let textToChange = view.string[range].components(separatedBy: " ").first, let replacement = result.replacementString?.components(separatedBy: " ").first {
      let firstLetterCap = textToChange.capitalizingFirstLetter()
      if replacement == firstLetterCap {
      continue //don't add to results
      }
      }
      newResult.append(result)
      }
      return newResult
      }


      This function will prevent that the first character will be capitalised.



      Ultimately, I check whether the capitalised version of the first word of the range that must include position "0" is equal to the first word of the replacement string. And if it is then I remove that result/suggestion from the result list.






      share|improve this answer




























        0












        0








        0







        It looks like I misunderstood the notification. It is not meant to be triggered when automatic capitalisation happens but when the systems preference of your Mac is changing.
        See the comment of ever helpful Willeke and see Notification of autocorrect



        In order to get to the intended result of reacting to autocapitalisation did I implement this function in the NSTextViewDelegate:



        public func textView(_ view: NSTextView, didCheckTextIn range: NSRange, types checkingTypes: NSTextCheckingTypes, options: [NSSpellChecker.OptionKey : Any] = [:], results: [NSTextCheckingResult], orthography: NSOrthography, wordCount: Int) -> [NSTextCheckingResult] {
        if !range.contains(0){
        return results
        }
        var newResult = [NSTextCheckingResult]()
        for result in results {
        if let textToChange = view.string[range].components(separatedBy: " ").first, let replacement = result.replacementString?.components(separatedBy: " ").first {
        let firstLetterCap = textToChange.capitalizingFirstLetter()
        if replacement == firstLetterCap {
        continue //don't add to results
        }
        }
        newResult.append(result)
        }
        return newResult
        }


        This function will prevent that the first character will be capitalised.



        Ultimately, I check whether the capitalised version of the first word of the range that must include position "0" is equal to the first word of the replacement string. And if it is then I remove that result/suggestion from the result list.






        share|improve this answer















        It looks like I misunderstood the notification. It is not meant to be triggered when automatic capitalisation happens but when the systems preference of your Mac is changing.
        See the comment of ever helpful Willeke and see Notification of autocorrect



        In order to get to the intended result of reacting to autocapitalisation did I implement this function in the NSTextViewDelegate:



        public func textView(_ view: NSTextView, didCheckTextIn range: NSRange, types checkingTypes: NSTextCheckingTypes, options: [NSSpellChecker.OptionKey : Any] = [:], results: [NSTextCheckingResult], orthography: NSOrthography, wordCount: Int) -> [NSTextCheckingResult] {
        if !range.contains(0){
        return results
        }
        var newResult = [NSTextCheckingResult]()
        for result in results {
        if let textToChange = view.string[range].components(separatedBy: " ").first, let replacement = result.replacementString?.components(separatedBy: " ").first {
        let firstLetterCap = textToChange.capitalizingFirstLetter()
        if replacement == firstLetterCap {
        continue //don't add to results
        }
        }
        newResult.append(result)
        }
        return newResult
        }


        This function will prevent that the first character will be capitalised.



        Ultimately, I check whether the capitalised version of the first word of the range that must include position "0" is equal to the first word of the replacement string. And if it is then I remove that result/suggestion from the result list.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 25 '18 at 4:44

























        answered Nov 24 '18 at 13:55









        Wizard of KneupWizard of Kneup

        677625




        677625
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452074%2fdidchangeautomaticcapitalizationnotification-not-triggered%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Ottavio Pratesi

            Tricia Helfer

            15 giugno