Prevents users from adding custom phrases with more than 6 characters.

Also fixes typos.
This commit is contained in:
zonble 2022-01-19 00:49:50 +08:00
parent d2c039c42d
commit 7e2d3df5ba
4 changed files with 19 additions and 5 deletions

View File

@ -143,7 +143,7 @@ class PreferencesTests: XCTestCase {
XCTAssert(Preferences.phraseReplacementEnabled == true)
}
func testChineneConversionEngine() {
func testChineseConversionEngine() {
XCTAssert(Preferences.chineseConversionEngine == 0)
Preferences.chineseConversionEngine = 1
XCTAssert(Preferences.chineseConversionEngine == 1)

View File

@ -55,6 +55,8 @@ using namespace McBopomofo;
using namespace OpenVanilla;
static const NSInteger kMinKeyLabelSize = 10;
static const NSInteger kMinMarkRangeLength = 2;
static const NSInteger kMaxMarkRangeLength = 6;
// input modes
static NSString *const kBopomofoModeIdentifier = @"org.openvanilla.inputmethod.McBopomofo.Bopomofo";
@ -1421,7 +1423,10 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
size_t begin = min(_builder->markerCursorIndex(), _builder->cursorIndex());
size_t end = max(_builder->markerCursorIndex(), _builder->cursorIndex());
// A phrase should contian at least two characters.
if (end - begin < 2) {
if (end - begin < kMinMarkRangeLength) {
return @"";
}
if (end - begin > kMaxMarkRangeLength) {
return @"";
}
@ -1443,6 +1448,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
{
NSString *currentMarkedPhrase = [self _currentMarkedTextAndReadings];
if (![currentMarkedPhrase length]) {
[self beep];
return NO;
}
@ -1464,9 +1470,13 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
NSString *message = NSLocalizedString(@"Model based Chinese conversion is on. Not suggested to add phrase in the mode.", @"");
[self _showTooltip:message client:client];
}
else if (length == 1) {
NSString *messsage = [NSString stringWithFormat:NSLocalizedString(@"You are now selecting \"%@\". You can add a phrase with two or more characters.", @""), text];
[self _showTooltip:messsage client:client];
else if (length < kMinMarkRangeLength) {
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"You are now selecting \"%@\". You can add a phrase with two or more characters.", @""), text];
[self _showTooltip:message client:client];
}
else if (length > kMaxMarkRangeLength) {
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"You are now selecting \"%@\". A phrase cannot be longer than 6 characters.", @""), text];
[self _showTooltip:message client:client];
}
else {
NSString *messsage = [NSString stringWithFormat:NSLocalizedString(@"You are now selecting \"%@\". Press enter to add a new phrase.", @""), text];

View File

@ -69,6 +69,8 @@
"You are now selecting \"%@\". Press enter to add a new phrase." = "You are now selecting \"%@\". Press enter to add a new phrase.";
"You are now selecting \"%@\". A phrase cannot be longer than 6 characters." = "You are now selecting \"%@\". A phrase cannot be longer than 6 characters.";
"Chinese conversion on" = "Chinese conversion on";
"Chinese conversion off" = "Chinese conversion off";

View File

@ -69,6 +69,8 @@
"You are now selecting \"%@\". Press enter to add a new phrase." = "您目前選擇了 \"%@\"。按下 Enter 就可以加入到使用者詞彙中。";
"You are now selecting \"%@\". A phrase cannot be longer than 6 characters." = "您目前選擇了 \"%@\"。自訂詞彙不能超過六個字元。";
"Chinese conversion on" = "已經切換到簡體中文模式";
"Chinese conversion off" = "已經切換到繁體中文模式";