/** * Joins several text lines to one line. * * @param document the document * @param startLine the start line * @param endLine the end line * @return the new caret offset * @throws BadLocationException if the document is accessed with wrong line or offset */ private int joinLines(IDocument document, int startLine, int endLine) throws BadLocationException { if (startLine == document.getNumberOfLines() - 1) { // do nothing because we are in the last line return -1; } if (startLine == endLine) endLine++; // append join with the next line StringBuilder buffer= new StringBuilder(); for (int line= startLine; line <= endLine; line++) { buffer.append(trim(document, line, line == startLine)); if (line != endLine) buffer.append(fJoint); } int startLineOffset= document.getLineOffset(startLine); int endLineOffset= document.getLineOffset(endLine) + document.getLineLength(endLine) - getLineDelimiterLength(document, endLine); String replaceString= buffer.toString(); document.replace(startLineOffset, endLineOffset - startLineOffset, replaceString); return startLineOffset + replaceString.length(); }
/** * Joins several text lines to one line. * * @param document the document * @param startLine the start line * @param endLine the end line * @return the new caret offset * @throws BadLocationException */ private int joinLines(IDocument document, int startLine, int endLine) throws BadLocationException { if (startLine == document.getNumberOfLines() - 1) { // do nothing because we are in the last line return -1; } if (startLine == endLine) endLine++; // append join with the next line StringBuffer buffer= new StringBuffer(); for (int line= startLine; line <= endLine; line++) { buffer.append(trim(document, line, line == startLine)); if (line != endLine) buffer.append(fJoint); } int startLineOffset= document.getLineOffset(startLine); int endLineOffset= document.getLineOffset(endLine) + document.getLineLength(endLine) - getLineDelimiterLength(document, endLine); String replaceString= buffer.toString(); document.replace(startLineOffset, endLineOffset - startLineOffset, replaceString); return startLineOffset + replaceString.length(); }
/** * Joins several text lines to one line. * * @param document the document * @param startLine the start line * @param endLine the end line * @return the new caret offset * @throws BadLocationException if the document is accessed with wrong line or offset */ private int joinLines(IDocument document, int startLine, int endLine) throws BadLocationException { if (startLine == document.getNumberOfLines() - 1) { // do nothing because we are in the last line return -1; } if (startLine == endLine) endLine++; // append join with the next line StringBuffer buffer= new StringBuffer(); for (int line= startLine; line <= endLine; line++) { buffer.append(trim(document, line, line == startLine)); if (line != endLine) buffer.append(fJoint); } int startLineOffset= document.getLineOffset(startLine); int endLineOffset= document.getLineOffset(endLine) + document.getLineLength(endLine) - getLineDelimiterLength(document, endLine); String replaceString= buffer.toString(); document.replace(startLineOffset, endLineOffset - startLineOffset, replaceString); return startLineOffset + replaceString.length(); }