| 1586 | } |
| 1587 | |
| 1588 | static private Pair<Integer, Integer> getWord(TextView tvBody) { |
| 1589 | int start = tvBody.getSelectionStart(); |
| 1590 | int end = tvBody.getSelectionEnd(); |
| 1591 | Spannable edit = (Spannable) tvBody.getText(); |
| 1592 | |
| 1593 | if (start < 0 || end < 0) |
| 1594 | return null; |
| 1595 | |
| 1596 | if (start > end) { |
| 1597 | int tmp = start; |
| 1598 | start = end; |
| 1599 | end = tmp; |
| 1600 | } |
| 1601 | |
| 1602 | // Expand selection at start |
| 1603 | while (start > 0 && edit.charAt(start - 1) != ' ' && edit.charAt(start - 1) != '\n') |
| 1604 | start--; |
| 1605 | |
| 1606 | // Expand selection at end |
| 1607 | while (end < edit.length() && edit.charAt(end) != ' ' && edit.charAt(end) != '\n') |
| 1608 | end++; |
| 1609 | |
| 1610 | if (start == end) |
| 1611 | return null; |
| 1612 | |
| 1613 | return new Pair<>(start, end); |
| 1614 | } |
| 1615 | |
| 1616 | public static Pair<Integer, Integer> getParagraph(TextView tvBody) { |
| 1617 | return getParagraph(tvBody, false); |