hotkeys-modal.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import { Button, Modal, Row, Col } from 'react-bootstrap'
  2. import PropTypes from 'prop-types'
  3. import { Trans, useTranslation } from 'react-i18next'
  4. import AccessibleModal from '../../../shared/components/accessible-modal'
  5. export default function HotkeysModal({
  6. animation = true,
  7. handleHide,
  8. show,
  9. isMac = false,
  10. trackChangesVisible = false,
  11. }) {
  12. const { t } = useTranslation()
  13. const ctrl = isMac ? 'Cmd' : 'Ctrl'
  14. return (
  15. <AccessibleModal
  16. bsSize="large"
  17. onHide={handleHide}
  18. show={show}
  19. animation={animation}
  20. >
  21. <Modal.Header closeButton>
  22. <Modal.Title>{t('hotkeys')}</Modal.Title>
  23. </Modal.Header>
  24. <Modal.Body className="modal-hotkeys">
  25. <h3>{t('common')}</h3>
  26. <Row>
  27. <Col xs={4}>
  28. <Hotkey
  29. combination={`${ctrl} + F`}
  30. description={t('hotkey_find_and_replace')}
  31. />
  32. <Hotkey
  33. combination={`${ctrl} + Enter`}
  34. description={t('hotkey_compile')}
  35. />
  36. </Col>
  37. <Col xs={4}>
  38. <Hotkey
  39. combination={`${ctrl} + Z`}
  40. description={t('hotkey_undo')}
  41. />
  42. </Col>
  43. <Col xs={4}>
  44. <Hotkey
  45. combination={`${ctrl} + Y`}
  46. description={t('hotkey_redo')}
  47. />
  48. </Col>
  49. </Row>
  50. <h3>{t('navigation')}</h3>
  51. <Row>
  52. <Col xs={4}>
  53. <Hotkey
  54. combination={`${ctrl} + Home`}
  55. description={t('hotkey_beginning_of_document')}
  56. />
  57. </Col>
  58. <Col xs={4}>
  59. <Hotkey
  60. combination={`${ctrl} + End`}
  61. description={t('hotkey_end_of_document')}
  62. />
  63. </Col>
  64. <Col xs={4}>
  65. <Hotkey
  66. combination={`${ctrl} + L`}
  67. description={t('hotkey_go_to_line')}
  68. />
  69. </Col>
  70. </Row>
  71. <h3>{t('editing')}</h3>
  72. <Row>
  73. <Col xs={4}>
  74. <Hotkey
  75. combination={`${ctrl} + /`}
  76. description={t('hotkey_toggle_comment')}
  77. />
  78. <Hotkey
  79. combination={`${ctrl} + D`}
  80. description={t('hotkey_delete_current_line')}
  81. />
  82. <Hotkey
  83. combination={`${ctrl} + A`}
  84. description={t('hotkey_select_all')}
  85. />
  86. </Col>
  87. <Col xs={4}>
  88. <Hotkey
  89. combination="Ctrl + U"
  90. description={t('hotkey_to_uppercase')}
  91. />
  92. <Hotkey
  93. combination="Ctrl + Shift + U"
  94. description={t('hotkey_to_lowercase')}
  95. />
  96. <Hotkey
  97. combination="Tab"
  98. description={t('hotkey_indent_selection')}
  99. />
  100. </Col>
  101. <Col xs={4}>
  102. <Hotkey
  103. combination={`${ctrl} + B`}
  104. description={t('hotkey_bold_text')}
  105. />
  106. <Hotkey
  107. combination={`${ctrl} + I`}
  108. description={t('hotkey_italic_text')}
  109. />
  110. </Col>
  111. </Row>
  112. <h3>{t('autocomplete')}</h3>
  113. <Row>
  114. <Col xs={4}>
  115. <Hotkey
  116. combination="Ctrl + Space"
  117. description={t('hotkey_autocomplete_menu')}
  118. />
  119. </Col>
  120. <Col xs={4}>
  121. <Hotkey
  122. combination="Tab / Up / Down"
  123. description={t('hotkey_select_candidate')}
  124. />
  125. </Col>
  126. <Col xs={4}>
  127. <Hotkey
  128. combination="Enter"
  129. description={t('hotkey_insert_candidate')}
  130. />
  131. </Col>
  132. </Row>
  133. <h3>
  134. <Trans
  135. i18nKey="autocomplete_references"
  136. components={{ code: <code /> }}
  137. />
  138. </h3>
  139. <Row>
  140. <Col xs={4}>
  141. <Hotkey
  142. combination={`Ctrl + Space `}
  143. description={t('hotkey_search_references')}
  144. />
  145. </Col>
  146. </Row>
  147. {trackChangesVisible && (
  148. <>
  149. <h3>{t('review')}</h3>
  150. <Row>
  151. <Col xs={4}>
  152. <Hotkey
  153. combination={`${ctrl} + J`}
  154. description={t('hotkey_toggle_review_panel')}
  155. />
  156. </Col>
  157. <Col xs={4}>
  158. <Hotkey
  159. combination={`${ctrl} + Shift + A`}
  160. description={t('hotkey_toggle_track_changes')}
  161. />
  162. </Col>
  163. <Col xs={4}>
  164. <Hotkey
  165. combination={`${ctrl} + Shift + C`}
  166. description={t('hotkey_add_a_comment')}
  167. />
  168. </Col>
  169. </Row>
  170. </>
  171. )}
  172. </Modal.Body>
  173. <Modal.Footer>
  174. <Button onClick={handleHide}>{t('ok')}</Button>
  175. </Modal.Footer>
  176. </AccessibleModal>
  177. )
  178. }
  179. HotkeysModal.propTypes = {
  180. animation: PropTypes.bool,
  181. isMac: PropTypes.bool,
  182. show: PropTypes.bool.isRequired,
  183. handleHide: PropTypes.func.isRequired,
  184. trackChangesVisible: PropTypes.bool,
  185. }
  186. function Hotkey({ combination, description }) {
  187. return (
  188. <div className="hotkey" data-test-selector="hotkey">
  189. <span className="combination">{combination}</span>
  190. <span className="description">{description}</span>
  191. </div>
  192. )
  193. }
  194. Hotkey.propTypes = {
  195. combination: PropTypes.string.isRequired,
  196. description: PropTypes.string.isRequired,
  197. }