From d50971ecbe33eb4aee58bcf7934d824416acad05 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Fri, 4 May 2012 14:30:01 +0400 Subject: [PATCH] IDEA-85624 doesn't work correctly for wrapped commit comment --- .../openapi/editor/actions/DeleteAction.java | 7 +++++-- ...tWrapApplianceOnDocumentModificationTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteAction.java index 40464840f388..4f03351c1bc1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -106,7 +106,10 @@ public class DeleteAction extends EditorAction { Document document = editor.getDocument(); int offset = editor.getCaretModel().getOffset(); if (!EditorActionUtil.canEditAtOffset(editor, offset + 1)) return; - if (afterLineEnd < 0) { + if (afterLineEnd < 0 + // There is a possible case that caret is located right before the soft wrap position at the last logical line + // (popular use case with the soft wraps at the commit message dialog). + || (offset < document.getTextLength() - 1 && editor.getSoftWrapModel().getSoftWrap(offset) != null)) { FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(offset); if (region != null && region.shouldNeverExpand()) { document.deleteString(region.getStartOffset(), region.getEndOffset()); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java index 9bfd5262dd1c..c2e95e03e9f5 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceOnDocumentModificationTest.java @@ -952,6 +952,22 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP checkSoftWraps(start, end); assertEquals(new VisualPosition(3, 0), myEditor.offsetToVisualPosition(text.indexOf("second"))); } + + public void testDeleteWhenCaretBeforeSoftWrap() throws IOException { + final String text = + "text 1234"; + init(7, text); + + final int offset = text.indexOf("123"); + checkSoftWraps(offset); + + final CaretModel caretModel = myEditor.getCaretModel(); + caretModel.moveToOffset(offset); + caretModel.moveCaretRelatively(-1, 0, false, false, false); + assertEquals(offset, caretModel.getOffset()); // Navigating from 'after soft wrap' to the 'before soft wrap' position. + delete(); + assertEquals("text 234", myEditor.getDocument().getText()); + } private void init(final int visibleWidthInColumns, @NotNull String fileText) throws IOException { int symbolWidthInPixels = 7;