From eafa46ce5406e2c8339a91b867050e46b157eab3 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 5 Oct 2015 19:10:27 +0300 Subject: [PATCH] IDEA-128385 kill to word end deletes past end of line --- .../editor/actions/KillToWordEndAction.java | 5 +- .../actions/KillToWordEndActionTest.java | 48 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillToWordEndAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillToWordEndAction.java index a8098cd0e289..e5326dad5b60 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillToWordEndAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillToWordEndAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.ide.KillRingTransferable; +import com.intellij.util.text.CharArrayUtil; /** * Stands for emacs kill-word command. @@ -61,7 +62,7 @@ public class KillToWordEndAction extends TextComponentEditorAction { } int end = lineEndOffset; - if (caretLine < document.getLineCount() - 1) { + if (caretLine < document.getLineCount() - 1 && CharArrayUtil.isEmptyOrSpaces(document.getImmutableCharSequence(), caretOffset, end)) { // No word end found between the current position and line end, hence, remove line feed sign if possible. end++; } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java index 7a02b7604937..1e6ef592ceed 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,9 @@ package com.intellij.openapi.editor.actions; import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.impl.CaretModelImpl; -import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.ide.KillRingTransferable; -import com.intellij.openapi.util.Disposer; import com.intellij.testFramework.LightPlatformCodeInsightTestCase; import org.jetbrains.annotations.NotNull; @@ -131,6 +127,20 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { assertEquals("first second", string); } + public void testBeforeLastWordAtLine() throws Exception { + configureFromFileText(getTestName(false) + ".txt", "abc def\nghi"); + killToWordEnd(); + checkResultByText("abc \nghi"); + assertEquals("def", getContents()); + } + + public void testBeforeLastWordAtLineWithTrailingSpace() throws Exception { + configureFromFileText(getTestName(false) + ".txt", "abc def \nghi"); + killToWordEnd(); + checkResultByText("abc \nghi"); + assertEquals("def", getContents()); + } + public void testSubsequentKillsInterruptedBySave() throws Exception { String text = "public class ParentCopy {\n" + " public Insets getBorderInsets(Component c) {\n" + @@ -157,28 +167,22 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { " }"; configureFromFileText(getTestName(false) + ".java", text); final FoldingModel model = myEditor.getFoldingModel(); - model.runBatchFoldingOperation(new Runnable() { - @Override - public void run() { - final FoldRegion foldRegion = model.addFoldRegion(70, 90, ""); - assertNotNull(foldRegion); - foldRegion.setExpanded(false); - assertFalse(foldRegion.isExpanded()); - } + model.runBatchFoldingOperation(() -> { + final FoldRegion foldRegion = model.addFoldRegion(70, 90, ""); + assertNotNull(foldRegion); + foldRegion.setExpanded(false); + assertFalse(foldRegion.isExpanded()); }); cutToLineEnd(); cutToLineEnd(); - model.runBatchFoldingOperationDoNotCollapseCaret(new Runnable() { - @Override - public void run() { - final FoldRegion[] regions = model.getAllFoldRegions(); - for (FoldRegion region : regions) { - assertNotNull(region); - region.setExpanded(true); - } - + model.runBatchFoldingOperationDoNotCollapseCaret(() -> { + final FoldRegion[] regions = model.getAllFoldRegions(); + for (FoldRegion region : regions) { + assertNotNull(region); + region.setExpanded(true); } + }); cutToLineEnd(); cutToLineEnd();