MCPcopy Create free account
hub / github.com/EasyIME/PIME / compositionMode

Function compositionMode

node/input_methods/emojime/src/reducer/compositionMode.js:7–127  ·  view source on GitHub ↗
(request, preState)

Source from the content-addressed store, hash-verified

5let KEYCODE = require('nime/lib/keyCodes');
6
7function compositionMode(request, preState) {
8
9 let {keyCode, charCode} = request;
10
11 let {
12 compositionString,
13 compositionCursor,
14 showCandidates
15 } = preState;
16
17 // ':' + space would fast input ': ' for typing
18 if (keyCode == KEYCODE.VK_SPACE && compositionString == ':') {
19 return Object.assign({}, preState, {
20 action: 'COMMIT_STRING',
21 compositionString: '',
22 compositionCursor: 0,
23 commitString: ': '
24 });
25 }
26
27 // Show candidate list
28 if (keyCode === KEYCODE.VK_DOWN) {
29
30 // Must larger ':'.length
31 if (compositionString.length > 1) {
32
33 let candidateList = [];
34
35 emojione.mapEmojioneList((unicode, shortname) => {
36 if (shortname.indexOf(compositionString.slice(1)) >= 0 && candidateList.length < 9) {
37 candidateList.push(`${emojione.convert(unicode)} ${shortname}`);
38 }
39 });
40
41 if (candidateList.length > 0) {
42 return Object.assign({}, preState, {
43 action: 'SHOW_CANDIDATES',
44 showCandidates: true,
45 candidateList
46 });
47 }
48 }
49 }
50
51 // Move cursor left
52 if (keyCode === KEYCODE.VK_LEFT) {
53 if (compositionCursor > 0) {
54 return Object.assign({}, preState, {
55 action: 'UPDATE_STRING',
56 compositionCursor: compositionCursor - 1
57 });
58 }
59 return Object.assign({}, preState, {action: ''});
60 }
61
62 // Move cursor right
63 if (keyCode === KEYCODE.VK_RIGHT) {
64 if (compositionCursor < compositionString.length) {

Callers 1

reduceOnKeyDownFunction · 0.85

Calls 1

convertMethod · 0.45

Tested by

no test coverage detected