MCPcopy Create free account
hub / github.com/BaseXdb/basex / enter

Method enter

basex-core/src/main/java/org/basex/gui/text/TextEditor.java:778–800  ·  view source on GitHub ↗

Processes the enter key and checks for opening brackets. @param sb typed in string @return number of characters to move forward

(final StringBuilder sb)

Source from the content-addressed store, hash-verified

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.

Callers 1

keyTypedMethod · 0.45

Calls 7

sizeMethod · 0.95
indentMethod · 0.95
openMethod · 0.95
addMethod · 0.95
appendMethod · 0.65
indexOfMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected