Zonble: Typing Alphabetic Contents to the Buffer.
Co-Authored-By: Weizhong Yang a.k.a zonble <zonble@gmail.com>
This commit is contained in:
parent
54e812cf2b
commit
8d79dcee79
|
@ -154,6 +154,10 @@ const vector<Unigram> vChewingLM::unigramsForKey(const string& key)
|
||||||
|
|
||||||
bool vChewingLM::hasUnigramsForKey(const string& key)
|
bool vChewingLM::hasUnigramsForKey(const string& key)
|
||||||
{
|
{
|
||||||
|
if (key == " ") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_excludedPhrases.hasUnigramsForKey(key)) {
|
if (!m_excludedPhrases.hasUnigramsForKey(key)) {
|
||||||
return m_userPhrases.hasUnigramsForKey(key) ||
|
return m_userPhrases.hasUnigramsForKey(key) ||
|
||||||
m_languageModel.hasUnigramsForKey(key);
|
m_languageModel.hasUnigramsForKey(key);
|
||||||
|
|
|
@ -160,7 +160,7 @@ static double FindHighestScore(const vector<NodeAnchor>& nodes, double epsilon)
|
||||||
- (NSMenu *)menu
|
- (NSMenu *)menu
|
||||||
{
|
{
|
||||||
// Define the case which ALT / Option key is pressed.
|
// Define the case which ALT / Option key is pressed.
|
||||||
BOOL optionKeyPressed = [[NSEvent class] respondsToSelector:@selector(modifierFlags)] && ([NSEvent modifierFlags] & NSAlternateKeyMask);
|
BOOL optionKeyPressed = [[NSEvent class] respondsToSelector:@selector(modifierFlags)] && ([NSEvent modifierFlags] & NSEventModifierFlagOption);
|
||||||
|
|
||||||
// a menu instance (autoreleased) is requested every time the user click on the input menu
|
// a menu instance (autoreleased) is requested every time the user click on the input menu
|
||||||
NSMenu *menu = [[NSMenu alloc] initWithTitle:LocalizationNotNeeded(@"Input Method Menu")];
|
NSMenu *menu = [[NSMenu alloc] initWithTitle:LocalizationNotNeeded(@"Input Method Menu")];
|
||||||
|
@ -550,10 +550,10 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
|
|
||||||
// if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it
|
// if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it
|
||||||
if (![_composingBuffer length] &&
|
if (![_composingBuffer length] &&
|
||||||
_bpmfReadingBuffer->isEmpty() &&
|
_bpmfReadingBuffer->isEmpty() &&
|
||||||
((flags & NSCommandKeyMask) || (flags & NSControlKeyMask) || (flags & NSAlternateKeyMask) || (flags & NSNumericPadKeyMask))) {
|
((flags & NSEventModifierFlagCommand) || (flags & NSEventModifierFlagControl) || (flags & NSEventModifierFlagOption) || (flags & NSEventModifierFlagNumericPad))) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caps Lock processing : if Caps Lock is on, temporarily disable bopomofo.
|
// Caps Lock processing : if Caps Lock is on, temporarily disable bopomofo.
|
||||||
if (charCode == 8 || charCode == 13 || keyCode == absorbedArrowKey || keyCode == extraChooseCandidateKey || keyCode == cursorForwardKey || keyCode == cursorBackwardKey) {
|
if (charCode == 8 || charCode == 13 || keyCode == absorbedArrowKey || keyCode == extraChooseCandidateKey || keyCode == cursorForwardKey || keyCode == cursorBackwardKey) {
|
||||||
|
@ -566,7 +566,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// first commit everything in the buffer.
|
// first commit everything in the buffer.
|
||||||
if (flags & NSShiftKeyMask) {
|
if (flags & NSEventModifierFlagShift) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & NSNumericPadKeyMask) {
|
if (flags & NSEventModifierFlagNumericPad) {
|
||||||
if (keyCode != kLeftKeyCode && keyCode != kRightKeyCode && keyCode != kDownKeyCode && keyCode != kUpKeyCode && charCode != 32 && isprint(charCode)) {
|
if (keyCode != kLeftKeyCode && keyCode != kRightKeyCode && keyCode != kDownKeyCode && keyCode != kUpKeyCode && charCode != 32 && isprint(charCode)) {
|
||||||
if ([_composingBuffer length]) {
|
if ([_composingBuffer length]) {
|
||||||
[self commitComposition:client];
|
[self commitComposition:client];
|
||||||
|
@ -619,7 +619,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
}
|
}
|
||||||
// Shift + left
|
// Shift + left
|
||||||
if ((keyCode == cursorBackwardKey || emacsKey == vChewingEmacsKeyBackward)
|
if ((keyCode == cursorBackwardKey || emacsKey == vChewingEmacsKeyBackward)
|
||||||
&& (flags & NSShiftKeyMask)) {
|
&& (flags & NSEventModifierFlagShift)) {
|
||||||
if (_builder->markerCursorIndex() > 0) {
|
if (_builder->markerCursorIndex() > 0) {
|
||||||
_builder->setMarkerCursorIndex(_builder->markerCursorIndex() - 1);
|
_builder->setMarkerCursorIndex(_builder->markerCursorIndex() - 1);
|
||||||
}
|
}
|
||||||
|
@ -631,7 +631,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
}
|
}
|
||||||
// Shift + Right
|
// Shift + Right
|
||||||
if ((keyCode == cursorForwardKey || emacsKey == vChewingEmacsKeyForward)
|
if ((keyCode == cursorForwardKey || emacsKey == vChewingEmacsKeyForward)
|
||||||
&& (flags & NSShiftKeyMask)) {
|
&& (flags & NSEventModifierFlagShift)) {
|
||||||
if (_builder->markerCursorIndex() < _builder->length()) {
|
if (_builder->markerCursorIndex() < _builder->length()) {
|
||||||
_builder->setMarkerCursorIndex(_builder->markerCursorIndex() + 1);
|
_builder->setMarkerCursorIndex(_builder->markerCursorIndex() + 1);
|
||||||
}
|
}
|
||||||
|
@ -706,7 +706,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
if (_bpmfReadingBuffer->isEmpty() && [_composingBuffer length] > 0 && (keyCode == extraChooseCandidateKey || charCode == 32 || (useVerticalMode && (keyCode == verticalModeOnlyChooseCandidateKey)))) {
|
if (_bpmfReadingBuffer->isEmpty() && [_composingBuffer length] > 0 && (keyCode == extraChooseCandidateKey || charCode == 32 || (useVerticalMode && (keyCode == verticalModeOnlyChooseCandidateKey)))) {
|
||||||
if (charCode == 32) {
|
if (charCode == 32) {
|
||||||
// if the spacebar is NOT set to be a selection key
|
// if the spacebar is NOT set to be a selection key
|
||||||
if (!Preferences.chooseCandidateUsingSpace) {
|
if ((flags & NSEventModifierFlagShift) != 0 || !Preferences.chooseCandidateUsingSpace) {
|
||||||
if (_builder->cursorIndex() >= _builder->length()) {
|
if (_builder->cursorIndex() >= _builder->length()) {
|
||||||
[_composingBuffer appendString:@" "];
|
[_composingBuffer appendString:@" "];
|
||||||
[self commitComposition:client];
|
[self commitComposition:client];
|
||||||
|
@ -773,7 +773,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & NSShiftKeyMask) {
|
if (flags & NSEventModifierFlagShift) {
|
||||||
// Shift + left
|
// Shift + left
|
||||||
if (_builder->cursorIndex() > 0) {
|
if (_builder->cursorIndex() > 0) {
|
||||||
_builder->setMarkerCursorIndex(_builder->cursorIndex() - 1);
|
_builder->setMarkerCursorIndex(_builder->cursorIndex() - 1);
|
||||||
|
@ -805,7 +805,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & NSShiftKeyMask) {
|
if (flags & NSEventModifierFlagShift) {
|
||||||
// Shift + Right
|
// Shift + Right
|
||||||
if (_builder->cursorIndex() < _builder->length()) {
|
if (_builder->cursorIndex() < _builder->length()) {
|
||||||
_builder->setMarkerCursorIndex(_builder->cursorIndex() + 1);
|
_builder->setMarkerCursorIndex(_builder->cursorIndex() + 1);
|
||||||
|
@ -962,6 +962,15 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((char)charCode >= 'A' && (char)charCode <= 'Z') {
|
||||||
|
if ([_composingBuffer length]) {
|
||||||
|
string letter = string("_letter_") + string(1, (char)charCode);
|
||||||
|
if ([self _handlePunctuation:letter usingVerticalMode:useVerticalMode client:client]) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// still nothing, then we update the composing buffer (some app has
|
// still nothing, then we update the composing buffer (some app has
|
||||||
// strange behavior if we don't do this, "thinking" the key is not
|
// strange behavior if we don't do this, "thinking" the key is not
|
||||||
// actually consumed)
|
// actually consumed)
|
||||||
|
@ -1209,7 +1218,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
|
|
||||||
// Function key pressed.
|
// Function key pressed.
|
||||||
BOOL includeShift = Preferences.functionKeyKeyboardLayoutOverrideIncludeShiftKey;
|
BOOL includeShift = Preferences.functionKeyKeyboardLayoutOverrideIncludeShiftKey;
|
||||||
if (([event modifierFlags] & ~NSShiftKeyMask) || (([event modifierFlags] & NSShiftKeyMask) && includeShift)) {
|
if (([event modifierFlags] & ~NSEventModifierFlagShift) || (([event modifierFlags] & NSEventModifierFlagShift) && includeShift)) {
|
||||||
// Override the keyboard layout and let the OS do its thing
|
// Override the keyboard layout and let the OS do its thing
|
||||||
[client overrideKeyboardWithKeyboardNamed:functionKeyKeyboardLayoutID];
|
[client overrideKeyboardWithKeyboardNamed:functionKeyKeyboardLayoutID];
|
||||||
return NO;
|
return NO;
|
||||||
|
|
Loading…
Reference in New Issue