hotkeys-modal.js 5.9 KB

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