Processes the enter key and checks for opening brackets. @param sb typed in string @return number of characters to move forward
(final StringBuilder sb)
| 776 | * @return number of characters to move forward |
| 777 | */ |
| 778 | int enter(final StringBuilder sb) { |
| 779 | // indent after opening bracket |
| 780 | final boolean opening = pos > 0 && OPENING.indexOf(text[pos - 1]) != -1; |
| 781 | final boolean closing = pos < size() && CLOSING.indexOf(text[pos]) != -1; |
| 782 | |
| 783 | final int ind = indent(); |
| 784 | int indent = open(), move = 0; |
| 785 | if(opening) { |
| 786 | if(closing) { |
| 787 | sb.append(" ".repeat(Math.max(0, indent + ind))); |
| 788 | move = indent + ind + 1; |
| 789 | sb.append('\n'); |
| 790 | } else { |
| 791 | indent += ind; |
| 792 | } |
| 793 | } else if(closing) { |
| 794 | // unindent before closing bracket |
| 795 | indent -= ind; |
| 796 | } |
| 797 | sb.append(" ".repeat(Math.max(0, indent))); |
| 798 | add(sb, false); |
| 799 | return move; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Processes and adds the specified string. |