hotkeys-modal.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import React from 'react'
  2. import { Button, Modal, Row, Col } from 'react-bootstrap'
  3. import PropTypes from 'prop-types'
  4. import { Trans, useTranslation } from 'react-i18next'
  5. import AccessibleModal from '../../../shared/components/accessible-modal'
  6. export default function HotkeysModal({
  7. animation = true,
  8. handleHide,
  9. show,
  10. isMac = false,
  11. trackChangesVisible = false
  12. }) {
  13. const { t } = useTranslation()
  14. const ctrl = isMac ? 'Cmd' : 'Ctrl'
  15. return (
  16. <AccessibleModal
  17. bsSize="large"
  18. onHide={handleHide}
  19. show={show}
  20. animation={animation}
  21. >
  22. <Modal.Header closeButton>
  23. <Modal.Title>{t('hotkeys')}</Modal.Title>
  24. </Modal.Header>
  25. <Modal.Body className="modal-hotkeys">
  26. <h3>{t('common')}</h3>
  27. <Row>
  28. <Col xs={4}>
  29. <Hotkey
  30. combination={`${ctrl} + F`}
  31. description="Find (and replace)"
  32. />
  33. <Hotkey combination={`${ctrl} + Enter`} description="Compile" />
  34. </Col>
  35. <Col xs={4}>
  36. <Hotkey combination={`${ctrl} + Z`} description="Undo" />
  37. </Col>
  38. <Col xs={4}>
  39. <Hotkey combination={`${ctrl} + Y`} description="Redo" />
  40. </Col>
  41. </Row>
  42. <h3>{t('navigation')}</h3>
  43. <Row>
  44. <Col xs={4}>
  45. <Hotkey
  46. combination={`${ctrl} + Home`}
  47. description="Beginning of document"
  48. />
  49. </Col>
  50. <Col xs={4}>
  51. <Hotkey
  52. combination={`${ctrl} + End`}
  53. description="End of document"
  54. />
  55. </Col>
  56. <Col xs={4}>
  57. <Hotkey combination={`${ctrl} + L`} description="Go To Line" />
  58. </Col>
  59. </Row>
  60. <h3>{t('editing')}</h3>
  61. <Row>
  62. <Col xs={4}>
  63. <Hotkey combination={`${ctrl} + /`} description="Toggle Comment" />
  64. <Hotkey
  65. combination={`${ctrl} + D`}
  66. description="Delete Current Line"
  67. />
  68. <Hotkey combination={`${ctrl} + A`} description="Select All" />
  69. </Col>
  70. <Col xs={4}>
  71. <Hotkey combination={`${ctrl} + U`} description="To Uppercase" />
  72. <Hotkey
  73. combination={`${ctrl} + Shift + U`}
  74. description="To Lowercase"
  75. />
  76. <Hotkey combination="Tab" description="Indent Selection" />
  77. </Col>
  78. <Col xs={4}>
  79. <Hotkey combination={`${ctrl} + B`} description="Bold text" />
  80. <Hotkey combination={`${ctrl} + I`} description="Italic Text" />
  81. </Col>
  82. </Row>
  83. <h3>{t('autocomplete')}</h3>
  84. <Row>
  85. <Col xs={4}>
  86. <Hotkey
  87. combination={`${ctrl} + Space`}
  88. description="Autocomplete Menu"
  89. />
  90. </Col>
  91. <Col xs={4}>
  92. <Hotkey
  93. combination="Tab / Up / Down"
  94. description="Select Candidate"
  95. />
  96. </Col>
  97. <Col xs={4}>
  98. <Hotkey combination="Enter" description="Insert Candidate" />
  99. </Col>
  100. </Row>
  101. <h3>
  102. <Trans
  103. i18nKey="autocomplete_references"
  104. components={{ code: <code /> }}
  105. />
  106. </h3>
  107. <Row>
  108. <Col xs={4}>
  109. <Hotkey
  110. combination={`${ctrl} + Space `}
  111. description="Search References"
  112. />
  113. </Col>
  114. </Row>
  115. {trackChangesVisible && (
  116. <>
  117. <h3>{t('review')}</h3>
  118. <Row>
  119. <Col xs={4}>
  120. <Hotkey
  121. combination={`${ctrl} + J`}
  122. description="Toggle review panel"
  123. />
  124. </Col>
  125. <Col xs={4}>
  126. <Hotkey
  127. combination={`${ctrl} + Shift + A`}
  128. description="Toggle track changes"
  129. />
  130. </Col>
  131. <Col xs={4}>
  132. <Hotkey
  133. combination={`${ctrl} + Shift + C`}
  134. description="Add a comment"
  135. />
  136. </Col>
  137. </Row>
  138. </>
  139. )}
  140. </Modal.Body>
  141. <Modal.Footer>
  142. <Button onClick={handleHide}>{t('ok')}</Button>
  143. </Modal.Footer>
  144. </AccessibleModal>
  145. )
  146. }
  147. HotkeysModal.propTypes = {
  148. animation: PropTypes.bool,
  149. isMac: PropTypes.bool,
  150. show: PropTypes.bool.isRequired,
  151. handleHide: PropTypes.func.isRequired,
  152. trackChangesVisible: PropTypes.bool
  153. }
  154. function Hotkey({ combination, description }) {
  155. return (
  156. <div className="hotkey" data-test-selector="hotkey">
  157. <span className="combination">{combination}</span>
  158. <span className="description">{description}</span>
  159. </div>
  160. )
  161. }
  162. Hotkey.propTypes = {
  163. combination: PropTypes.string.isRequired,
  164. description: PropTypes.string.isRequired
  165. }