How pocketed input method macOS is how to handle ascii 0x01 compatibility issues -macOS input settings correct buffer

As early as last year,Off the grid user input methods have reported pocketed Chinese input method macOS can not type in normal mode MarkDown proper way cloud notes,After testing proved true,Embodied in the text when hit,buffer refresh will be strange delete a character before the cursor - on,no more, no less,To delete a。

Fiddle for a long time failed,Finally, I did not move all the contents out of print,Discover the mystery:

When I get input cursor to the left of the text printed out,I found behind the text is appended a strange character:

Strange red question mark,It indicates that the character can not express。

You may not see,It is actually a character can not express,In general text editor to represent characters from a broken。but,After a character encoding conversion,I still find its original,This is an ASCII character,Code is 0x01 ……Ok,Characters can not express - then the answer is obvious,When the system is clearly set buffer to determine the number of the characters (that is, 1),But when this character did not replace the,Thus the end of the word to the replacement。

then,I will be judged according to BundleID proper way cloud notes,Once you find this character,That description is, in its MarkDown mode,Then type before buffer,Manually put this character to back it up - well at least it really work:

But did not last long,Six months,In another app, Quiver, I also encountered this problem,This is not so easy to solve,The same approach would lead to infinite recursion ...... Well,It's time to actually use the technologies。

Upon inquiry Gangster (yes ask out ......),macOS of InputMethodKit in public func setMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) this way,Although Swift is declared in the reception Any Types of,That both String still is NSAttributedString Can (the statement is true explanation),But in fact it is the latter needs,Very simple,Generate a NSAttributedString Re-write buffer ,problem solved。

The same time,Careful I also found an interesting question,Pocketed input method underline the buffer system is always better than an underscore to rough it a bit (here I do compare with QIM):

buffer underlined pocketed input method is very thick

QIM underscore relatively thin,And the same system。

original, IMKInputController There is such a method:

It can return a dictionary that contains rich text labels,This dictionary can mark a buffer strip,So let the system know this buffer。

So this is probably usage:

This property is then additionally generated when setting the buffer NSAttributedString .,This is macOS input to set the correct posture buffer:

Such,Input buffer zone and on exactly the same as the system:

Pocketed the input buffer underlined very small corrections macOS

Original article written by Gerber drop-off:R0uter's Blog » How pocketed input method macOS is how to handle ascii 0x01 compatibility issues -macOS input settings correct buffer

Reproduced Please keep the source and description link:

About the Author


The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *