From 771a39f2674a0ce7a9c3f7238fe4d2b9959d2a52 Mon Sep 17 00:00:00 2001
From: Alf Eaton <75253002+aeaton-overleaf@users.noreply.github.com>
Date: Thu, 10 Dec 2020 11:13:59 +0000
Subject: [PATCH] Merge pull request #3441 from overleaf/3803-hotkeys-modal
Migrate hotkeys modal to React
GitOrigin-RevId: 78399d3d62771cd296bdc2f4f8b1083263d31551
---
services/web/app/views/project/editor.pug | 2 -
.../web/app/views/project/editor/hotkeys.pug | 113 -----------
.../app/views/project/editor/left-menu.pug | 8 +-
.../frontend/extracted-translation-keys.json | 7 +
.../components/hotkeys-modal-content.js | 177 ++++++++++++++++++
.../hotkeys-modal/components/hotkeys-modal.js | 26 +++
.../controllers/hotkeys-modal-controller.js | 25 +++
.../hotkeys/controllers/HotkeysController.js | 47 -----
services/web/frontend/js/ide/hotkeys/index.js | 2 +-
.../frontend/stories/hotkeys-modal.stories.js | 24 +++
.../components/hotkeys-modal.test.js | 61 ++++++
11 files changed, 328 insertions(+), 164 deletions(-)
delete mode 100644 services/web/app/views/project/editor/hotkeys.pug
create mode 100644 services/web/frontend/js/features/hotkeys-modal/components/hotkeys-modal-content.js
create mode 100644 services/web/frontend/js/features/hotkeys-modal/components/hotkeys-modal.js
create mode 100644 services/web/frontend/js/features/hotkeys-modal/controllers/hotkeys-modal-controller.js
delete mode 100644 services/web/frontend/js/ide/hotkeys/controllers/HotkeysController.js
create mode 100644 services/web/frontend/stories/hotkeys-modal.stories.js
create mode 100644 services/web/test/frontend/features/hotkeys-modal/components/hotkeys-modal.test.js
diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug
index 473825b426..2b09ad54e6 100644
--- a/services/web/app/views/project/editor.pug
+++ b/services/web/app/views/project/editor.pug
@@ -110,8 +110,6 @@ block content
else
include ./editor/chat
- include ./editor/hotkeys
-
script(type="text/ng-template", id="genericMessageModalTemplate")
.modal-header
button.close(
diff --git a/services/web/app/views/project/editor/hotkeys.pug b/services/web/app/views/project/editor/hotkeys.pug
deleted file mode 100644
index 798548f5c4..0000000000
--- a/services/web/app/views/project/editor/hotkeys.pug
+++ /dev/null
@@ -1,113 +0,0 @@
-script(type="text/ng-template", id="hotkeysModalTemplate")
- .modal-header
- button.close(
- type="button"
- data-dismiss="modal"
- ng-click="cancel()"
- aria-label="Close"
- )
- span(aria-hidden="true") ×
- h3 #{translate("hotkeys")}
- .modal-body.modal-hotkeys
- h3 #{translate("common")}
- .row
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + F
- span.description Find (and replace)
- .hotkey
- span.combination {{ctrl}} + Enter
- span.description Compile
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + Z
- span.description Undo
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + Y
- span.description Redo
- h3 #{translate("navigation")}
- .row
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + Home
- span.description Beginning of document
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + End
- span.description End of document
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + L
- span.description Go To Line
- h3 #{translate("editing")}
- .row
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + /
- span.description Toggle Comment
- .hotkey
- span.combination {{ctrl}} + D
- span.description Delete Current Line
- .hotkey
- span.combination {{ctrl}} + A
- span.description Select All
- .col-xs-4
- .hotkey
- span.combination Ctrl + U
- span.description To Uppercase
- .hotkey
- span.combination Ctrl + Shift + U
- span.description To Lowercase
- .hotkey
- span.combination Tab
- span.description Indent Selection
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + B
- span.description Bold text
- .hotkey
- span.combination {{ctrl}} + I
- span.description Italic Text
-
- h3 #{translate("autocomplete")}
- .row
- .col-xs-4
- .hotkey
- span.combination Ctrl + Space
- span.description Autocomplete Menu
- .col-xs-4
- .hotkey
- span.combination Tab / Up / Down
- span.description Select Candidate
- .col-xs-4
- .hotkey
- span.combination Enter
- span.description Insert Candidate
-
- h3 !{translate("autocomplete_references")}
- .row
- .col-xs-4
- .hotkey
- span.combination Ctrl + Space
- span.description Search References
-
- h3(ng-if="trackChangesVisible") #{translate("review")}
- .row(ng-if="trackChangesVisible")
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + J
- span.description Toggle review panel
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + Shift + A
- span.description Toggle track changes
- .col-xs-4
- .hotkey
- span.combination {{ctrl}} + Shift + C
- span.description Add a comment
-
- .modal-footer
- button.btn.btn-default(
- ng-click="cancel()"
- ) #{translate("ok")}
diff --git a/services/web/app/views/project/editor/left-menu.pug b/services/web/app/views/project/editor/left-menu.pug
index a3715ba7bd..020bd33091 100644
--- a/services/web/app/views/project/editor/left-menu.pug
+++ b/services/web/app/views/project/editor/left-menu.pug
@@ -201,10 +201,16 @@ aside#left-menu.full-size(
h4 #{translate("help")}
ul.list-unstyled.nav
- li(ng-controller="HotkeysController")
+ li(ng-controller="HotkeysModalController")
a(ng-click="openHotkeysModal()")
i.fa.fa-keyboard-o.fa-fw
| #{translate("show_hotkeys")}
+
+ hotkeys-modal(
+ handle-hide="handleHide"
+ show="show"
+ track-changes-visible="trackChangesVisible"
+ )
if showSupport
li
a(href='/learn', target="_blank")
diff --git a/services/web/frontend/extracted-translation-keys.json b/services/web/frontend/extracted-translation-keys.json
index fefc81fc46..3d453847e2 100644
--- a/services/web/frontend/extracted-translation-keys.json
+++ b/services/web/frontend/extracted-translation-keys.json
@@ -2,10 +2,13 @@
"auto_compile",
"autocompile_disabled_reason",
"autocompile_disabled",
+ "autocomplete",
+ "autocomplete_references",
"clear_cached_files",
"clsi_maintenance",
"clsi_unavailable",
"collapse",
+ "common",
"compile_error_description",
"compile_error_entry_description",
"compile_mode",
@@ -16,6 +19,7 @@
"download_file",
"download_pdf",
"duplicate_paths_found",
+ "editing",
"expand",
"fast",
"file_outline",
@@ -27,6 +31,7 @@
"full_screen",
"go_to_error_location",
"hide_outline",
+ "hotkeys",
"ignore_validation_errors",
"latex_error",
"learn_how_to_make_documents_compile_quickly",
@@ -34,6 +39,7 @@
"log_entry_description",
"log_hint_extra_info",
"main_file_not_found",
+ "navigation",
"n_errors_plural",
"n_errors",
"n_warnings_plural",
@@ -58,6 +64,7 @@
"raw_logs",
"recompile_from_scratch",
"recompile",
+ "review",
"run_syntax_check_now",
"send_first_message",
"server_error",
diff --git a/services/web/frontend/js/features/hotkeys-modal/components/hotkeys-modal-content.js b/services/web/frontend/js/features/hotkeys-modal/components/hotkeys-modal-content.js
new file mode 100644
index 0000000000..7b93bcd6af
--- /dev/null
+++ b/services/web/frontend/js/features/hotkeys-modal/components/hotkeys-modal-content.js
@@ -0,0 +1,177 @@
+import React from 'react'
+import { Button, Modal, Row, Col } from 'react-bootstrap'
+import PropTypes from 'prop-types'
+import { Trans, useTranslation } from 'react-i18next'
+
+function HotkeysModalContent({
+ handleHide,
+ isMac = false,
+ trackChangesVisible = false
+}) {
+ const { t } = useTranslation()
+
+ const ctrl = isMac ? 'Cmd' : 'Ctrl'
+
+ return (
+ <>
+ {t('common')}
+
+ {t('navigation')}
+
+ {t('editing')}
+
+ {t('autocomplete')}
+
+
+
+
+ {t('review')}
+
+