user1464024
user1464024

Reputation:

How to get the input source of an NSTextView

I set up a small test app that has the App Delegate set up as the delegate for the NSTextView.

With that, I supply the the following NSTextView delegate method:

- (BOOL)textView:(NSTextView *)aTextView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString

I would like to determine what input source generates the replacementString.

Mainly, I am interested in finding out if the replacementString comes from the Character Viewer (Edit > Special Characters...) or from the keyboard.

I have looked into using the Carbon Text Input API which can give you information about whether the Character Viewer is "selected" (on screen vs. offscreen), but I cannot find a way to determine if it was responsible for generating the text string.

The reason for doing this is that I am writing a simple plugin that leverages the Character Viewer to convert Unicode characters to HTML entities. The Character Viewer has all the characters in one place and it is available at the OS level. Seems to make more sense to use that than write my own.

Can this be done in Cocoa or Carbon?

Any help would be greatly appreciated.

Thank you.

Upvotes: 0

Views: 541

Answers (1)

rshahriar
rshahriar

Reputation: 2470

Have found some knowledge about text input sources from the following code:

CFArrayRef TISCreateInputSourceList (
   CFDictionaryRef properties,
   Boolean includeAllInstalled
);

Apple documentation (archive)

Got some idea about that from the following link which may be helpful to you also. Cheers.

Upvotes: 1

Related Questions