mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 11:35:57 +00:00
Merge pull request #1467 from sharelatex/as-global-search-keybind
Enable search keybinding globally in editor GitOrigin-RevId: 8e36dbe44ffd385d212bf9dabb549fd04b84a428
This commit is contained in:
parent
01a8cc9aea
commit
210e2700a9
3 changed files with 57 additions and 2 deletions
|
@ -19,6 +19,8 @@ define([
|
|||
'ide/editor/directives/aceEditor/track-changes/TrackChangesManager',
|
||||
'ide/editor/directives/aceEditor/track-changes/TrackChangesAdapter',
|
||||
'ide/editor/directives/aceEditor/metadata/MetadataManager',
|
||||
'ide/editor/directives/aceEditor/global-key-binding/GlobalKeybindingManager',
|
||||
'ide/editor/directives/aceEditor/global-key-binding/GlobalKeybindingAdapter',
|
||||
'ide/metadata/services/metadata',
|
||||
'ide/graphics/services/graphics',
|
||||
'ide/preamble/services/preamble',
|
||||
|
@ -38,7 +40,9 @@ define([
|
|||
CursorPositionAdapter,
|
||||
TrackChangesManager,
|
||||
TrackChangesAdapter,
|
||||
MetadataManager
|
||||
MetadataManager,
|
||||
GlobalKeybindingManager,
|
||||
GlobalKeybindingAdapter
|
||||
) {
|
||||
let syntaxValidationEnabled
|
||||
const { EditSession } = ace.require('ace/edit_session')
|
||||
|
@ -197,9 +201,12 @@ define([
|
|||
preamble,
|
||||
files
|
||||
)
|
||||
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
const keybindingManager = new GlobalKeybindingManager(
|
||||
new GlobalKeybindingAdapter(editor)
|
||||
)
|
||||
|
||||
scope.$watch('onSave', function(callback) {
|
||||
if (callback != null) {
|
||||
Vim.defineEx('write', 'w', callback)
|
||||
|
@ -744,6 +751,7 @@ define([
|
|||
triggerEditorInitEvent()
|
||||
initSpellCheck()
|
||||
initTrackChanges()
|
||||
keybindingManager.init()
|
||||
|
||||
resetScrollMargins()
|
||||
|
||||
|
@ -794,6 +802,7 @@ define([
|
|||
var detachFromAce = function(sharejs_doc) {
|
||||
tearDownSpellCheck()
|
||||
tearDownTrackChanges()
|
||||
keybindingManager.tearDown()
|
||||
sharejs_doc.detachFromAce()
|
||||
sharejs_doc.off('remoteop.recordRemote')
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
define(['ace/ace', 'ace/ext-searchbox'], function() {
|
||||
const SearchBox = ace.require('ace/ext/searchbox')
|
||||
|
||||
class GlobalKeybindingAdapter {
|
||||
constructor(editor) {
|
||||
this.editor = editor
|
||||
}
|
||||
|
||||
handleF(e) {
|
||||
e.preventDefault()
|
||||
SearchBox.Search(this.editor, true)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return GlobalKeybindingAdapter
|
||||
})
|
|
@ -0,0 +1,29 @@
|
|||
define([], function() {
|
||||
const F_KEY = 70
|
||||
|
||||
class GlobalKeyBindingManager {
|
||||
constructor(adapter) {
|
||||
this.adapter = adapter
|
||||
this.handleKey = this.handleKey.bind(this)
|
||||
}
|
||||
|
||||
handleKey(e) {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
switch (e.keyCode) {
|
||||
case F_KEY:
|
||||
return this.adapter.handleF(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
$(document).on('keydown', this.handleKey)
|
||||
}
|
||||
|
||||
tearDown() {
|
||||
$(document).off('keydown', this.handleKey)
|
||||
}
|
||||
}
|
||||
|
||||
return GlobalKeyBindingManager
|
||||
})
|
Loading…
Reference in a new issue