Make trailing `:` into a setting (#6711)

* Make trailing `:` into a setting

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

* Make traling comma opt-out

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

* Write `insertTrailingComma` when reading for future opt-in setting

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

* Update src/editor/parts.ts

* Fix line length

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

Co-authored-by: Travis Ralston <travpc@gmail.com>
pull/21833/head
Šimon Brandner 2022-03-04 08:23:26 +01:00 committed by GitHub
parent afbe3d16b4
commit 4c05b7da1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 1 deletions

View File

@ -162,6 +162,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
'MessageComposerInput.ctrlEnterToSend', 'MessageComposerInput.ctrlEnterToSend',
'MessageComposerInput.surroundWith', 'MessageComposerInput.surroundWith',
'MessageComposerInput.showStickersButton', 'MessageComposerInput.showStickersButton',
'MessageComposerInput.insertTrailingComma',
]; ];
static TIME_SETTINGS = [ static TIME_SETTINGS = [

View File

@ -30,6 +30,7 @@ import { unicodeToShortcode } from "../HtmlUtils";
import * as Avatar from "../Avatar"; import * as Avatar from "../Avatar";
import defaultDispatcher from "../dispatcher/dispatcher"; import defaultDispatcher from "../dispatcher/dispatcher";
import { Action } from "../dispatcher/actions"; import { Action } from "../dispatcher/actions";
import SettingsStore from "../settings/SettingsStore";
interface ISerializedPart { interface ISerializedPart {
type: Type.Plain | Type.Newline | Type.Emoji | Type.Command | Type.PillCandidate; type: Type.Plain | Type.Newline | Type.Emoji | Type.Command | Type.PillCandidate;
@ -650,7 +651,10 @@ export class PartCreator {
userId: string, userId: string,
): [UserPillPart, PlainPart] { ): [UserPillPart, PlainPart] {
const pill = this.userPill(displayName, userId); const pill = this.userPill(displayName, userId);
const postfix = this.plain(insertTrailingCharacter ? ": " : " "); const postfix = this.plain(
insertTrailingCharacter &&
(SettingsStore.getValue("MessageComposerInput.insertTrailingComma") ? ": " : " "),
);
return [pill, postfix]; return [pill, postfix];
} }
} }

View File

@ -906,6 +906,7 @@
"Use custom size": "Use custom size", "Use custom size": "Use custom size",
"Enable Emoji suggestions while typing": "Enable Emoji suggestions while typing", "Enable Emoji suggestions while typing": "Enable Emoji suggestions while typing",
"Show stickers button": "Show stickers button", "Show stickers button": "Show stickers button",
"Insert a trailing colon after user mentions at the start of a message": "Insert a trailing colon after user mentions at the start of a message",
"Use a more compact 'Modern' layout": "Use a more compact 'Modern' layout", "Use a more compact 'Modern' layout": "Use a more compact 'Modern' layout",
"Show a placeholder for removed messages": "Show a placeholder for removed messages", "Show a placeholder for removed messages": "Show a placeholder for removed messages",
"Show join/leave messages (invites/removes/bans unaffected)": "Show join/leave messages (invites/removes/bans unaffected)", "Show join/leave messages (invites/removes/bans unaffected)": "Show join/leave messages (invites/removes/bans unaffected)",

View File

@ -429,6 +429,11 @@ export const SETTINGS: {[setting: string]: ISetting} = {
default: true, default: true,
controller: new UIFeatureController(UIFeature.Widgets, false), controller: new UIFeatureController(UIFeature.Widgets, false),
}, },
"MessageComposerInput.insertTrailingComma": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Insert a trailing colon after user mentions at the start of a message'),
default: true,
},
// TODO: Wire up appropriately to UI (FTUE notifications) // TODO: Wire up appropriately to UI (FTUE notifications)
"Notifications.alwaysShowBadgeCounts": { "Notifications.alwaysShowBadgeCounts": {
supportedLevels: LEVELS_ROOM_OR_ACCOUNT, supportedLevels: LEVELS_ROOM_OR_ACCOUNT,

View File

@ -121,6 +121,19 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
return content[settingName]; return content[settingName];
} }
if (settingName === "MessageComposerInput.insertTrailingComma") {
const content = this.getSettings() || {};
const value = content[settingName];
if (value === null || value === undefined) {
// Write true as it is the default. This will give us the option
// of making this opt-in in the future, without affecting old
// users
this.setValue(settingName, roomId, true);
return true;
}
return value;
}
const settings = this.getSettings() || {}; const settings = this.getSettings() || {};
let preferredValue = settings[settingName]; let preferredValue = settings[settingName];