This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
/
KeyBindings.ts
175 lines (149 loc) · 6.88 KB
/
KeyBindings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* KeyBindings.ts
*
* Default, out-of-the-box keybindings for Oni
*/
import * as Oni from "oni-api"
import * as Platform from "./../Platform"
import { Configuration } from "./../Services/Configuration"
interface ISidebar {
sidebar: {
activeEntryId: string
isFocused: boolean
}
}
export const applyDefaultKeyBindings = (oni: Oni.Plugin.Api, config: Configuration): void => {
const { editors, input, menu } = oni
input.unbindAll()
const isVisualMode = () => editors.activeEditor.mode === "visual"
const isNormalMode = () => editors.activeEditor.mode === "normal"
const isNotInsertMode = () => editors.activeEditor.mode !== "insert"
const isInsertOrCommandMode = () =>
editors.activeEditor.mode === "insert" || editors.activeEditor.mode === "cmdline_normal"
const oniWithSidebar = oni as Oni.Plugin.Api & ISidebar
const isSidebarPaneOpen = (paneId: string) =>
oniWithSidebar.sidebar.activeEntryId === paneId &&
oniWithSidebar.sidebar.isFocused &&
!isInsertOrCommandMode() &&
!isMenuOpen()
const isExplorerActive = () => isSidebarPaneOpen("oni.sidebar.explorer")
const areSessionsActive = () => isSidebarPaneOpen("oni.sidebar.sessions")
const isVCSActive = () => isSidebarPaneOpen("oni.sidebar.vcs")
const isMenuOpen = () => menu.isMenuOpen()
if (Platform.isMac()) {
input.bind("<m-q>", "oni.quit")
input.bind("<m-p>", "quickOpen.show", () => isNormalMode() && !isMenuOpen())
input.bind("<m-s-p>", "commands.show", isNormalMode)
input.bind("<m-enter>", "language.codeAction.expand")
input.bind("<m-t>", "language.symbols.workspace", () => !menu.isMenuOpen())
input.bind("<s-m-t>", "language.symbols.document")
input.bind("<m-m>", "oni.editor.minimize")
input.bind("<m-h>", "oni.editor.hide")
input.bind("<c-tab>", "buffer.toggle")
input.bind("<m-s-f>", "search.searchAllFiles")
input.bind("<m-s-e>", "explorer.toggle")
input.bind("<m-s-_>", "sidebar.decreaseWidth")
input.bind("<m-s-+>", "sidebar.increaseWidth")
input.bind("<m-,>", "oni.config.openConfigJs")
if (config.getValue("editor.clipboard.enabled")) {
input.bind("<m-c>", "editor.clipboard.yank", isVisualMode)
input.bind("<m-v>", "editor.clipboard.paste", isInsertOrCommandMode)
}
// Browser
input.bind("<m-left>", "browser.goBack")
input.bind("<m-right>", "browser.goForward")
input.bind("<m-r>", "browser.reload")
} else {
input.bind("<a-f4>", "oni.quit")
input.bind("<s-c-_>", "sidebar.decreaseWidth")
input.bind("<s-c-+>", "sidebar.increaseWidth")
input.bind("<c-p>", "quickOpen.show", () => isNormalMode() && !isMenuOpen())
input.bind("<s-c-p>", "commands.show", isNormalMode)
input.bind("<a-enter>", "language.codeAction.expand")
input.bind("<c-t>", "language.symbols.workspace", () => !menu.isMenuOpen())
input.bind("<s-c-t>", "language.symbols.document")
input.bind("<c-tab>", "buffer.toggle")
input.bind("<s-c-f>", "search.searchAllFiles")
input.bind("<s-c-e>", "explorer.toggle")
input.bind("<c-,>", "oni.config.openConfigJs")
if (config.getValue("editor.clipboard.enabled")) {
input.bind("<c-c>", "editor.clipboard.yank", isVisualMode)
input.bind("<c-v>", "editor.clipboard.paste", isInsertOrCommandMode)
}
// Browser
input.bind("<a-left>", "browser.goBack")
input.bind("<a-right>", "browser.goForward")
input.bind("<f5>", "browser.reload")
}
input.bind("<f2>", "editor.rename", () => isNormalMode())
input.bind("<f3>", "language.format")
input.bind(["<f12>"], "language.gotoDefinition", () => isNormalMode() && !menu.isMenuOpen())
input.bind(
["<c-enter>", "<c-f12>"],
"language.gotoDefinition.openVertical",
() => isNormalMode() && !menu.isMenuOpen(),
)
input.bind(
["<s-enter>", "<s-f12>"],
"language.gotoDefinition.openHorizontal",
() => isNormalMode() && !menu.isMenuOpen(),
)
input.bind("<S-C-P>", "commands.show", isNormalMode)
input.bind("<C-pageup>", "oni.process.cyclePrevious")
input.bind("<C-pagedown>", "oni.process.cycleNext")
// QuickOpen
input.bind("<C-/>", "quickOpen.showBufferLines", isNormalMode)
input.bind(["<C-v>"], "quickOpen.openFileVertical")
input.bind(["<C-s>"], "quickOpen.openFileHorizontal")
input.bind("<C-t>", "quickOpen.openFileNewTab")
input.bind(["<C-enter>"], "quickOpen.openFileAlternative")
// Snippets
input.bind("<tab>", "snippet.nextPlaceholder")
input.bind("<s-tab>", "snippet.previousPlaceholder")
input.bind("<esc>", "snippet.cancel")
// Completion
input.bind(["<enter>"], "contextMenu.select")
input.bind(["<down>", "<C-n>"], "contextMenu.next")
input.bind(["<up>", "<C-p>"], "contextMenu.previous")
input.bind(
["<esc>"],
"contextMenu.close",
isNotInsertMode /* In insert mode, the mode change will close the popupmenu anyway */,
)
// Menu
input.bind(["<down>", "<C-n>"], "menu.next")
input.bind(["<up>", "<C-p>"], "menu.previous")
input.bind(["<esc>", "<C-[>", "<C-C>"], "menu.close")
input.bind("<enter>", "menu.select")
input.bind(["<enter>", "<space>"], "select")
// TODO: Scope 's' to just the local window
input.bind("<c-g>", "sneak.show", () => isNormalMode() && !menu.isMenuOpen())
input.bind(["<esc>", "<c-c>"], "sneak.hide")
input.bind("<s-c-b>", "sidebar.toggle", isNormalMode)
// Explorer
input.bind("d", "explorer.delete.persist", isExplorerActive)
input.bind("<c-delete>", "explorer.delete.persist", isExplorerActive)
input.bind("<c-s-d>", "explorer.delete", isExplorerActive)
input.bind("<delete>", "explorer.delete", isExplorerActive)
input.bind("y", "explorer.yank", isExplorerActive)
input.bind("p", "explorer.paste", isExplorerActive)
input.bind("u", "explorer.undo", isExplorerActive)
input.bind("h", "explorer.collapse.directory", isExplorerActive)
input.bind("l", "explorer.expand.directory", isExplorerActive)
input.bind("r", "explorer.rename", isExplorerActive)
input.bind("<c-e>", "explorer.create.file", isExplorerActive)
input.bind("<c-f>", "explorer.create.folder", isExplorerActive)
input.bind("<c-r>", "explorer.refresh", isExplorerActive)
// Browser
input.bind("k", "browser.scrollUp")
input.bind("j", "browser.scrollDown")
input.bind("h", "browser.scrollLeft")
input.bind("l", "browser.scrollRight")
// VCS
input.bind("e", "vcs.openFile", isVCSActive)
input.bind("u", "vcs.unstage", isVCSActive)
input.bind("<c-r>", "vcs.refresh", isVCSActive)
input.bind("?", "vcs.showHelp", isVCSActive)
// Sessions
input.bind("<c-d>", "oni.sessions.delete", areSessionsActive)
}