usbong / UsbongKit

A framework for reading and displaying contents of Usbong Trees
www.usbong.ph
Apache License 2.0
2 stars 1 forks source link

When "open quotation" is used, the word immediately right after it does not show the Word Hint #17

Closed masarapmabuhay closed 7 years ago

masarapmabuhay commented 7 years ago

Salut! I noticed that when "open quotation" is used, the word immediately right after it does not show the Word Hint.

wordhintbug

Merci beaucoup!

chrisamanse commented 7 years ago

Found the code that causes this issue. It is caused by the String parsing that checks if a substring is a word: https://github.com/usbong/UsbongKit/blob/master/UsbongKit/Views/HintsTextView.swift#L103

// Previous character should be whitespace or newline
let whitespaceAndNewLineCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
if range.location > 0 {
    let previousCharacterString = string.substringWithRange(NSRange(location: range.location - 1, length: 1))
    if previousCharacterString.rangeOfCharacterFromSet(whitespaceAndNewLineCharacterSet) == nil {
        foundStringIsWord = false
    }
}

To fix this, instead of just checking if the previous character is a whitespace or newline, it should also consider ".

chrisamanse commented 7 years ago

Let me know if 0addc21 fixes you're issue.

chrisamanse commented 7 years ago

Hi @masarapmabuhay, I updated the code and created PR #19. For a word to be considered a "word" by the parser, the previous character of the word can be any punctuation in general as defined in the Punctuation general category of Unicode character property. Previously, it was set only to whitespace, thus, in "Hindi was not considered a word previously.

chrisamanse commented 7 years ago

Feel free to merge it to master once you tested it.