Skip to content

Commit 733025d

Browse files
author
breandan
committed
add focus symbols and jump commands
1 parent b384cd5 commit 733025d

8 files changed

Lines changed: 167 additions & 19 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.jetbrains.idear;
2+
3+
/**
4+
* Created by breandan on 10/25/2015.
5+
*/
6+
public class WordToNumberConverter {
7+
public static int getNumber(String input) {
8+
int accumulator = 0;
9+
int total = 0;
10+
String[] words = input.trim().split("\\s+");
11+
12+
for (String word : words) {
13+
switch (word) {
14+
case "zero":
15+
accumulator += 0;
16+
break;
17+
case "one":
18+
accumulator += 1;
19+
break;
20+
case "two":
21+
accumulator += 2;
22+
break;
23+
case "three":
24+
accumulator += 3;
25+
break;
26+
case "four":
27+
accumulator += 4;
28+
break;
29+
case "five":
30+
accumulator += 5;
31+
break;
32+
case "six":
33+
accumulator += 6;
34+
break;
35+
case "seven":
36+
accumulator += 7;
37+
break;
38+
case "eight":
39+
accumulator += 8;
40+
break;
41+
case "nine":
42+
accumulator += 9;
43+
break;
44+
case "ten":
45+
accumulator += 10;
46+
break;
47+
case "eleven":
48+
accumulator += 11;
49+
break;
50+
case "twelve":
51+
accumulator += 12;
52+
break;
53+
case "thirteen":
54+
accumulator += 13;
55+
break;
56+
case "fourteen":
57+
accumulator += 14;
58+
break;
59+
case "fifteen":
60+
accumulator += 15;
61+
break;
62+
case "sixteen":
63+
accumulator += 16;
64+
break;
65+
case "seventeen":
66+
accumulator += 17;
67+
break;
68+
case "eighteen":
69+
accumulator += 18;
70+
break;
71+
case "nineteen":
72+
accumulator += 19;
73+
break;
74+
case "twenty":
75+
accumulator += 20;
76+
break;
77+
case "thirty":
78+
accumulator += 30;
79+
break;
80+
case "forty":
81+
accumulator += 40;
82+
break;
83+
case "fifty":
84+
accumulator += 50;
85+
break;
86+
case "sixty":
87+
accumulator += 60;
88+
break;
89+
case "seventy":
90+
accumulator += 70;
91+
break;
92+
case "eighty":
93+
accumulator += 80;
94+
break;
95+
case "ninety":
96+
accumulator += 90;
97+
break;
98+
case "hundred":
99+
accumulator *= 100;
100+
break;
101+
case "thousand":
102+
accumulator *= 1000;
103+
total += accumulator;
104+
accumulator = 0;
105+
break;
106+
}
107+
}
108+
109+
return total + accumulator;
110+
}
111+
}

src/com/jetbrains/idear/asr/ASRControlLoop.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.openapi.util.Pair;
99
import com.intellij.util.Consumer;
1010
import com.jetbrains.idear.GoogleHelper;
11+
import com.jetbrains.idear.WordToNumberConverter;
1112
import com.jetbrains.idear.actions.ExecuteVoiceCommandAction;
1213
import com.jetbrains.idear.actions.recognition.SurroundWithNoNullCheckRecognizer;
1314
import com.jetbrains.idear.ide.IDEService;
@@ -49,7 +50,7 @@ public ASRControlLoop(CustomLiveSpeechRecognizer recognizer) {
4950
public static final String EDITOR = "editor";
5051
public static final String PROJECT = "project";
5152
public static final String SELECTION = "selection";
52-
public static final String EXPAND = "expand";
53+
public static final String EXPAND = "grow";
5354
public static final String SHRINK = "shrink";
5455
public static final String PRESS = "press";
5556
public static final String DELETE = "delete";
@@ -128,25 +129,28 @@ private void applyAction(String c) {
128129
// TODO(kudinkin): extract to action
129130
ideService.invokeAction("Idear.WhereAmI");
130131
} else if (c.startsWith("focus")) {
131-
if (c.endsWith("editor")) {
132+
if (c.endsWith(EDITOR)) {
132133
pressKeystroke(KeyEvent.VK_ESCAPE);
133-
} else if (c.endsWith("project")) {
134+
} else if (c.endsWith(PROJECT)) {
134135
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_1);
136+
} else if(c.endsWith("symbols")) {
137+
ideService.invokeAction("AceJumpAction");
138+
ideService.type(("" + recognizeNumber()).toCharArray());
135139
}
136-
} else if (c.startsWith("grow")) {
140+
} else if (c.startsWith(EXPAND)) {
137141
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_W);
138-
} else if (c.startsWith("shrink")) {
142+
} else if (c.startsWith(SHRINK)) {
139143
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_W);
140144
} else if (c.startsWith("press")) {
141145
if (c.contains("delete")) {
142146
pressKeystroke(KeyEvent.VK_DELETE);
143147
} else if (c.contains("return")) {
144148
pressKeystroke(KeyEvent.VK_ENTER);
145-
} else if (c.contains("escape")) {
149+
} else if (c.contains(ESCAPE)) {
146150
pressKeystroke(KeyEvent.VK_ESCAPE);
147-
} else if (c.contains("tab")) {
151+
} else if (c.contains(TAB)) {
148152
pressKeystroke(KeyEvent.VK_TAB);
149-
} else if (c.contains("undo")) {
153+
} else if (c.contains(UNDO)) {
150154
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_Z);
151155
}
152156
} else if (c.startsWith("following")) {
@@ -207,7 +211,7 @@ private void applyAction(String c) {
207211

208212
private void pressKeystroke(final int... keys) {
209213
ServiceManager.getService(IDEService.class)
210-
.pressKeystroke(keys);
214+
.type(keys);
211215
}
212216

213217
private void run(SurroundWithNoNullCheckRecognizer rec, String c, DataContext dataContext) {
@@ -313,6 +317,15 @@ private void pauseSpeech() {
313317
}
314318
}
315319

320+
private int recognizeNumber() {
321+
String result;
322+
while(true) {
323+
result = getResultFromRecognizer();
324+
if(result.startsWith("jump "))
325+
return WordToNumberConverter.getNumber(result.substring(5));
326+
}
327+
}
328+
316329
// Helpers
317330

318331
public synchronized void say(String something) {

src/com/jetbrains/idear/ide/IDEService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public interface IDEService {
2424

2525
void dispose();
2626

27-
void pressKeystroke(final int... keys);
27+
void type(final int... keys);
28+
void type(final char... keys);
29+
2830

2931
void invokeAction(final String action);
3032

src/com/jetbrains/idear/ide/IDEServiceImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ public class IDEServiceImpl implements IDEService {
1616

1717
private Robot robot;
1818

19-
public void init() {
19+
public IDEServiceImpl() {
2020
try {
2121
robot = new Robot();
2222
} catch (AWTException e) {
2323
e.printStackTrace();
2424
}
2525
}
2626

27+
@Override
28+
public void init() {
29+
30+
}
31+
2732
@Override
2833
public void dispose() {
2934

@@ -52,7 +57,17 @@ public void invokeAction(String action, Function<DataContext, AnActionEvent> act
5257
);
5358
}
5459

55-
public void pressKeystroke(final int... keys) {
60+
public void type(final int... keys) {
61+
for (int key : keys) {
62+
robot.keyPress(key);
63+
}
64+
65+
for (int key : keys) {
66+
robot.keyRelease(key);
67+
}
68+
}
69+
70+
public void type(final char... keys) {
5671
for (int key : keys) {
5772
robot.keyPress(key);
5873
}

src/com/johnlindquist/acejump/AceFinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import javax.swing.event.ChangeListener
1818

1919
public class AceFinder(val project: Project, val document: DocumentImpl, val editor: EditorImpl, val virtualFile: VirtualFile) {
2020
companion object AceFinder {
21-
val ALLOWED_CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
21+
val ALLOWED_CHARACTERS = "1234567890";
2222
val END_OF_LINE = "\\n";
2323
val BEGINNING_OF_LINE = "^.|\\n(?<!.\\n)";
2424
val CODE_INDENTS = "^\\s*\\S";

src/com/johnlindquist/acejump/AceJumpAction.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public open class AceJumpAction() : DumbAwareAction() {
4949
val aceJumper = AceJumper(editor, document)
5050
val aceCanvas = AceCanvas()
5151
val searchBox = SearchBox()
52+
aceFinder.findAllVisibleSymbols();
53+
searchBox.disableSearch();
5254
val textAndOffsetHash = HashMap<String, Int>()
5355

5456
fun showJumpers(textPointPairs: List<Pair<String, Point>>?) {

src/com/johnlindquist/acejump/ui/SearchBox.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class SearchBox: JTextField() {
2828
override fun paintBorder(p0: Graphics?) {
2929
}
3030

31-
3231
//todo: I need to really rethink this entire approach
3332
override fun processKeyEvent(p0: KeyEvent) {
3433
if (getText()?.length() == 0) {

src/resources/com.jetbrains.idear/grammars/command.gram

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ grammar dialog;
4040

4141
<selection_command> = grow | shrink;
4242

43-
<focus_command> = focus (editor | project);
43+
<focus_command> = focus (editor | project | symbols);
4444

4545
<run_command> = execute;
4646

@@ -54,23 +54,29 @@ grammar dialog;
5454

5555
<next_command> = [following | previous] [line | method | error];
5656

57-
<google_command> = (okay | ok) google;
58-
5957
<check_not_null> = check not null;
6058

6159
<joke_command> = tell me a joke | who is there | wait who | who are you;
6260

6361
<navigate_command> = navigate;
6462

63+
<jump_command> = jump <number>;
64+
65+
<number> = <hundreds> | <tens> | <teens> | <ones>;
66+
<hundreds> = <ones> hundred [<tens> | <teens> | <ones>];
67+
<tens> = (twenty | thirty | forty | fifty | sixty | seventy | eighty | ninety) [<ones>];
68+
<teens> = ten | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen;
69+
<ones> = one | two | three | four | five | six | seven | eight | nine;
70+
6571
public <command> = <init_command> |
6672
<activation_command> |
6773
<menu_command> |
6874
<editor_command> |
6975
<focus_command> |
7076
<speech_command> |
71-
<google_command> |
7277
<run_command> |
7378
<debug_command> |
7479
<joke_command> |
7580
<check_not_null> |
76-
<keyboard_command> ;
81+
<keyboard_command> |
82+
<jump_command>;

0 commit comments

Comments
 (0)