()
| 584 | } |
| 585 | |
| 586 | public String getCurrentKeyword() { |
| 587 | String text = ""; |
| 588 | if (textarea.getSelectedText() != null) |
| 589 | text = textarea.getSelectedText().trim(); |
| 590 | |
| 591 | try { |
| 592 | int current = textarea.getCaretPosition(); |
| 593 | int startOffset = 0; |
| 594 | int endIndex = current; |
| 595 | String tmp = textarea.getDocument().getText(current, 1); |
| 596 | // TODO probably a regexp that matches Arduino lang special chars |
| 597 | // already exists. |
| 598 | String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]"; |
| 599 | |
| 600 | while (!tmp.matches(regexp)) { |
| 601 | endIndex++; |
| 602 | tmp = textarea.getDocument().getText(endIndex, 1); |
| 603 | } |
| 604 | // For some reason document index start at 2. |
| 605 | // if( current - start < 2 ) return; |
| 606 | |
| 607 | tmp = ""; |
| 608 | while (!tmp.matches(regexp)) { |
| 609 | startOffset++; |
| 610 | if (current - startOffset < 0) { |
| 611 | tmp = textarea.getDocument().getText(0, 1); |
| 612 | break; |
| 613 | } else |
| 614 | tmp = textarea.getDocument().getText(current - startOffset, 1); |
| 615 | } |
| 616 | startOffset--; |
| 617 | |
| 618 | int length = endIndex - current + startOffset; |
| 619 | text = textarea.getDocument().getText(current - startOffset, length); |
| 620 | |
| 621 | } catch (BadLocationException bl) { |
| 622 | bl.printStackTrace(); |
| 623 | } |
| 624 | return text; |
| 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public boolean requestFocusInWindow() { |
no test coverage detected