Skip to content

Commit 4edc27a

Browse files
committed
fix(input): gate prior tone change with preference
1 parent 98d0943 commit 4edc27a

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

Source/Engine/Mandarin/Mandarin.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,6 @@ class BopomofoReadingBuffer {
458458

459459
const BPMF syllable() const { return syllable_; }
460460

461-
void setSyllableRemovingTone(BPMF syllable) {
462-
BPMF::Component masked = (syllable.consonantComponent() |
463-
syllable.middleVowelComponent() |
464-
syllable.vowelComponent());
465-
syllable_ = BPMF(masked);
466-
if (pinyin_mode_) {
467-
pinyin_sequence_ = syllable_.HanyuPinyinString(false, false);
468-
}
469-
}
470-
471461
const std::string standardLayoutQueryString() const {
472462
return BopomofoKeyboardLayout::StandardLayout()->keySequenceFromSyllable(
473463
syllable_);

Source/KeyHandler.mm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,20 @@ - (BOOL)handleInput:(KeyHandlerInput *)input state:(InputState *)inState stateCa
468468
//
469469
// This allows users to use tone key to change an existing reading before
470470
// the current cursor.
471-
if (_bpmfReadingBuffer->hasToneMarkerOnly() && _grid->readings().size() > 0 && _grid->cursor() > 0) {
471+
if (Preferences.allowChangingPriorTone &&
472+
_bpmfReadingBuffer->hasToneMarkerOnly() &&
473+
_grid->readings().size() > 0 &&
474+
_grid->cursor() > 0) {
472475
size_t cursor = _grid->cursor() - 1;
473-
const std::string reading = _grid->readings()[cursor];
476+
// const std::string reading = _grid->readings()[cursor];
477+
const std::string& reading = _grid->readings()[cursor];
474478
if (!reading.empty() && reading[0] != '_') {
475479
Formosa::Mandarin::BopomofoReadingBuffer tmpBuffer(_bpmfReadingBuffer->keyboardLayout());
476-
Formosa::Mandarin::BopomofoSyllable syllable = Formosa::Mandarin::BopomofoSyllable::FromComposedString(reading);
477-
tmpBuffer.setSyllableRemovingTone(syllable);
480+
Formosa::Mandarin::BopomofoSyllable syllable = Formosa::Mandarin::BopomofoSyllable::FromComposedString(reading);
481+
std::string keys = _bpmfReadingBuffer->keyboardLayout()->keySequenceFromSyllable(syllable);
482+
for (char k:keys) {
483+
tmpBuffer.combineKey(k);
484+
}
478485
tmpBuffer.combineKey((char)charCode);
479486
std::string newReading = tmpBuffer.syllable().composedString();
480487
if (_languageModel->hasUnigrams(newReading)) {

Source/Preferences.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private let kBig5InputEnabledKey = "Big5InputEnabled"
7474
let kBeepUponInputErrorKey = "BeepUponInputError"
7575

7676
private let kEnableUserPhrasesInPlainBopomofo = "EnableUserPhrasesInPlainBopomofo"
77+
private let kAllowChangingPriorTone = "AllowChangingPriorTone"
7778

7879
// MARK: Property wrappers
7980

@@ -570,6 +571,11 @@ extension Preferences {
570571
@objc static var enableUserPhrasesInPlainBopomofo: Bool
571572
}
572573

574+
extension Preferences {
575+
@UserDefault(key: kAllowChangingPriorTone, defaultValue: false)
576+
@objc static var allowChangingPriorTone: Bool
577+
}
578+
573579
extension Preferences {
574580
static func createReport() -> String {
575581
var lines: [String] = []

0 commit comments

Comments
 (0)