hotkeys-modal.jsx 5.8 KB

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