Permalink
Browse files

Merge pull request #370 from JimJeon/feature/emoji

이모티콘 입력기 일부 수정
  • Loading branch information...
youknowone committed Oct 11, 2018
2 parents 5c5211a + 19d77d4 commit 62f91d6cb824a626edcd13bef1b33c50d511dee7
@@ -94,6 +94,8 @@
878898012160AA6E00BF5770 /* CIMInputManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871B807B2153DDFA0013EE69 /* CIMInputManager.swift */; };
8FB2D1F50746B5A15A5617BE /* libPods-OSXTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E73EDD6DBCA6CA17A1708BE5 /* libPods-OSXTests.a */; };
A34E20012168B21B00B12476 /* GureumTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BAAE062160C6970076C66D /* GureumTests.swift */; };
A34E2025216ADBEC00B12476 /* emoji.txt in Copy Hanja Files */ = {isa = PBXBuildFile; fileRef = A34E2024216ADBEC00B12476 /* emoji.txt */; };
A36A435B216F86780052BE12 /* emoji_ko.txt in Copy Hanja Files */ = {isa = PBXBuildFile; fileRef = A36A4358216F86780052BE12 /* emoji_ko.txt */; };
A3F007682160B09700501606 /* EmoticonComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F007652160B09700501606 /* EmoticonComposer.swift */; };
B0DE8679435065D0866D2AAF /* Pods_PreferencesApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F10FF4A81E4501FB2F71251 /* Pods_PreferencesApp.framework */; };
DAA59CC398282039EE3F4265 /* libPods-OSX.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 057B3CD9EB092349BD540E8B /* libPods-OSX.a */; };
@@ -178,6 +180,8 @@
dstPath = hanja;
dstSubfolderSpec = 7;
files = (
A36A435B216F86780052BE12 /* emoji_ko.txt in Copy Hanja Files */,
A34E2025216ADBEC00B12476 /* emoji.txt in Copy Hanja Files */,
3835B52E1F5DABB400896BEC /* mssymbol.txt in Copy Hanja Files */,
3835B52D1F5DABAF00896BEC /* hanja.txt in Copy Hanja Files */,
3835B5251F5DAB5E00896BEC /* all.txt in Copy Hanja Files */,
@@ -341,6 +345,8 @@
80383E6C2161F0D300FC5FB6 /* hangul-combination-3p.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "hangul-combination-3p.xml"; sourceTree = "<group>"; };
871B807B2153DDFA0013EE69 /* CIMInputManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CIMInputManager.swift; sourceTree = "<group>"; };
9B1EC9A5CFCEEBC9368AE9A9 /* Pods-PreferencesApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PreferencesApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PreferencesApp/Pods-PreferencesApp.debug.xcconfig"; sourceTree = "<group>"; };
A34E2024216ADBEC00B12476 /* emoji.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = emoji.txt; path = OSX/data/hanja/emoji.txt; sourceTree = "<group>"; };
A36A4358216F86780052BE12 /* emoji_ko.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = emoji_ko.txt; path = OSX/data/hanja/emoji_ko.txt; sourceTree = "<group>"; };
A3BAAE062160C6970076C66D /* GureumTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GureumTests.swift; sourceTree = "<group>"; };
A3F007652160B09700501606 /* EmoticonComposer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmoticonComposer.swift; sourceTree = "<group>"; };
ACF9BC1D0ED009626F8CD0E5 /* Pods-Preferences.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Preferences.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Preferences/Pods-Preferences.debug.xcconfig"; sourceTree = "<group>"; };
@@ -576,6 +582,8 @@
38863C4E140E62D100A8ED76 = {
isa = PBXGroup;
children = (
A36A4358216F86780052BE12 /* emoji_ko.txt */,
A34E2024216ADBEC00B12476 /* emoji.txt */,
387DFFFE1421F1E000DAE6F4 /* Common Input Method */,
38162DF6141263270077AA2D /* OSX */,
38BFE7FD18B45419004B2B2E /* GureumTests */,
@@ -31,9 +31,9 @@ class GureumTests: XCTestCase {
func testSearchEmoticonTable() {
let bundle: Bundle = Bundle.main
let path: String? = bundle.path(forResource: "emoticon", ofType: "txt", inDirectory: "hanja")
let path: String? = bundle.path(forResource: "emoji", ofType: "txt", inDirectory: "hanja")
let table: HGHanjaTable = HGHanjaTable.init(contentOfFile: path ?? "")
let list: HGHanjaList = table.hanjas(byPrefixSearching: "hushed") ?? HGHanjaList()
let list: HGHanjaList = table.hanjas(byPrefixSearching: "hushed") ?? HGHanjaList() // 현재 5글자 이상만 가능
XCTAssert(list.count > 0)
}
}
View
@@ -11,48 +11,43 @@ import Hangul
let DEBUG_EMOTICON = true
class EmoticonComposer: CIMComposer {
// FIXME: How can i use static with _sharedEmoticonTable?
var _sharedEmoticonTable: HGHanjaTable? = nil
static let emoticonTable: HGHanjaTable = HGHanjaTable(contentOfFile: Bundle.main.path(forResource: "emoji", ofType: "txt", inDirectory: "hanja")!)
var _commitString: String = ""
var _candidates: [String] = []
var _composedString: String = ""
var _candidates: [String]?
var _bufferedString: String = ""
var _composedString: String = ""
var _commitString: String = ""
var mode: Bool = false
var mode: Bool = true
var _selectedCandidate: NSAttributedString? = nil
var romanComposer: CIMComposerDelegate {
return self.delegate
}
override var composedString: String {
get {
return self._composedString
}
set(newValue) {
self._composedString = newValue
}
override var candidates: [String]? {
return _candidates
}
override var originalString: String {
get {
return self._bufferedString
}
override var composedString: String {
return _composedString
}
override var commitString: String {
get {
return self._commitString
}
set(newValue) {
self._commitString = newValue
}
return _commitString
}
override var originalString: String {
return _bufferedString
}
override func dequeueCommitString() -> String {
let dequeued = self._commitString
self._commitString = ""
return dequeued
let result = self._commitString
if !result.isEmpty {
self._bufferedString = ""
self._commitString = ""
}
return result
}
override func cancelComposition() {
@@ -68,34 +63,30 @@ class EmoticonComposer: CIMComposer {
}
override var hasCandidates: Bool {
get {
let candidates = self._candidates
return candidates.count > 0 ? true : false
}
}
override var candidates: [String]! {
get {
return self._candidates
}
set(newValue) {
self._candidates = newValue
guard let candidates = self._candidates else {
return false
}
return candidates.count > 0 ? true : false
}
override func candidateSelected(_ candidateString: NSAttributedString) {
dlog(DEBUG_EMOTICON, "DEBUG 1, [candidateSelected] MSG: function called")
let value: String? = candidateString.string.components(separatedBy: ":")[0]
dlog(DEBUG_EMOTICON, "DEBUG 2, [candidateSelected] MSG: value == %@", value ?? "")
let value: String = candidateString.string.components(separatedBy: ":")[0]
dlog(DEBUG_EMOTICON, "DEBUG 2, [candidateSelected] MSG: value == %@", value)
self._bufferedString = ""
self.composedString = ""
self.commitString = value ?? ""
self._composedString = ""
self._commitString = value
self.romanComposer.cancelComposition()
self.romanComposer.dequeueCommitString()
}
override func candidateSelectionChanged(_ candidateString: NSAttributedString) {
// Pass
if candidateString.length == 0 {
self._selectedCandidate = nil
} else {
let value: String = candidateString.string.components(separatedBy: ":")[0]
self._selectedCandidate = NSAttributedString(string: value)
}
}
func updateEmoticonCandidates() {
@@ -105,18 +96,18 @@ class EmoticonComposer: CIMComposer {
self._bufferedString.append(x)
self._bufferedString.append(self.romanComposer.composedString)
let originalString: String = self._bufferedString
self.composedString = originalString
self._composedString = originalString
let keyword: String = originalString
dlog(DEBUG_EMOTICON, "DEBUG 1, [updateEmoticonCandidates] MSG: %@", originalString)
if keyword.count == 0 {
self._candidates = []
} else {
self._candidates = []
for table: HGHanjaTable in [emoticonTable()!] {
for table: HGHanjaTable in [EmoticonComposer.emoticonTable] {
dlog(DEBUG_EMOTICON, "DEBUG 3, [updateEmoticonCandidates] MSG: before hanjasByPrefixSearching")
dlog(DEBUG_EMOTICON, "DEBUG 4, [updateEmoticonCandidates] MSG: [keyword: %@]", keyword)
dlog(DEBUG_EMOTICON, "DEBUG 14, [updateEmoticonCandidates] MSG: %@", self._sharedEmoticonTable.debugDescription)
dlog(DEBUG_EMOTICON, "DEBUG 14, [updateEmoticonCandidates] MSG: %@", EmoticonComposer.emoticonTable.debugDescription)
let list: HGHanjaList = table.hanjas(byPrefixSearching: keyword) ?? HGHanjaList()
dlog(DEBUG_EMOTICON, "DEBUG 5, [updateEmoticonCandidates] MSG: after hanjasByPrefixSearching")
@@ -128,12 +119,15 @@ class EmoticonComposer: CIMComposer {
dlog(DEBUG_EMOTICON, "DEBUG 7, [updateEmoticonCandidates] MSG: hanja is nil!")
}
dlog(DEBUG_EMOTICON, "DEBUG 6, [updateEmoticonCandidates] MSG: %@ %@ %@", list.hanja(at: idx).comment, list.hanja(at: idx).key, list.hanja(at: idx).value)
self._candidates.append(emoticon.value as String + ": " + emoticon.comment as String)
if self._candidates == nil {
self._candidates = []
}
self._candidates!.append(emoticon.value as String + ": " + emoticon.comment as String)
}
}
}
}
dlog(DEBUG_EMOTICON, "DEBUG 2, [updateEmoticonCandidates] MSG: %@", self.candidates)
dlog(DEBUG_EMOTICON, "DEBUG 2, [updateEmoticonCandidates] MSG: %@", self.candidates ?? [])
}
func update(fromController controller: CIMInputController) {
@@ -158,16 +152,6 @@ class EmoticonComposer: CIMComposer {
self.updateEmoticonCandidates()
}
func emoticonTable() -> HGHanjaTable? {
if self._sharedEmoticonTable == nil {
let bundle: Bundle = Bundle.main
let path: String? = bundle.path(forResource: "emoticon", ofType: "txt", inDirectory: "hanja")
self._sharedEmoticonTable = HGHanjaTable.init(contentOfFile: path ?? "")
}
return self._sharedEmoticonTable
}
override func inputController(_ controller: CIMInputController!, inputText string: String!, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any!) -> CIMInputTextProcessResult {
dlog(DEBUG_EMOTICON, "DEBUG 1, [inputController] MSG: %@, [[%d]]", string, keyCode)
var result: CIMInputTextProcessResult = self.delegate.inputController(controller, inputText: string, key: keyCode, modifiers: flags, client: sender)
@@ -182,7 +166,7 @@ class EmoticonComposer: CIMComposer {
let lastIndex: String.Index = self._bufferedString.index(before: self._bufferedString.endIndex)
self._bufferedString.remove(at: lastIndex)
dlog(DEBUG_EMOTICON, "DEBUG 5, [inputController] MSG: after deletion, buffer (%@)", self._bufferedString)
self.composedString = self.originalString
self._composedString = self.originalString
result = CIMInputTextProcessResult.processed
} else {
self.mode = false
@@ -207,18 +191,20 @@ class EmoticonComposer: CIMComposer {
self.romanComposer.cancelComposition()
self._bufferedString.append(self.romanComposer.dequeueCommitString())
// step 2. commit all
self.composedString = self.originalString
self._composedString = self.originalString
self.cancelComposition()
// step 3. cancel candidates
self.candidates = nil
self._candidates = []
return CIMInputTextProcessResult.notProcessedAndNeedsCommit
// Enter
case 36:
self.candidateSelected(self._selectedCandidate ?? NSAttributedString(string: ""))
break
default:
break
}
dlog(DEBUG_EMOTICON, "DEBUG 2, [inputController] MSG: %@", string)
// switch for some keyCodes
// updateEmoticonCandidates
self.updateEmoticonCandidates()
dlog(DEBUG_EMOTICON, "DEBUG 3, [inputController] MSG: %@", string)
View
@@ -178,8 +178,7 @@ let GureumInputSourceToHangulKeyboardIdentifierTable: [String: String] = [
if (inputModifier, keyCode) == configuration.inputModeHanjaKey {
delegatedComposer = hanjaComposer
}
// Disabled
// if (inputModifier, keyCode) == configuration.inputModeEmojiKey {
// if (inputModifier, keyCode) == configuration.inputModeEmoticonKey {
// delegatedComposer = emoticonComposer
// }
// }
@@ -20,8 +20,8 @@ enum GureumConfigurationName: String {
case rightControlKeyShortcutBehavior = "CIMRightControlKeyShortcutBehavior"
case inputModeExchangeKeyModifier = "CIMInputModeExchangeKeyModifier"
case inputModeExchangeKeyCode = "CIMInputModeExchangeKeyCode"
case inputModeEmojiKeyModifier = "CIMInputModeEmojiKeyModifier"
case inputModeEmojiKeyCode = "CIMInputModeEmojiKeyCode"
case inputModeEmoticonKeyModifier = "CIMInputModeEmoticonKeyModifier"
case inputModeEmoticonKeyCode = "CIMInputModeEmoticonKeyCode"
case inputModeHanjaKeyModifier = "CIMInputModeHanjaKeyModifier"
case inputModeHanjaKeyCode = "CIMInputModeHanjaKeyCode"
case inputModeEnglishKeyModifier = "CIMInputModeEnglishKeyModifier"
@@ -47,8 +47,8 @@ enum GureumConfigurationName: String {
self.register(defaults: [
GureumConfigurationName.inputModeExchangeKeyModifier.rawValue: NSEvent.ModifierFlags.shift.rawValue,
GureumConfigurationName.inputModeExchangeKeyCode.rawValue: 0x31,
GureumConfigurationName.inputModeEmojiKeyModifier.rawValue: NSEvent.ModifierFlags([.shift, .option]).rawValue,
GureumConfigurationName.inputModeEmojiKeyCode.rawValue: 0x24,
GureumConfigurationName.inputModeEmoticonKeyModifier.rawValue: NSEvent.ModifierFlags([.shift, .option]).rawValue,
GureumConfigurationName.inputModeEmoticonKeyCode.rawValue: 0x24,
GureumConfigurationName.inputModeHanjaKeyModifier.rawValue: NSEvent.ModifierFlags.option.rawValue,
GureumConfigurationName.inputModeHanjaKeyCode.rawValue: 0x24,
GureumConfigurationName.optionKeyBehavior.rawValue: 0,
@@ -116,22 +116,22 @@ enum GureumConfigurationName: String {
}
}
@objc public var inputModeEmojiKeyModifier: NSEvent.ModifierFlags {
@objc public var inputModeEmoticonKeyModifier: NSEvent.ModifierFlags {
get {
let value = self.integer(forKey: GureumConfigurationName.inputModeEmojiKeyModifier.rawValue)
let value = self.integer(forKey: GureumConfigurationName.inputModeEmoticonKeyModifier.rawValue)
return NSEvent.ModifierFlags(rawValue: UInt(value))
}
}
@objc public var inputModeEmojiKeyCode: Int {
@objc public var inputModeEmoticonKeyCode: Int {
get {
return self.integer(forKey: GureumConfigurationName.inputModeEmojiKeyCode.rawValue)
return self.integer(forKey: GureumConfigurationName.inputModeEmoticonKeyCode.rawValue)
}
}
public var inputModeEmojiKey: (NSEvent.ModifierFlags, Int) {
public var inputModeEmoticonKey: (NSEvent.ModifierFlags, Int) {
get {
return (self.inputModeEmojiKeyModifier, self.inputModeEmojiKeyCode)
return (self.inputModeEmoticonKeyModifier, self.inputModeEmoticonKeyCode)
}
}
View
@@ -15,6 +15,7 @@ class HanjaComposer: CIMComposer {
static let wordTable: HGHanjaTable = HGHanjaTable(contentOfFile: Bundle.main.path(forResource: "hanjaw", ofType: "txt", inDirectory: "hanja")!)
static let reversedTable: HGHanjaTable = HGHanjaTable(contentOfFile: Bundle.main.path(forResource: "hanjar", ofType: "txt", inDirectory: "hanja")!)
static let msSymbolTable: HGHanjaTable = HGHanjaTable(contentOfFile: Bundle.main.path(forResource: "mssymbol", ofType: "txt", inDirectory: "hanja")!)
static let emojiTable: HGHanjaTable = HGHanjaTable(contentOfFile: Bundle.main.path(forResource: "emoji_ko", ofType: "txt", inDirectory: "hanja")!)
var _candidates: [String]?
var _bufferedString: String = ""
@@ -162,7 +163,7 @@ class HanjaComposer: CIMComposer {
} else {
// dlog(DEBUG_HANJACOMPOSER, "HanjaComposer -updateHanjaCandidates candidates");
var candidates: [String] = []
for table in [HanjaComposer.msSymbolTable, HanjaComposer.wordTable, HanjaComposer.reversedTable, HanjaComposer.characterTable] {
for table in [HanjaComposer.msSymbolTable, HanjaComposer.wordTable, HanjaComposer.reversedTable, HanjaComposer.characterTable, HanjaComposer.emojiTable] {
dlog(DEBUG_HANJACOMPOSER, "HanjaComposer -updateHanjaCandidates getting list for table: %@", table);
let list: HGHanjaList = table.hanjas(byPrefixSearching: keyword) ?? HGHanjaList()
dlog(DEBUG_HANJACOMPOSER, "HanjaComposer -updateHanjaCandidates getting list: %@", list);
Oops, something went wrong.

0 comments on commit 62f91d6

Please sign in to comment.