mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Improve "compile" keyboard shortcut handling (#10624)
* Improve "compile" keypress handling * Remove "compile" keypress handling from PDF preview * Remove compile shortcuts from CM6 * Use an event for Vim keybindings * Remove event handlers from Angular/Ace * Move useCompileTriggers into DetachCompileProvider GitOrigin-RevId: 7f0e667b5106a849458e06ebb0f7a413d5d63430
This commit is contained in:
parent
3baff57e4c
commit
65b0fd73ea
8 changed files with 48 additions and 90 deletions
|
@ -26,7 +26,6 @@ else
|
|||
custom-toggler-pane=hasFeature('custom-togglers') ? "west" : false
|
||||
custom-toggler-msg-when-open=hasFeature('custom-togglers') ? translate("tooltip_hide_filetree") : false
|
||||
custom-toggler-msg-when-closed=hasFeature('custom-togglers') ? translate("tooltip_show_filetree") : false
|
||||
ng-keydown="handleKeyDown($event)"
|
||||
tabindex="0"
|
||||
initial-size-east="250"
|
||||
init-closed-east="true"
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
annotations="pdf.logEntryAnnotations[editor.open_doc_id]",
|
||||
read-only="!permissions.write",
|
||||
file-name="editor.open_doc_name",
|
||||
on-ctrl-enter="recompileViaKey",
|
||||
on-save="recompileViaKey",
|
||||
on-ctrl-j="toggleReviewPanel",
|
||||
on-ctrl-shift-c="addNewCommentFromKbdShortcut",
|
||||
on-ctrl-shift-a="toggleTrackChangesFromKbdShortcut",
|
||||
|
|
|
@ -15,14 +15,8 @@ import { getPdfCachingMetrics } from '../util/metrics'
|
|||
function PdfJsViewer({ url, pdfFile }) {
|
||||
const { _id: projectId } = useProjectContext()
|
||||
|
||||
const {
|
||||
setError,
|
||||
firstRenderDone,
|
||||
highlights,
|
||||
position,
|
||||
setPosition,
|
||||
startCompile,
|
||||
} = useCompileContext()
|
||||
const { setError, firstRenderDone, highlights, position, setPosition } =
|
||||
useCompileContext()
|
||||
|
||||
// state values persisted in localStorage to restore on load
|
||||
const [scale, setScale] = usePersistedState(
|
||||
|
@ -372,24 +366,26 @@ function PdfJsViewer({ url, pdfFile }) {
|
|||
if (!initialised) {
|
||||
return
|
||||
}
|
||||
if ((event.metaKey || event.ctrlKey) && event.key === '=') {
|
||||
event.preventDefault()
|
||||
setZoom('zoom-in')
|
||||
} else if ((event.metaKey || event.ctrlKey) && event.key === '-') {
|
||||
event.preventDefault()
|
||||
setZoom('zoom-out')
|
||||
} else if ((event.metaKey || event.ctrlKey) && event.key === '0') {
|
||||
event.preventDefault()
|
||||
setZoom('fit-width')
|
||||
} else if (
|
||||
(event.metaKey && (event.key === 's' || event.key === 'Enter')) ||
|
||||
(event.ctrlKey && event.key === '.')
|
||||
) {
|
||||
event.preventDefault()
|
||||
startCompile()
|
||||
if (event.metaKey || event.ctrlKey) {
|
||||
switch (event.key) {
|
||||
case '=':
|
||||
event.preventDefault()
|
||||
setZoom('zoom-in')
|
||||
break
|
||||
|
||||
case '-':
|
||||
event.preventDefault()
|
||||
setZoom('zoom-out')
|
||||
break
|
||||
|
||||
case '0':
|
||||
event.preventDefault()
|
||||
setZoom('fit-width')
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
[initialised, setZoom, startCompile]
|
||||
[initialised, setZoom]
|
||||
)
|
||||
|
||||
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import PdfPreviewPane from './pdf-preview-pane'
|
||||
import useCompileTriggers from '../hooks/use-compile-triggers'
|
||||
import { memo } from 'react'
|
||||
import withErrorBoundary from '../../../infrastructure/error-boundary'
|
||||
import PdfPreviewErrorBoundaryFallback from './pdf-preview-error-boundary-fallback'
|
||||
import { useLayoutContext } from '../../../shared/context/layout-context'
|
||||
|
||||
function PdfPreview() {
|
||||
useCompileTriggers()
|
||||
|
||||
const { detachRole } = useLayoutContext()
|
||||
if (detachRole === 'detacher') return null
|
||||
return <PdfPreviewPane />
|
||||
|
|
|
@ -1,28 +1,31 @@
|
|||
import { useCallback, useEffect } from 'react'
|
||||
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
||||
import useEventListener from '../../../shared/hooks/use-event-listener'
|
||||
import useDetachAction from '../../../shared/hooks/use-detach-action'
|
||||
|
||||
export default function useCompileTriggers() {
|
||||
const { startCompile, setChangedAt } = useCompileContext()
|
||||
export const startCompileKeypress = event => {
|
||||
if (event.shiftKey || event.altKey) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (event.ctrlKey) {
|
||||
// Ctrl+s / Ctrl+Enter / Ctrl+.
|
||||
if (event.key === 's' || event.key === 'Enter' || event.key === '.') {
|
||||
return true
|
||||
}
|
||||
} else if (event.metaKey) {
|
||||
// Cmd+s / Cmd+Enter
|
||||
if (event.key === 's' || event.key === 'Enter') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function useCompileTriggers(startCompile, setChangedAt) {
|
||||
const handleKeyDown = useCallback(
|
||||
event => {
|
||||
if (event.metaKey) {
|
||||
switch (event.key) {
|
||||
case 's':
|
||||
case 'Enter':
|
||||
event.preventDefault()
|
||||
startCompile()
|
||||
break
|
||||
}
|
||||
} else if (event.ctrlKey) {
|
||||
switch (event.key) {
|
||||
case '.':
|
||||
event.preventDefault()
|
||||
startCompile()
|
||||
break
|
||||
}
|
||||
if (startCompileKeypress(event)) {
|
||||
event.preventDefault()
|
||||
startCompile()
|
||||
}
|
||||
},
|
||||
[startCompile]
|
||||
|
|
|
@ -387,24 +387,8 @@ If the project has been renamed please look in your project list for a new proje
|
|||
}
|
||||
})
|
||||
|
||||
$scope.recompileViaKey = () => {
|
||||
if ($scope.recompile) {
|
||||
$scope.recompile()
|
||||
} else {
|
||||
window.dispatchEvent(new CustomEvent('pdf:recompile'))
|
||||
}
|
||||
}
|
||||
|
||||
$scope.handleKeyDown = event => {
|
||||
if (event.shiftKey || event.altKey) {
|
||||
return
|
||||
}
|
||||
|
||||
// Ctrl+s or Cmd+s => recompile
|
||||
if (event.key === 's' && (event.metaKey || event.ctrlKey)) {
|
||||
event.preventDefault()
|
||||
$scope.recompileViaKey()
|
||||
}
|
||||
$scope.handleKeyDown = () => {
|
||||
// unused?
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -242,30 +242,8 @@ App.directive(
|
|||
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
scope.$watch('onSave', function (callback) {
|
||||
if (callback != null) {
|
||||
Vim.defineEx('write', 'w', callback)
|
||||
editor.commands.addCommand({
|
||||
name: 'save',
|
||||
bindKey: {
|
||||
win: 'Ctrl-S',
|
||||
mac: 'Command-S',
|
||||
},
|
||||
exec: callback,
|
||||
readOnly: true,
|
||||
})
|
||||
// Not technically 'save', but Ctrl-. recompiles in OL v1
|
||||
// so maintain compatibility
|
||||
return editor.commands.addCommand({
|
||||
name: 'recompile_v1',
|
||||
bindKey: {
|
||||
win: 'Ctrl-.',
|
||||
mac: 'Ctrl-.',
|
||||
},
|
||||
exec: callback,
|
||||
readOnly: true,
|
||||
})
|
||||
}
|
||||
Vim.defineEx('write', 'w', function () {
|
||||
window.dispatchEvent(new Event('pdf:recompile'))
|
||||
})
|
||||
editor.commands.removeCommand('transposeletters')
|
||||
editor.commands.removeCommand('showSettingsMenu')
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
} from './local-compile-context'
|
||||
import useDetachStateWatcher from '../hooks/use-detach-state-watcher'
|
||||
import useDetachAction from '../hooks/use-detach-action'
|
||||
import useCompileTriggers from '../../features/pdf-preview/hooks/use-compile-triggers'
|
||||
|
||||
export const DetachCompileContext = createContext()
|
||||
|
||||
|
@ -343,6 +344,8 @@ export function DetachCompileProvider({ children }) {
|
|||
'detacher'
|
||||
)
|
||||
|
||||
useCompileTriggers(startCompile, setChangedAt)
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
animateCompileDropdownArrow,
|
||||
|
|
Loading…
Reference in a new issue