From 0f781d5b8cc1cb53a6148902f2d12764cbb5e1ef Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 31 Jan 2011 10:33:19 +0300 Subject: [PATCH] 1. Reverted incorrect commit; 2. Checking if target offset belongs to document range; --- .../openapi/editor/GenericLineWrapPositionStrategy.java | 4 ++-- .../impl/softwrap/mapping/SoftWrapApplianceManager.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java b/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java index 911982812186..c32530cc9f3d 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java @@ -59,7 +59,7 @@ public class GenericLineWrapPositionStrategy implements LineWrapPositionStrategy maxPreferredOffsetToUse = maxPreferredOffsetToUse < startOffset ? startOffset : maxPreferredOffsetToUse; // Try to find out wrap position before preferred offset. - for (int i = maxPreferredOffsetToUse; i > startOffset; i--) { + for (int i = Math.min(maxPreferredOffsetToUse, text.length() - 1); i > startOffset; i--) { char c = text.charAt(i); if (c == '\n') { return i + 1; @@ -99,7 +99,7 @@ public class GenericLineWrapPositionStrategy implements LineWrapPositionStrategy // Try to find target offset that is beyond preferred offset. // Note that we don't consider symbol weights here and just break on the first appropriate position. - if (!allowToBeyondMaxPreferredOffset) { + if (!allowToBeyondMaxPreferredOffset || maxPreferredOffset >= text.length() - 1) { return maxPreferredOffset; } for (int i = maxPreferredOffsetToUse + 1; i < endOffset; i++) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java index 367b99fc24aa..9579adba8dac 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java @@ -472,8 +472,7 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen return i; } } - assert end > 0; - return end - 1; + return end; } private static int calculateWidthInColumns(char c, int widthInPixels, int spaceWithInPixels) {