mgrPrefs, etc. // Nomenclatural updates.
- KeyLayout -> MandarinParser. - BasisKeyboardLayout -> BasicKeyboardLayout. - Also optimizing KeyCov.isDynamicBasicKeyboardLayoutEnabled().
This commit is contained in:
parent
3452f4bffa
commit
8a4c2b5910
|
@ -25,43 +25,30 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
import Cocoa
|
||||
|
||||
@objc class AppleKeyboardConverter: NSObject {
|
||||
@objc class func isDynamicBaseKeyboardLayoutEnabled() -> Bool {
|
||||
switch mgrPrefs.basisKeyboardLayout {
|
||||
case "com.apple.keylayout.ZhuyinBopomofo":
|
||||
return true
|
||||
case "com.apple.keylayout.ZhuyinEten":
|
||||
return true
|
||||
case "org.atelierInmu.vChewing.keyLayouts.vchewingdachen":
|
||||
return true
|
||||
case "org.atelierInmu.vChewing.keyLayouts.vchewingmitac":
|
||||
return true
|
||||
case "org.atelierInmu.vChewing.keyLayouts.vchewingibm":
|
||||
return true
|
||||
case "org.atelierInmu.vChewing.keyLayouts.vchewingseigyou":
|
||||
return true
|
||||
case "org.atelierInmu.vChewing.keyLayouts.vchewingeten":
|
||||
return true
|
||||
case "org.unknown.keylayout.vChewingDachen":
|
||||
return true
|
||||
case "org.unknown.keylayout.vChewingFakeSeigyou":
|
||||
return true
|
||||
case "org.unknown.keylayout.vChewingETen":
|
||||
return true
|
||||
case "org.unknown.keylayout.vChewingIBM":
|
||||
return true
|
||||
case "org.unknown.keylayout.vChewingMiTAC":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
static let arrDynamicBasicKeyLayout: [String] = [
|
||||
"com.apple.keylayout.ZhuyinBopomofo",
|
||||
"com.apple.keylayout.ZhuyinEten",
|
||||
"org.atelierInmu.vChewing.keyLayouts.vchewingdachen",
|
||||
"org.atelierInmu.vChewing.keyLayouts.vchewingmitac",
|
||||
"org.atelierInmu.vChewing.keyLayouts.vchewingibm",
|
||||
"org.atelierInmu.vChewing.keyLayouts.vchewingseigyou",
|
||||
"org.atelierInmu.vChewing.keyLayouts.vchewingeten",
|
||||
"org.unknown.keylayout.vChewingDachen",
|
||||
"org.unknown.keylayout.vChewingFakeSeigyou",
|
||||
"org.unknown.keylayout.vChewingETen",
|
||||
"org.unknown.keylayout.vChewingIBM",
|
||||
"org.unknown.keylayout.vChewingMiTAC",
|
||||
]
|
||||
@objc class func isDynamicBasicKeyboardLayoutEnabled() -> Bool {
|
||||
return AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout)
|
||||
}
|
||||
// 處理 Apple 注音鍵盤佈局類型。
|
||||
@objc class func cnvApple2ABC(_ charCode: UniChar) -> UniChar {
|
||||
var charCode = charCode
|
||||
// 在按鍵資訊被送往 OVMandarin 之前,先轉換為可以被 OVMandarin 正常處理的資訊。
|
||||
if self.isDynamicBaseKeyboardLayoutEnabled() {
|
||||
if self.isDynamicBasicKeyboardLayoutEnabled() {
|
||||
// 針對不同的 Apple 動態鍵盤佈局糾正大寫英文輸入。
|
||||
switch mgrPrefs.basisKeyboardLayout {
|
||||
switch mgrPrefs.basicKeyboardLayout {
|
||||
case "com.apple.keylayout.ZhuyinBopomofo":
|
||||
do {
|
||||
if charCode == 97 { charCode = UniChar(65) }
|
||||
|
@ -186,7 +173,7 @@ import Cocoa
|
|||
// 摁了 Alt 的符號。
|
||||
if charCode == 8212 { charCode = UniChar(45) }
|
||||
// Apple 倚天注音佈局追加符號糾正項目。
|
||||
if mgrPrefs.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
|
||||
if mgrPrefs.basicKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
|
||||
if charCode == 65343 { charCode = UniChar(95) }
|
||||
if charCode == 65306 { charCode = UniChar(58) }
|
||||
if charCode == 65311 { charCode = UniChar(63) }
|
||||
|
@ -199,9 +186,9 @@ import Cocoa
|
|||
|
||||
@objc class func cnvStringApple2ABC(_ strProcessed: String) -> String {
|
||||
var strProcessed = strProcessed
|
||||
if self.isDynamicBaseKeyboardLayoutEnabled() {
|
||||
if self.isDynamicBasicKeyboardLayoutEnabled() {
|
||||
// 針對不同的 Apple 動態鍵盤佈局糾正大寫英文輸入。
|
||||
switch mgrPrefs.basisKeyboardLayout {
|
||||
switch mgrPrefs.basicKeyboardLayout {
|
||||
case "com.apple.keylayout.ZhuyinBopomofo":
|
||||
do {
|
||||
if strProcessed == "a" { strProcessed = "A" }
|
||||
|
@ -326,7 +313,7 @@ import Cocoa
|
|||
// 摁了 Alt 的符號。
|
||||
if strProcessed == "—" { strProcessed = "-" }
|
||||
// Apple 倚天注音佈局追加符號糾正項目。
|
||||
if mgrPrefs.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
|
||||
if mgrPrefs.basicKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
|
||||
if strProcessed == "_" { strProcessed = "_" }
|
||||
if strProcessed == ":" { strProcessed = ":" }
|
||||
if strProcessed == "?" { strProcessed = "?" }
|
||||
|
|
|
@ -46,9 +46,7 @@ static double FindHighestScore(const std::vector<Gramambular::NodeAnchor> &nodes
|
|||
{
|
||||
double score = ni->node->highestUnigramScore();
|
||||
if (score > highestScore)
|
||||
{
|
||||
highestScore = score;
|
||||
}
|
||||
}
|
||||
return highestScore + epsilon;
|
||||
}
|
||||
|
@ -98,14 +96,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
|
||||
- (BOOL)isBuilderEmpty
|
||||
{
|
||||
if (_builder->grid().width() == 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return (_builder->grid().width() == 0);
|
||||
}
|
||||
|
||||
- (void)setInputMode:(NSString *)value
|
||||
|
@ -114,25 +105,17 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
vChewing::LMInstantiator *newLanguageModel;
|
||||
vChewing::UserOverrideModel *newUserOverrideModel;
|
||||
|
||||
if ([value isKindOfClass:[NSString class]] && [value isEqual:imeModeCHS])
|
||||
{
|
||||
newInputMode = imeModeCHS;
|
||||
newLanguageModel = [mgrLangModel lmCHS];
|
||||
newUserOverrideModel = [mgrLangModel userOverrideModelCHS];
|
||||
}
|
||||
else
|
||||
{
|
||||
newInputMode = imeModeCHT;
|
||||
newLanguageModel = [mgrLangModel lmCHT];
|
||||
newUserOverrideModel = [mgrLangModel userOverrideModelCHT];
|
||||
}
|
||||
BOOL isCHS = [value isKindOfClass:[NSString class]] && [value isEqual:imeModeCHS];
|
||||
|
||||
newInputMode = isCHS ? imeModeCHS : imeModeCHT;
|
||||
newLanguageModel = isCHS ? [mgrLangModel lmCHS] : [mgrLangModel lmCHT];
|
||||
newUserOverrideModel = isCHS ? [mgrLangModel userOverrideModelCHS] : [mgrLangModel userOverrideModelCHT];
|
||||
|
||||
// Report the current Input Mode to ctlInputMethod:
|
||||
ctlInputMethod.currentInputMode = newInputMode;
|
||||
|
||||
// Synchronize the Preference Setting "setPhraseReplacementEnabled" to the new LM.
|
||||
// Synchronize the sub-languageModel state settings to the new LM.
|
||||
newLanguageModel->setPhraseReplacementEnabled(mgrPrefs.phraseReplacementEnabled);
|
||||
// Also other sub language models:
|
||||
newLanguageModel->setSymbolEnabled(mgrPrefs.symbolInputEnabled);
|
||||
newLanguageModel->setCNSEnabled(mgrPrefs.cns11643Enabled);
|
||||
|
||||
|
@ -151,24 +134,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
}
|
||||
|
||||
if (!_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
_bpmfReadingBuffer->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
// clean up everything
|
||||
{ // clean up everything
|
||||
if (_bpmfReadingBuffer)
|
||||
{
|
||||
delete _bpmfReadingBuffer;
|
||||
}
|
||||
|
||||
if (_builder)
|
||||
{
|
||||
delete _builder;
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
|
@ -196,36 +171,35 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
|
||||
- (void)syncWithPreferences
|
||||
{
|
||||
NSInteger layout = mgrPrefs.keyboardLayout;
|
||||
switch (layout)
|
||||
switch (mgrPrefs.mandarinParser)
|
||||
{
|
||||
case KeyboardLayoutOfStandard:
|
||||
case MandarinParserOfStandard:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout());
|
||||
break;
|
||||
case KeyboardLayoutOfEten:
|
||||
case MandarinParserOfEten:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETenLayout());
|
||||
break;
|
||||
case KeyboardLayoutOfHsu:
|
||||
case MandarinParserOfHsu:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HsuLayout());
|
||||
break;
|
||||
case KeyboardLayoutOfEen26:
|
||||
case MandarinParserOfEen26:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETen26Layout());
|
||||
break;
|
||||
case KeyboardLayoutOfIBM:
|
||||
case MandarinParserOfIBM:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::IBMLayout());
|
||||
break;
|
||||
case KeyboardLayoutOfMiTAC:
|
||||
case MandarinParserOfMiTAC:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::MiTACLayout());
|
||||
break;
|
||||
case KeyboardLayoutOfFakeSeigyou:
|
||||
case MandarinParserOfFakeSeigyou:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::FakeSeigyouLayout());
|
||||
break;
|
||||
case KeyboardLayoutOfHanyuPinyin:
|
||||
case MandarinParserOfHanyuPinyin:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HanyuPinyinLayout());
|
||||
break;
|
||||
default:
|
||||
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout());
|
||||
mgrPrefs.keyboardLayout = KeyboardLayoutOfStandard;
|
||||
mgrPrefs.mandarinParser = MandarinParserOfStandard;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,21 +215,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
// in the user override model.
|
||||
BOOL addToOverrideModel = YES;
|
||||
if (selectedNode.spanningLength != [value count])
|
||||
{
|
||||
addToOverrideModel = NO;
|
||||
}
|
||||
|
||||
if (addToOverrideModel)
|
||||
{
|
||||
double score = selectedNode.node->scoreForCandidate(stringValue);
|
||||
if (score <= -12)
|
||||
{ // 威注音的 SymbolLM 的 Score 是 -12。
|
||||
if (score <= -12) // 威注音的 SymbolLM 的 Score 是 -12。
|
||||
addToOverrideModel = NO;
|
||||
}
|
||||
}
|
||||
if (addToOverrideModel)
|
||||
{
|
||||
_userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]);
|
||||
}
|
||||
}
|
||||
[self _walk];
|
||||
|
||||
|
@ -265,15 +234,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
for (auto node : _walkedNodes)
|
||||
{
|
||||
if (nextPosition >= cursorIndex)
|
||||
{
|
||||
break;
|
||||
}
|
||||
nextPosition += node.spanningLength;
|
||||
}
|
||||
if (nextPosition <= _builder->length())
|
||||
{
|
||||
_builder->setCursorIndex(nextPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,13 +249,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
_walkedNodes.clear();
|
||||
}
|
||||
|
||||
- (std::string)_currentLayout
|
||||
- (std::string)_currentMandarinParser
|
||||
{
|
||||
NSString *keyboardLayoutName = mgrPrefs.keyboardLayoutName;
|
||||
std::string layout = std::string(keyboardLayoutName.UTF8String) + std::string("_");
|
||||
return layout;
|
||||
return std::string(mgrPrefs.mandarinParserName.UTF8String) + std::string("_");
|
||||
}
|
||||
|
||||
// MARK: - Handling Input
|
||||
|
||||
- (BOOL)handleInput:(keyParser *)input
|
||||
state:(InputState *)inState
|
||||
stateCallback:(void (^)(InputState *))stateCallback
|
||||
|
@ -302,18 +267,14 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
|
||||
// if the inputText is empty, it's a function key combination, we ignore it
|
||||
if (!input.inputText.length)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it
|
||||
BOOL isFunctionKey =
|
||||
([input isCommandHold] || [input isOptionHotKey] || [input isNumericPad]) || [input isControlHotKey];
|
||||
if (![state isKindOfClass:[InputStateNotEmpty class]] &&
|
||||
![state isKindOfClass:[InputStateAssociatedPhrases class]] && isFunctionKey)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Caps Lock processing: if Caps Lock is ON, temporarily disable bopomofo.
|
||||
// Note: Alphanumerical mode processing.
|
||||
|
@ -331,16 +292,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
|
||||
// When shift is pressed, don't do further processing, since it outputs capital letter anyway.
|
||||
if ([input isShiftHold])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// if ASCII but not printable, don't use insertText:replacementRange: as many apps don't handle non-ASCII char
|
||||
// insertions.
|
||||
if (charCode < 0x80 && !isprint(charCode))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// commit everything in the buffer.
|
||||
InputStateCommitting *committingState =
|
||||
|
@ -369,9 +326,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
|
||||
// MARK: Handle Candidates
|
||||
if ([state isKindOfClass:[InputStateChoosingCandidate class]])
|
||||
{
|
||||
return [self _handleCandidateState:state input:input stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Handle Associated Phrases
|
||||
if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
|
||||
|
@ -381,9 +336,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback];
|
||||
if (result)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
stateCallback(state);
|
||||
}
|
||||
|
@ -396,9 +349,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
input:input
|
||||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
state = [marking convertToInputting];
|
||||
stateCallback(state);
|
||||
}
|
||||
|
@ -493,9 +444,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
(InputStateAssociatedPhrases *)[self buildAssociatePhraseStateWithKey:text
|
||||
useVerticalMode:input.useVerticalMode];
|
||||
if (associatedPhrases)
|
||||
{
|
||||
stateCallback(associatedPhrases);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputStateEmpty *empty = [[InputStateEmpty alloc] init];
|
||||
|
@ -504,9 +453,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stateCallback(choosingCandidates);
|
||||
}
|
||||
}
|
||||
|
||||
// and tells the client that the key is consumed
|
||||
|
@ -558,82 +505,54 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
|
||||
// MARK: Esc
|
||||
if ([input isESC])
|
||||
{
|
||||
return [self _handleEscWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Cursor backward
|
||||
if ([input isCursorBackward] || emacsKey == vChewingEmacsKeyBackward)
|
||||
{
|
||||
return [self _handleBackwardWithState:state
|
||||
input:input
|
||||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Cursor forward
|
||||
if ([input isCursorForward] || emacsKey == vChewingEmacsKeyForward)
|
||||
{
|
||||
return [self _handleForwardWithState:state input:input stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Home
|
||||
if ([input isHome] || emacsKey == vChewingEmacsKeyHome)
|
||||
{
|
||||
return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: End
|
||||
if ([input isEnd] || emacsKey == vChewingEmacsKeyEnd)
|
||||
{
|
||||
return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Ctrl+PgLf or Shift+PgLf
|
||||
if ([input isControlHold] || [input isShiftHold])
|
||||
{
|
||||
if ([input isOptionHold] && [input isLeft])
|
||||
{
|
||||
return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
}
|
||||
if (([input isControlHold] || [input isShiftHold]) && ([input isOptionHold] && [input isLeft]))
|
||||
return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
|
||||
// MARK: Ctrl+PgRt or Shift+PgRt
|
||||
if ([input isControlHold] || [input isShiftHold])
|
||||
{
|
||||
if ([input isOptionHold] && [input isRight])
|
||||
{
|
||||
return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
}
|
||||
if (([input isControlHold] || [input isShiftHold]) && ([input isOptionHold] && [input isRight]))
|
||||
return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
|
||||
// MARK: AbsorbedArrowKey
|
||||
if ([input isAbsorbedArrowKey] || [input isExtraChooseCandidateKey] || [input isExtraChooseCandidateKeyReverse])
|
||||
{
|
||||
return [self _handleAbsorbedArrowKeyWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Backspace
|
||||
if ([input isBackSpace])
|
||||
{
|
||||
return [self _handleBackspaceWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Delete
|
||||
if ([input isDelete] || emacsKey == vChewingEmacsKeyDelete)
|
||||
{
|
||||
return [self _handleDeleteWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Enter
|
||||
if ([input isEnter])
|
||||
{
|
||||
return ([input isControlHold] && [input isCommandHold])
|
||||
? [self _handleCtrlCommandEnterWithState:state
|
||||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback]
|
||||
: [self _handleEnterWithState:state stateCallback:stateCallback errorCallback:errorCallback];
|
||||
}
|
||||
|
||||
// MARK: Punctuation list
|
||||
if ([input isSymbolMenuPhysicalKey] && ![input isShiftHold])
|
||||
|
@ -679,32 +598,24 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
// if nothing is matched, see if it's a punctuation key for current layout.
|
||||
|
||||
std::string punctuationNamePrefix;
|
||||
|
||||
if ([input isOptionHold])
|
||||
{
|
||||
punctuationNamePrefix = std::string("_alt_punctuation_");
|
||||
}
|
||||
else if ([input isControlHold])
|
||||
{
|
||||
punctuationNamePrefix = std::string("_ctrl_punctuation_");
|
||||
}
|
||||
else if (mgrPrefs.halfWidthPunctuationEnabled)
|
||||
{
|
||||
punctuationNamePrefix = std::string("_half_punctuation_");
|
||||
}
|
||||
else
|
||||
{
|
||||
punctuationNamePrefix = std::string("_punctuation_");
|
||||
}
|
||||
std::string layout = [self _currentLayout];
|
||||
std::string customPunctuation = punctuationNamePrefix + layout + std::string(1, (char)charCode);
|
||||
|
||||
std::string parser = [self _currentMandarinParser];
|
||||
std::string customPunctuation = punctuationNamePrefix + parser + std::string(1, (char)charCode);
|
||||
if ([self _handlePunctuation:customPunctuation
|
||||
state:state
|
||||
usingVerticalMode:input.useVerticalMode
|
||||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
// if nothing is matched, see if it's a punctuation key.
|
||||
std::string punctuation = punctuationNamePrefix + std::string(1, (char)charCode);
|
||||
|
@ -713,9 +624,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
usingVerticalMode:input.useVerticalMode
|
||||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
// Lukhnos 這裡的處理反而會使得 Apple 倚天注音動態鍵盤佈局「敲不了半形大寫英文」的缺點曝露無疑,所以注釋掉。
|
||||
// 至於他試圖用這種處理來解決的上游 UPR293
|
||||
|
@ -728,9 +637,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
usingVerticalMode:input.useVerticalMode
|
||||
stateCallback:stateCallback
|
||||
errorCallback:errorCallback])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
// still nothing, then we update the composing buffer (some app has strange behavior if we don't do this, "thinking"
|
||||
|
@ -754,9 +661,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL escToClearInputBufferEnabled = mgrPrefs.escToCleanInputBuffer;
|
||||
|
||||
|
@ -800,9 +705,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -859,9 +762,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -917,9 +818,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -950,9 +849,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -983,9 +880,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -1001,9 +896,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -1021,9 +914,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_bpmfReadingBuffer->backspace();
|
||||
}
|
||||
|
||||
if (_bpmfReadingBuffer->isEmpty() && !_builder->length())
|
||||
{
|
||||
|
@ -1043,9 +934,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (_bpmfReadingBuffer->isEmpty())
|
||||
{
|
||||
|
@ -1106,9 +995,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (![state isKindOfClass:[InputStateInputting class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
[self clear];
|
||||
|
||||
|
@ -1128,9 +1015,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (!_languageModel->hasUnigramsForKey(customPunctuation))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSString *poppedText;
|
||||
if (_bpmfReadingBuffer->isEmpty())
|
||||
|
@ -1165,9 +1050,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
stateCallback(empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
stateCallback(candidateState);
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
@ -1218,9 +1101,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
stateCallback(inputting);
|
||||
}
|
||||
else
|
||||
{
|
||||
stateCallback(marking);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1249,9 +1130,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
stateCallback(inputting);
|
||||
}
|
||||
else
|
||||
{
|
||||
stateCallback(marking);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1495,9 +1374,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
ctlCandidateCurrent.selectedCandidateIndex = 0;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
@ -1505,18 +1382,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
NSArray *candidates;
|
||||
|
||||
if ([state isKindOfClass:[InputStateChoosingCandidate class]])
|
||||
{
|
||||
candidates = [(InputStateChoosingCandidate *)state candidates];
|
||||
}
|
||||
else if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
|
||||
{
|
||||
candidates = [(InputStateAssociatedPhrases *)state candidates];
|
||||
}
|
||||
|
||||
if (!candidates)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (([input isEnd] || input.emacsKey == vChewingEmacsKeyEnd) && candidates.count > 0)
|
||||
{
|
||||
|
@ -1526,30 +1397,23 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
errorCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
ctlCandidateCurrent.selectedCandidateIndex = candidates.count - 1;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
|
||||
{
|
||||
if (![input isShiftHold])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
NSInteger index = NSNotFound;
|
||||
NSString *match;
|
||||
if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
|
||||
{
|
||||
match = input.inputTextIgnoringModifiers;
|
||||
}
|
||||
else
|
||||
{
|
||||
match = inputText;
|
||||
}
|
||||
|
||||
for (NSUInteger j = 0, c = [ctlCandidateCurrent.keyLabels count]; j < c; j++)
|
||||
{
|
||||
|
@ -1572,31 +1436,22 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
}
|
||||
|
||||
if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (mgrPrefs.useSCPCTypingMode)
|
||||
{
|
||||
std::string layout = [self _currentLayout];
|
||||
std::string punctuationNamePrefix;
|
||||
if ([input isOptionHold])
|
||||
{
|
||||
punctuationNamePrefix = std::string("_alt_punctuation_");
|
||||
}
|
||||
else if ([input isControlHold])
|
||||
{
|
||||
punctuationNamePrefix = std::string("_ctrl_punctuation_");
|
||||
}
|
||||
else if (mgrPrefs.halfWidthPunctuationEnabled)
|
||||
{
|
||||
punctuationNamePrefix = std::string("_half_punctuation_");
|
||||
}
|
||||
else
|
||||
{
|
||||
punctuationNamePrefix = std::string("_punctuation_");
|
||||
}
|
||||
std::string customPunctuation = punctuationNamePrefix + layout + std::string(1, (char)charCode);
|
||||
|
||||
std::string parser = [self _currentMandarinParser];
|
||||
std::string customPunctuation = punctuationNamePrefix + parser + std::string(1, (char)charCode);
|
||||
std::string punctuation = punctuationNamePrefix + std::string(1, (char)charCode);
|
||||
|
||||
BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char)charCode) ||
|
||||
|
@ -1607,9 +1462,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
{
|
||||
std::string letter = std::string("_letter_") + std::string(1, (char)charCode);
|
||||
if (_languageModel->hasUnigramsForKey(letter))
|
||||
{
|
||||
shouldAutoSelectCandidate = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldAutoSelectCandidate)
|
||||
|
@ -1813,9 +1666,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
const std::vector<Gramambular::KeyValuePair> &candidates = (*ni).node->candidates();
|
||||
for (std::vector<Gramambular::KeyValuePair>::const_iterator ci = candidates.begin(), ce = candidates.end();
|
||||
ci != ce; ++ci)
|
||||
{
|
||||
[candidatesArray addObject:[NSString stringWithUTF8String:(*ci).value.c_str()]];
|
||||
}
|
||||
}
|
||||
|
||||
InputStateChoosingCandidate *state =
|
||||
|
@ -1831,9 +1682,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
size_t cursorIndex = _builder->cursorIndex();
|
||||
// MS Phonetics IME style, phrase is *after* the cursor, i.e. cursor is always *before* the phrase
|
||||
if ((mgrPrefs.selectPhraseAfterCursorAsCandidate && (cursorIndex < _builder->length())) || !cursorIndex)
|
||||
{
|
||||
++cursorIndex;
|
||||
}
|
||||
|
||||
return cursorIndex;
|
||||
}
|
||||
|
@ -1843,9 +1692,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
NSMutableArray *readingsArray = [[NSMutableArray alloc] init];
|
||||
std::vector<std::string> v = _builder->readings();
|
||||
for (std::vector<std::string>::iterator it_i = v.begin(); it_i != v.end(); ++it_i)
|
||||
{
|
||||
[readingsArray addObject:[NSString stringWithUTF8String:it_i->c_str()]];
|
||||
}
|
||||
return readingsArray;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class ctlInputMethod: IMKInputController {
|
|||
|
||||
@objc func setKeyLayout() {
|
||||
let client = client().self as IMKTextInput
|
||||
client.overrideKeyboard(withKeyboardNamed: mgrPrefs.basisKeyboardLayout)
|
||||
client.overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
|
||||
}
|
||||
|
||||
// MARK: - IMKInputController methods
|
||||
|
|
|
@ -30,8 +30,8 @@ struct UserDef {
|
|||
static let kIsDebugModeEnabled = "_DebugMode"
|
||||
static let kUserDataFolderSpecified = "UserDataFolderSpecified"
|
||||
static let kCheckUpdateAutomatically = "CheckUpdateAutomatically"
|
||||
static let kKeyboardLayout = "KeyboardLayout"
|
||||
static let kBasisKeyboardLayout = "BasisKeyboardLayout"
|
||||
static let kMandarinParser = "MandarinParser"
|
||||
static let kBasicKeyboardLayout = "BasicKeyboardLayout"
|
||||
static let kShowPageButtonsInCandidateWindow = "ShowPageButtonsInCandidateWindow"
|
||||
static let kCandidateListTextSize = "CandidateListTextSize"
|
||||
static let kAppleLanguages = "AppleLanguages"
|
||||
|
@ -167,7 +167,7 @@ struct ComposingBufferSize {
|
|||
|
||||
// MARK: -
|
||||
|
||||
@objc enum KeyboardLayout: Int {
|
||||
@objc enum MandarinParser: Int {
|
||||
case ofStandard = 0
|
||||
case ofEten = 1
|
||||
case ofHsu = 2
|
||||
|
@ -205,8 +205,8 @@ struct ComposingBufferSize {
|
|||
[
|
||||
UserDef.kIsDebugModeEnabled,
|
||||
UserDef.kUserDataFolderSpecified,
|
||||
UserDef.kKeyboardLayout,
|
||||
UserDef.kBasisKeyboardLayout,
|
||||
UserDef.kMandarinParser,
|
||||
UserDef.kBasicKeyboardLayout,
|
||||
UserDef.kShowPageButtonsInCandidateWindow,
|
||||
UserDef.kCandidateListTextSize,
|
||||
UserDef.kAppleLanguages,
|
||||
|
@ -289,16 +289,16 @@ struct ComposingBufferSize {
|
|||
@UserDefault(key: UserDef.kAppleLanguages, defaultValue: [])
|
||||
@objc static var appleLanguages: [String]
|
||||
|
||||
@UserDefault(key: UserDef.kKeyboardLayout, defaultValue: 0)
|
||||
@objc static var keyboardLayout: Int
|
||||
@UserDefault(key: UserDef.kMandarinParser, defaultValue: 0)
|
||||
@objc static var mandarinParser: Int
|
||||
|
||||
@objc static var keyboardLayoutName: String {
|
||||
(KeyboardLayout(rawValue: self.keyboardLayout) ?? KeyboardLayout.ofStandard).name
|
||||
@objc static var mandarinParserName: String {
|
||||
(MandarinParser(rawValue: self.mandarinParser) ?? MandarinParser.ofStandard).name
|
||||
}
|
||||
|
||||
@UserDefault(
|
||||
key: UserDef.kBasisKeyboardLayout, defaultValue: "com.apple.keylayout.ZhuyinBopomofo")
|
||||
@objc static var basisKeyboardLayout: String
|
||||
key: UserDef.kBasicKeyboardLayout, defaultValue: "com.apple.keylayout.ZhuyinBopomofo")
|
||||
@objc static var basicKeyboardLayout: String
|
||||
|
||||
@UserDefault(key: UserDef.kShowPageButtonsInCandidateWindow, defaultValue: true)
|
||||
@objc static var showPageButtonsInCandidateWindow: Bool
|
||||
|
|
|
@ -33,7 +33,7 @@ import Cocoa
|
|||
@objc(ctlPrefWindow) class ctlPrefWindow: NSWindowController {
|
||||
@IBOutlet weak var fontSizePopUpButton: NSPopUpButton!
|
||||
@IBOutlet weak var uiLanguageButton: NSPopUpButton!
|
||||
@IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton!
|
||||
@IBOutlet weak var basicKeyboardLayoutButton: NSPopUpButton!
|
||||
@IBOutlet weak var selectionKeyComboBox: NSComboBox!
|
||||
@IBOutlet weak var chkTrad2KangXi: NSButton!
|
||||
@IBOutlet weak var chkTrad2JISShinjitai: NSButton!
|
||||
|
@ -77,22 +77,22 @@ import Cocoa
|
|||
var usKeyboardLayoutItem: NSMenuItem? = nil
|
||||
var chosenBaseKeyboardLayoutItem: NSMenuItem? = nil
|
||||
|
||||
basisKeyboardLayoutButton.menu?.removeAllItems()
|
||||
basicKeyboardLayoutButton.menu?.removeAllItems()
|
||||
|
||||
let itmAppleZhuyinBopomofo = NSMenuItem()
|
||||
itmAppleZhuyinBopomofo.title = String(
|
||||
format: NSLocalizedString("Apple Zhuyin Bopomofo (Dachen)", comment: ""))
|
||||
itmAppleZhuyinBopomofo.representedObject = String(
|
||||
"com.apple.keylayout.ZhuyinBopomofo")
|
||||
basisKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinBopomofo)
|
||||
basicKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinBopomofo)
|
||||
|
||||
let itmAppleZhuyinEten = NSMenuItem()
|
||||
itmAppleZhuyinEten.title = String(
|
||||
format: NSLocalizedString("Apple Zhuyin Eten (Traditional)", comment: ""))
|
||||
itmAppleZhuyinEten.representedObject = String("com.apple.keylayout.ZhuyinEten")
|
||||
basisKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinEten)
|
||||
basicKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinEten)
|
||||
|
||||
let basisKeyboardLayoutID = mgrPrefs.basisKeyboardLayout
|
||||
let basicKeyboardLayoutID = mgrPrefs.basicKeyboardLayout
|
||||
|
||||
for source in list {
|
||||
if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) {
|
||||
|
@ -142,13 +142,13 @@ import Cocoa
|
|||
if sourceID == "com.apple.keylayout.US" {
|
||||
usKeyboardLayoutItem = menuItem
|
||||
}
|
||||
if basisKeyboardLayoutID == sourceID {
|
||||
if basicKeyboardLayoutID == sourceID {
|
||||
chosenBaseKeyboardLayoutItem = menuItem
|
||||
}
|
||||
basisKeyboardLayoutButton.menu?.addItem(menuItem)
|
||||
basicKeyboardLayoutButton.menu?.addItem(menuItem)
|
||||
}
|
||||
|
||||
switch basisKeyboardLayoutID {
|
||||
switch basicKeyboardLayoutID {
|
||||
case "com.apple.keylayout.ZhuyinBopomofo":
|
||||
chosenBaseKeyboardLayoutItem = itmAppleZhuyinBopomofo
|
||||
case "com.apple.keylayout.ZhuyinEten":
|
||||
|
@ -157,7 +157,7 @@ import Cocoa
|
|||
break // nothing to do
|
||||
}
|
||||
|
||||
basisKeyboardLayoutButton.select(chosenBaseKeyboardLayoutItem ?? usKeyboardLayoutItem)
|
||||
basicKeyboardLayoutButton.select(chosenBaseKeyboardLayoutItem ?? usKeyboardLayoutItem)
|
||||
|
||||
selectionKeyComboBox.usesDataSource = false
|
||||
selectionKeyComboBox.removeAllItems()
|
||||
|
@ -193,9 +193,9 @@ import Cocoa
|
|||
}
|
||||
}
|
||||
|
||||
@IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) {
|
||||
if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject as? String {
|
||||
mgrPrefs.basisKeyboardLayout = sourceID
|
||||
@IBAction func updateBasicKeyboardLayoutAction(_ sender: Any) {
|
||||
if let sourceID = basicKeyboardLayoutButton.selectedItem?.representedObject as? String {
|
||||
mgrPrefs.basicKeyboardLayout = sourceID
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="ctlPrefWindow">
|
||||
<connections>
|
||||
<outlet property="basisKeyboardLayoutButton" destination="124" id="135"/>
|
||||
<outlet property="basicKeyboardLayoutButton" destination="124" id="135"/>
|
||||
<outlet property="chkTrad2JISShinjitai" destination="h4r-Sp-LBI" id="pk8-xi-IJi"/>
|
||||
<outlet property="chkTrad2KangXi" destination="5IL-zZ-CL9" id="PGS-Dy-BBY"/>
|
||||
<outlet property="fontSizePopUpButton" destination="90" id="108"/>
|
||||
|
@ -764,7 +764,7 @@
|
|||
</items>
|
||||
</menu>
|
||||
<connections>
|
||||
<binding destination="32" name="selectedTag" keyPath="values.KeyboardLayout" id="103"/>
|
||||
<binding destination="32" name="selectedTag" keyPath="values.MandarinParser" id="n3r-9x-E3p"/>
|
||||
</connections>
|
||||
</popUpButtonCell>
|
||||
</popUpButton>
|
||||
|
@ -779,7 +779,7 @@
|
|||
<menu key="menu" title="OtherViews" id="128"/>
|
||||
</popUpButtonCell>
|
||||
<connections>
|
||||
<action selector="updateBasisKeyboardLayoutAction:" target="-2" id="136"/>
|
||||
<action selector="updateBasicKeyboardLayoutAction:" target="-2" id="136"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="125">
|
||||
|
|
Loading…
Reference in New Issue