[Glitch] Add hotkey for toggling content warning composer field

Port 6b6a9d0ea3 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
signup-info-prompt
ThibG 2020-06-09 10:32:32 +02:00 committed by Thibaut Girka
parent 5e07deefc1
commit 00cd919750
2 changed files with 13 additions and 2 deletions

View File

@ -105,6 +105,10 @@ class KeyboardShortcuts extends ImmutablePureComponent {
<td><kbd>alt</kbd>+<kbd>n</kbd></td> <td><kbd>alt</kbd>+<kbd>n</kbd></td>
<td><FormattedMessage id='keyboard_shortcuts.toot' defaultMessage='to start a brand new toot' /></td> <td><FormattedMessage id='keyboard_shortcuts.toot' defaultMessage='to start a brand new toot' /></td>
</tr> </tr>
<tr>
<td><kbd>alt</kbd>+<kbd>x</kbd></td>
<td><FormattedMessage id='keyboard_shortcuts.spoilers' defaultMessage='to show/hide CW field' /></td>
</tr>
<tr> <tr>
<td><kbd>backspace</kbd></td> <td><kbd>backspace</kbd></td>
<td><FormattedMessage id='keyboard_shortcuts.back' defaultMessage='to navigate back' /></td> <td><FormattedMessage id='keyboard_shortcuts.back' defaultMessage='to navigate back' /></td>

View File

@ -7,7 +7,7 @@ import { connect } from 'react-redux';
import { Redirect, withRouter } from 'react-router-dom'; import { Redirect, withRouter } from 'react-router-dom';
import { isMobile } from 'flavours/glitch/util/is_mobile'; import { isMobile } from 'flavours/glitch/util/is_mobile';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { uploadCompose, resetCompose } from 'flavours/glitch/actions/compose'; import { uploadCompose, resetCompose, changeComposeSpoilerness } from 'flavours/glitch/actions/compose';
import { expandHomeTimeline } from 'flavours/glitch/actions/timelines'; import { expandHomeTimeline } from 'flavours/glitch/actions/timelines';
import { expandNotifications, notificationsSetVisibility } from 'flavours/glitch/actions/notifications'; import { expandNotifications, notificationsSetVisibility } from 'flavours/glitch/actions/notifications';
import { fetchFilters } from 'flavours/glitch/actions/filters'; import { fetchFilters } from 'flavours/glitch/actions/filters';
@ -81,6 +81,7 @@ const keyMap = {
new: 'n', new: 'n',
search: 's', search: 's',
forceNew: 'option+n', forceNew: 'option+n',
toggleComposeSpoilers: 'option+x',
focusColumn: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], focusColumn: ['1', '2', '3', '4', '5', '6', '7', '8', '9'],
reply: 'r', reply: 'r',
favourite: 'f', favourite: 'f',
@ -396,7 +397,7 @@ class UI extends React.Component {
componentDidMount () { componentDidMount () {
this.hotkeys.__mousetrap__.stopCallback = (e, element) => { this.hotkeys.__mousetrap__.stopCallback = (e, element) => {
return ['TEXTAREA', 'SELECT', 'INPUT'].includes(element.tagName); return ['TEXTAREA', 'SELECT', 'INPUT'].includes(element.tagName) && !e.altKey;
}; };
} }
@ -455,6 +456,11 @@ class UI extends React.Component {
this.props.dispatch(resetCompose()); this.props.dispatch(resetCompose());
} }
handleHotkeyToggleComposeSpoilers = e => {
e.preventDefault();
this.props.dispatch(changeComposeSpoilerness());
}
handleHotkeyFocusColumn = e => { handleHotkeyFocusColumn = e => {
const index = (e.key * 1) + 1; // First child is drawer, skip that const index = (e.key * 1) + 1; // First child is drawer, skip that
const column = this.node.querySelector(`.column:nth-child(${index})`); const column = this.node.querySelector(`.column:nth-child(${index})`);
@ -569,6 +575,7 @@ class UI extends React.Component {
new: this.handleHotkeyNew, new: this.handleHotkeyNew,
search: this.handleHotkeySearch, search: this.handleHotkeySearch,
forceNew: this.handleHotkeyForceNew, forceNew: this.handleHotkeyForceNew,
toggleComposeSpoilers: this.handleHotkeyToggleComposeSpoilers,
focusColumn: this.handleHotkeyFocusColumn, focusColumn: this.handleHotkeyFocusColumn,
back: this.handleHotkeyBack, back: this.handleHotkeyBack,
goToHome: this.handleHotkeyGoToHome, goToHome: this.handleHotkeyGoToHome,