MCPcopy
hub / github.com/arduino/Arduino / keyTyped

Method keyTyped

app/src/processing/app/EditorStatus.java:289–328  ·  view source on GitHub ↗
(KeyEvent event)

Source from the content-addressed store, hash-verified

287 // enter or backspace or whatever, so the keychar should
288 // be used instead. grr.
289 public void keyTyped(KeyEvent event) {
290 int c = event.getKeyChar();
291
292 if (c == KeyEvent.VK_ENTER) { // accept the input
293 String answer = editField.getText();
294 editor.getSketchController().nameCode(answer);
295 unedit();
296 event.consume();
297
298 // easier to test the affirmative case than the negative
299 } else if ((c == KeyEvent.VK_BACK_SPACE) ||
300 (c == KeyEvent.VK_DELETE) ||
301 (c == KeyEvent.VK_RIGHT) ||
302 (c == KeyEvent.VK_LEFT) ||
303 (c == KeyEvent.VK_UP) ||
304 (c == KeyEvent.VK_DOWN) ||
305 (c == KeyEvent.VK_HOME) ||
306 (c == KeyEvent.VK_END) ||
307 (c == KeyEvent.VK_SHIFT)) {
308 // these events are ignored
309
310 } else if (c == KeyEvent.VK_SPACE) {
311 String t = editField.getText();
312 int start = editField.getSelectionStart();
313 int end = editField.getSelectionEnd();
314 editField.setText(t.substring(0, start) + "_" +
315 t.substring(end));
316 editField.setCaretPosition(start + 1);
317 event.consume();
318
319 } else if ((c == '_') || (c == '.') || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) { // allow .pde and .java
320 // these are ok, allow them through
321
322 } else if ((c >= '0') && (c <= '9')) {
323 // these are ok, allow them through
324
325 } else {
326 event.consume();
327 }
328 }
329 });
330 add(editField);
331 editField.setVisible(false);

Callers

nothing calls this directly

Calls 7

uneditMethod · 0.95
nameCodeMethod · 0.80
getSketchControllerMethod · 0.80
getSelectionStartMethod · 0.80
getTextMethod · 0.65
setTextMethod · 0.45
setCaretPositionMethod · 0.45

Tested by

no test coverage detected