Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add support for disabling spell checking #8604

Merged
merged 15 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions res/css/views/settings/tabs/_SettingsTab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ limitations under the License.
color: $primary-content;
margin-top: 10px; // TODO: Use a spacing variable
margin-bottom: 10px; // TODO: Use a spacing variable
margin-right: 100px; // TODO: Use a spacing variable

&:nth-child(n + 2) {
margin-top: 30px; // TODO: Use a spacing variable
Expand All @@ -49,6 +50,7 @@ limitations under the License.
color: $primary-content;
margin-top: $spacing-12;
margin-bottom: 10px; // TODO: Use a spacing variable
margin-right: 100px; // TODO: Use a spacing variable
}

.mx_SettingsTab_subsectionText {
Expand Down
4 changes: 4 additions & 0 deletions res/css/views/settings/tabs/user/_GeneralUserSettingsTab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ limitations under the License.
.mx_GeneralUserSettingsTab_warningIcon {
vertical-align: middle;
}

.mx_SettingsTab_section_spellcheck .mx_ToggleSwitch {
float: right;
}
8 changes: 7 additions & 1 deletion src/BasePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default abstract class BasePlatform {
* Return true if platform supports multi-language
* spell-checking, otherwise false.
*/
public supportsMultiLanguageSpellCheck(): boolean {
public supportsSpellCheckSettings(): boolean {
return false;
}

Expand Down Expand Up @@ -266,6 +266,12 @@ export default abstract class BasePlatform {

public setLanguage(preferredLangs: string[]) {}

public setSpellCheckEnabled(enabled: boolean): void {}

public async getSpellCheckEnabled(): Promise<boolean> {
return null;
}

public setSpellCheckLanguages(preferredLangs: string[]) {}

public getSpellCheckLanguages(): Promise<string[]> | null {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/ToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IProps {
checked: boolean;

// Whether or not the user can interact with the switch
disabled: boolean;
disabled?: boolean;

// Called when the checked state changes. First argument will be the new state.
onChange(checked: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ import ChangePassword from "../../ChangePassword";
import InlineTermsAgreement from "../../../terms/InlineTermsAgreement";
import SetIdServer from "../../SetIdServer";
import SetIntegrationManager from "../../SetIntegrationManager";
import ToggleSwitch from "../../../elements/ToggleSwitch";
import { IS_MAC } from "../../../../../Keyboard";

interface IProps {
closeSettingsFn: () => void;
}

interface IState {
language: string;
spellCheckEnabled: boolean;
spellCheckLanguages: string[];
haveIdServer: boolean;
serverSupportsSeparateAddAndBind: boolean;
Expand Down Expand Up @@ -85,6 +88,7 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta

this.state = {
language: languageHandler.getCurrentLanguage(),
spellCheckEnabled: false,
spellCheckLanguages: [],
haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl()),
serverSupportsSeparateAddAndBind: null,
Expand Down Expand Up @@ -126,10 +130,13 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
}

public async componentDidMount(): Promise<void> {
const plaf = PlatformPeg.get();
if (plaf) {
const spellCheckEnabled = await PlatformPeg.get().getSpellCheckEnabled();
const spellCheckLanguages = await PlatformPeg.get().getSpellCheckLanguages();
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved

if (spellCheckLanguages) {
this.setState({
spellCheckLanguages: await plaf.getSpellCheckLanguages(),
spellCheckEnabled,
spellCheckLanguages,
});
}
}
Expand Down Expand Up @@ -238,11 +245,12 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta

private onSpellCheckLanguagesChange = (languages: string[]): void => {
this.setState({ spellCheckLanguages: languages });
PlatformPeg.get()?.setSpellCheckLanguages(languages);
};

const plaf = PlatformPeg.get();
if (plaf) {
plaf.setSpellCheckLanguages(languages);
}
private onSpellCheckEnabledChange = (spellCheckEnabled: boolean): void => {
this.setState({ spellCheckEnabled });
PlatformPeg.get()?.setSpellCheckEnabled(spellCheckEnabled);
};

private onPasswordChangeError = (err): void => {
Expand Down Expand Up @@ -368,12 +376,18 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta

private renderSpellCheckSection(): JSX.Element {
return (
<div className="mx_SettingsTab_section">
<span className="mx_SettingsTab_subheading">{ _t("Spell check dictionaries") }</span>
<SpellCheckSettings
<div className="mx_SettingsTab_section mx_SettingsTab_section_spellcheck">
<span className="mx_SettingsTab_subheading">
{ _t("Spell check") }
<ToggleSwitch
checked={this.state.spellCheckEnabled}
onChange={this.onSpellCheckEnabledChange}
/>
</span>
{ (this.state.spellCheckEnabled && !IS_MAC) && <SpellCheckSettings
languages={this.state.spellCheckLanguages}
onLanguagesChange={this.onSpellCheckLanguagesChange}
/>
/> }
</div>
);
}
Expand Down Expand Up @@ -449,7 +463,7 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta

public render(): JSX.Element {
const plaf = PlatformPeg.get();
const supportsMultiLanguageSpellCheck = plaf.supportsMultiLanguageSpellCheck();
const supportsMultiLanguageSpellCheck = plaf.supportsSpellCheckSettings();

const discoWarning = this.state.requiredPolicyInfo.hasTerms
? <img
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@
"Set a new account password...": "Set a new account password...",
"Account": "Account",
"Language and region": "Language and region",
"Spell check dictionaries": "Spell check dictionaries",
"Spell check": "Spell check",
"Agree to the identity server (%(serverName)s) Terms of Service to allow yourself to be discoverable by email address or phone number.": "Agree to the identity server (%(serverName)s) Terms of Service to allow yourself to be discoverable by email address or phone number.",
"Account management": "Account management",
"Deactivating your account is a permanent action — be careful!": "Deactivating your account is a permanent action — be careful!",
Expand Down