int (int lineCount) { int startLine = myLine; List<JoinLinesHandlerDelegate> list = JoinLinesHandlerDelegate.EP_NAME.getExtensionList(); int beforeLines = myDoc.getLineCount(); CharSequence text = myDoc.getCharsSequence(); int finalLine = myLine + lineCount; int finalOffset = myDoc.getLineEndOffset(myLine + lineCount); while (startLine < finalLine) { myIndicator.checkCanceled(); myIndicator.setFraction(0.1 + 0.2 * (startLine - myLine) / Math.max(1, finalLine - myLine)); int rc = CANNOT_JOIN; int lineEndOffset = myDoc.getLineEndOffset(startLine); int start = StringUtil.skipWhitespaceBackward(text, lineEndOffset); int end = CharArrayUtil.shiftForward(text, lineEndOffset, finalOffset, " \t\n"); int linesToJoin = myDoc.getLineNumber(end) - startLine; JoinRawLinesHandlerDelegate rawJoiner = null; if (end < finalOffset && start > 0 && text.charAt(start - 1) != '\n') { // Skip raw joiners if either of first or last lines is empty for (JoinLinesHandlerDelegate delegate : list) { if (delegate instanceof JoinRawLinesHandlerDelegate) { rawJoiner = (JoinRawLinesHandlerDelegate)delegate; rc = rawJoiner.tryJoinRawLines(myDoc, myFile, start, end); if (rc != CANNOT_JOIN) { myCaretRestoreOffset = checkOffset(rc, delegate, myDoc); break; } } } } if (rc == CANNOT_JOIN) { startLine += linesToJoin; } else { myManager.doPostponedOperationsAndUnblockDocument(myDoc); myManager.commitDocument(myDoc); int afterLines = myDoc.getLineCount(); if (afterLines > beforeLines) { LOG.error("Raw joiner increased number of lines: " + rawJoiner + " (" + rawJoiner.getClass() + ")"); } if (afterLines >= beforeLines && myLine == startLine) { // if number of lines is the same, continue processing from the next line myLine++; startLine++; } else { // Single Join two lines procedure could join more than two (e.g. if it removes braces) finalLine -= Math.max(beforeLines - afterLines, 1); } beforeLines = afterLines; text = myDoc.getCharsSequence(); if (finalLine >= startLine) { finalOffset = myDoc.getLineEndOffset(finalLine); } } } return startLine - myLine; }