Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to toggle double space period shortcuts. #491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,17 @@ class KeyboardViewController: UIInputViewController {
}
}

func doubleSpacePeriodsEnabled() -> Bool {
let langCode = languagesAbbrDict[controllerLanguage] ?? "unknown"
if let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer") {
let dictionaryKey = langCode + "DoubleSpacePeriods"

return userDefaults.bool(forKey: dictionaryKey)
} else {
return true // return the default value
}
}

func emojiAutosuggestIsEnabled() -> Bool {
let langCode = languagesAbbrDict[controllerLanguage] ?? "unknown"
if let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer") {
Expand Down Expand Up @@ -2904,7 +2915,8 @@ class KeyboardViewController: UIInputViewController {
if touch.tapCount == 2
&& (originalKey == spaceBar || originalKey == languageTextForSpaceBar)
&& proxy.documentContextBeforeInput?.count != 1
&& doubleSpacePeriodPossible {
&& doubleSpacePeriodPossible
&& doubleSpacePeriodsEnabled() {
// The first condition prevents a period if the prior characters are spaces as the user wants a series of spaces.
if proxy.documentContextBeforeInput?.suffix(2) != " " && ![.translate, .conjugate, .plural].contains(commandState) {
proxy.deleteBackward()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ final class InfoChildTableViewCell: UITableViewCell {
let dictionaryKey = languageCode + "AccentCharacters"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)

case .doubleSpacePeriods:
let dictionaryKey = languageCode + "DoubleSpacePeriods"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)

case .autosuggestEmojis:
let dictionaryKey = languageCode + "EmojiAutosuggest"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)
Expand Down Expand Up @@ -156,6 +160,14 @@ final class InfoChildTableViewCell: UITableViewCell {
toggleSwitch.isOn = false // Default value
}

case .doubleSpacePeriods:
let dictionaryKey = languageCode + "DoubleSpacePeriods"
if let toggleValue = userDefaults.object(forKey: dictionaryKey) as? Bool {
toggleSwitch.isOn = toggleValue
} else {
toggleSwitch.isOn = true // Default value
}

case .autosuggestEmojis:
let dictionaryKey = languageCode + "EmojiAutosuggest"
if let toggleValue = userDefaults.object(forKey: dictionaryKey) as? Bool {
Expand Down
1 change: 1 addition & 0 deletions Scribe/ParentTableCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum SectionState: Equatable {

enum UserInteractiveState {
case toggleCommaAndPeriod
case doubleSpacePeriods
case autosuggestEmojis
case toggleAccentCharacters
case none
Expand Down
6 changes: 6 additions & 0 deletions Scribe/SettingsTab/SettingsTableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ enum SettingsTableData {
ParentTableCellModel(
headingTitle: NSLocalizedString("app.settings.functionality", value: "Functionality", comment: ""),
section: [
Section(
sectionTitle: NSLocalizedString("app.settings.functionality.doubleSpacePeriods", value: "Double space periods", comment: ""),
hasToggle: true,
sectionState: .none(.doubleSpacePeriods),
shortDescription: NSLocalizedString("app.settings.layout.doubleSpacePeriods.description", value: "Automatically insert a period when the space key is pressed twice.", comment: "")
),
Section(
sectionTitle: NSLocalizedString("app.settings.functionality.autoSuggestEmoji", value: "Autosuggest emojis", comment: ""),
hasToggle: true,
Expand Down
22 changes: 22 additions & 0 deletions Scribe/i18n/Scribe-i18n/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,17 @@
}
}
},
"app.settings.functionality.doubleSpacePeriods" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Double space periods"
}
}
}
},
"app.settings.installedKeyboards" : {
"comment" : "",
"localizations" : {
Expand Down Expand Up @@ -1568,6 +1579,17 @@
}
}
},
"app.settings.layout.doubleSpacePeriods.description" : {
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Automatically insert a period when the space key is pressed twice."
}
}
}
},
"app.settings.layout.periodAndComma" : {
"comment" : "",
"localizations" : {
Expand Down