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:
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:
1 2 3 4 5 6 7 8 9 |
//修复有道云笔记 MD 模式的奇葩问题 if let id = self.bundleIdentifier(), id == "com.youdao.note.YoudaoNoteMac" { if self.selectedRange().length == 1 { if self.attributedSubstring(from: self.selectedRange()).string == "\u{01}" { self.insert(text: "\u{01}") } } } //补丁结束 |
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):
original, IMKInputController There is such a method:
1 |
func mark(forStyle style: Int, at range: NSRange) -> [AnyHashable : Any]! |
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:
1 |
let attr = mark(forStyle: kTSMHiliteConvertedText, at: NSMakeRange(NSNotFound,0)) |
This property is then additionally generated when setting the buffer NSAttributedString .,This is macOS input to set the correct posture buffer:
1 2 |
let att = NSAttributedString(string: t, attributes: attr) setMarkedText(att, selectionRange: NSMakeRange(NSNotFound, NSNotFound), replacementRange: NSMakeRange(NSNotFound, NSNotFound)) |
Such,Input buffer zone and on exactly the same as the system:
Original article written by LogStudio: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:https://www.logcg.com/archives/2959.html