"Join lines" sometimes doesn't join all selected lines

This commit is contained in:
Dmitry Batrak
2016-11-23 08:59:23 +03:00
parent eab16f5297
commit eccfbecaee
4 changed files with 10 additions and 2 deletions
@@ -115,7 +115,7 @@ public class JoinLinesHandler extends EditorWriteActionHandler {
int caretRestoreOffset = -1;
// joining lines, several times if selection is multiline
for (int i = startLine; i < endLine; i++) {
if (i >= doc.getLineCount() - 1) break;
if (startLine >= doc.getLineCount() - 1) break;
docManager.doPostponedOperationsAndUnblockDocument(doc);
docManager.commitDocument(doc);
@@ -89,6 +89,7 @@ public interface IdeActions {
@NonNls String ACTION_CUT = "$Cut";
@NonNls String ACTION_DELETE = "$Delete";
@NonNls String ACTION_PASTE = "$Paste";
@NonNls String ACTION_SELECT_ALL = "$SelectAll";
@NonNls String ACTION_CONTEXT_HELP = "ContextHelp";
@NonNls String ACTION_EDIT_SOURCE = "EditSource";
@NonNls String ACTION_VIEW_SOURCE = "ViewSource";
@@ -54,7 +54,7 @@ public class JoinLinesAction extends TextComponentEditorAction {
int caretRestoreOffset = -1;
for (int i = startLine; i < endLine; i++) {
if (i >= doc.getLineCount() - 1) break;
if (startLine >= doc.getLineCount() - 1) break;
CharSequence text = doc.getCharsSequence();
int end = doc.getLineEndOffset(startLine) + doc.getLineSeparatorLength(startLine);
int start = end - doc.getLineSeparatorLength(startLine);
@@ -234,4 +234,11 @@ public class EditorActionTest extends AbstractEditorTest {
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_CASE);
checkResultByText("class C { String s = \"<selection>AB\\nCD<caret></selection>\"; }");
}
public void testJoinSeveralLinesAtDocumentEnd() throws Exception {
initText("a\nb\nc");
executeAction(IdeActions.ACTION_SELECT_ALL);
executeAction(IdeActions.ACTION_EDITOR_JOIN_LINES);
checkResultByText("a b c");
}
}