private void handleNewline(@Nonnull KeyEvent event) {
		// Consume the event so the normal 'enter' behavior is skipped.
		event.consume();

		// Abort if handling tab completion.
		// Holding shift bypasses tab completion.
		boolean shiftMask = event.isShiftDown();
		if (!shiftMask && handleTabCompletion(event))
			return;

		// If there is selected contents, newline should replace it.
		IndexRange selection = codeArea.getSelection();
		if (selection.getLength() > 0) {
			codeArea.replace(selection.getStart(), selection.getEnd(), newText("\n"));
			return;
		}

		// Compute matching indentation level.
		int paragraph = codeArea.getCurrentParagraph();
		String paragraphContents = codeArea.getParagraph(paragraph).getText();
		int indent = 0;
		for (; indent < paragraphContents.length(); indent++) {
			char c = paragraphContents.charAt(indent);
			if (c != ' ' && c != '\t') break;
		}

		// Padding to insert in into the next line.
		String padding = paragraphContents.substring(0, indent);

		// For open brackets we'd like to do an extra level of indentation
		// and also complete the brace for the user.
		char closingBrace = '\0';
		for (int i = paragraphContents.length() - 1; i >= indent; i--) {
			char c = paragraphContents.charAt(i);
			if (c == '{') {
				closingBrace = '}';
				padding += '\t';
				break;
			} else if (c == '[') {
				closingBrace = ']';
				padding += '\t';
				break;
			} else if (c != ' ' && c != '\t') {
				break;
			}
		}

		// Insert the indented newline + closing brace (if needed)
		int caret = codeArea.getCaretPosition();
		if (closingBrace == '\0' || !recentKeys.contains(KeyCode.OPEN_BRACKET)) {
			codeArea.insertText(caret, '\n' + padding);
		} else {
			// Insert the '}' or ']' and move the caret between
			codeArea.insertText(caret, '\n' + padding + '\n' + StringUtil.limit(padding, padding.length() - 1) + closingBrace);
			codeArea.moveTo(caret + padding.length() + 1);
		}

		// Clear recent keys so that we reset the state of tracking for the open-bracket key.
		recentKeys.clear();
	}
Handles newline events. Inserts a new line, but matches the indentation level of the previous line.

@param event
		Key event where {@link KeyCode#ENTER} was pressed.
recaf-ui/src/main/java/software/coley/recaf/ui/control/richtext/Editor.java