1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var KeyBindingUtil = require("./KeyBindingUtil");
|
14 |
|
15 | var Keys = require("fbjs/lib/Keys");
|
16 |
|
17 | var UserAgent = require("fbjs/lib/UserAgent");
|
18 |
|
19 | var isOSX = UserAgent.isPlatform('Mac OS X');
|
20 |
|
21 |
|
22 |
|
23 | var shouldFixFirefoxMovement = isOSX && UserAgent.isBrowser('Firefox < 29');
|
24 | var hasCommandModifier = KeyBindingUtil.hasCommandModifier,
|
25 | isCtrlKeyCommand = KeyBindingUtil.isCtrlKeyCommand;
|
26 |
|
27 | function shouldRemoveWord(e) {
|
28 | return isOSX && e.altKey || isCtrlKeyCommand(e);
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function getZCommand(e) {
|
36 | if (!hasCommandModifier(e)) {
|
37 | return null;
|
38 | }
|
39 |
|
40 | return e.shiftKey ? 'redo' : 'undo';
|
41 | }
|
42 |
|
43 | function getDeleteCommand(e) {
|
44 |
|
45 | if (!isOSX && e.shiftKey) {
|
46 | return null;
|
47 | }
|
48 |
|
49 | return shouldRemoveWord(e) ? 'delete-word' : 'delete';
|
50 | }
|
51 |
|
52 | function getBackspaceCommand(e) {
|
53 | if (hasCommandModifier(e) && isOSX) {
|
54 | return 'backspace-to-start-of-line';
|
55 | }
|
56 |
|
57 | return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function getDefaultKeyBinding(e) {
|
65 | switch (e.keyCode) {
|
66 | case 66:
|
67 |
|
68 | return hasCommandModifier(e) ? 'bold' : null;
|
69 |
|
70 | case 68:
|
71 |
|
72 | return isCtrlKeyCommand(e) ? 'delete' : null;
|
73 |
|
74 | case 72:
|
75 |
|
76 | return isCtrlKeyCommand(e) ? 'backspace' : null;
|
77 |
|
78 | case 73:
|
79 |
|
80 | return hasCommandModifier(e) ? 'italic' : null;
|
81 |
|
82 | case 74:
|
83 |
|
84 | return hasCommandModifier(e) ? 'code' : null;
|
85 |
|
86 | case 75:
|
87 |
|
88 | return isOSX && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
|
89 |
|
90 | case 77:
|
91 |
|
92 | return isCtrlKeyCommand(e) ? 'split-block' : null;
|
93 |
|
94 | case 79:
|
95 |
|
96 | return isCtrlKeyCommand(e) ? 'split-block' : null;
|
97 |
|
98 | case 84:
|
99 |
|
100 | return isOSX && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
|
101 |
|
102 | case 85:
|
103 |
|
104 | return hasCommandModifier(e) ? 'underline' : null;
|
105 |
|
106 | case 87:
|
107 |
|
108 | return isOSX && isCtrlKeyCommand(e) ? 'backspace-word' : null;
|
109 |
|
110 | case 89:
|
111 |
|
112 | if (isCtrlKeyCommand(e)) {
|
113 | return isOSX ? 'secondary-paste' : 'redo';
|
114 | }
|
115 |
|
116 | return null;
|
117 |
|
118 | case 90:
|
119 |
|
120 | return getZCommand(e) || null;
|
121 |
|
122 | case Keys.RETURN:
|
123 | return 'split-block';
|
124 |
|
125 | case Keys.DELETE:
|
126 | return getDeleteCommand(e);
|
127 |
|
128 | case Keys.BACKSPACE:
|
129 | return getBackspaceCommand(e);
|
130 |
|
131 |
|
132 | case Keys.LEFT:
|
133 | return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
|
134 |
|
135 | case Keys.RIGHT:
|
136 | return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
|
137 |
|
138 | default:
|
139 | return null;
|
140 | }
|
141 | }
|
142 |
|
143 | module.exports = getDefaultKeyBinding; |
\ | No newline at end of file |