From 0e1c82098855ed1d416e9fa42d0ca606689f5f43 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 25 Nov 2013 13:56:24 +0400 Subject: [PATCH] IDEA-113684 Soft wraps insert additional spaces --- .../injected/editor/EditorWindow.java | 6 ++- .../intellij/codeInsight/SoftWrapTest.java | 54 +++++++++++++++++++ xml/tests/testData/softWrap/softWrap.html | 12 +++++ .../testData/softWrap/softWrap_after.html | 12 +++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 xml/tests/src/com/intellij/codeInsight/SoftWrapTest.java create mode 100644 xml/tests/testData/softWrap/softWrap.html create mode 100644 xml/tests/testData/softWrap/softWrap_after.html diff --git a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java index ce8606677f3e..8b7da068f968 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java @@ -36,6 +36,7 @@ import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.LightHighlighterClient; import com.intellij.openapi.editor.impl.EditorImpl; +import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import com.intellij.openapi.editor.impl.TextDrawingCallback; import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces; import com.intellij.openapi.editor.markup.MarkupModel; @@ -73,6 +74,7 @@ public class EditorWindow extends UserDataHolderBase implements EditorEx { private boolean myDisposed; private final MarkupModelWindow myMarkupModelDelegate; private final FoldingModelWindow myFoldingModelWindow; + private final SoftWrapModelImpl mySoftWrapModel; public static Editor create(@NotNull final DocumentWindowImpl documentRange, @NotNull final EditorImpl editor, @NotNull final PsiFile injectedFile) { assert documentRange.isValid(); @@ -106,6 +108,8 @@ public class EditorWindow extends UserDataHolderBase implements EditorEx { mySelectionModelDelegate = new SelectionModelWindow(myDelegate, myDocumentWindow,this); myMarkupModelDelegate = new MarkupModelWindow((MarkupModelEx)myDelegate.getMarkupModel(), myDocumentWindow); myFoldingModelWindow = new FoldingModelWindow(delegate.getFoldingModel(), documentWindow, this); + mySoftWrapModel = new SoftWrapModelImpl(this); + Disposer.register(myDocumentWindow, mySoftWrapModel); } public static void disposeInvalidEditors() { @@ -262,7 +266,7 @@ public class EditorWindow extends UserDataHolderBase implements EditorEx { @Override @NotNull public SoftWrapModelEx getSoftWrapModel() { - return myDelegate.getSoftWrapModel(); + return mySoftWrapModel; } @Override diff --git a/xml/tests/src/com/intellij/codeInsight/SoftWrapTest.java b/xml/tests/src/com/intellij/codeInsight/SoftWrapTest.java new file mode 100644 index 000000000000..4de8e700def3 --- /dev/null +++ b/xml/tests/src/com/intellij/codeInsight/SoftWrapTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.impl.SoftWrapModelImpl; +import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; + +/** + * @author Dmitry Avdeev + * Date: 25.11.13 + */ +public class SoftWrapTest extends LightPlatformCodeInsightFixtureTestCase { + + public void testSoftWrapInInjection() throws Exception { + + myFixture.configureByFile("softWrap.html"); + Editor editor = myFixture.getEditor(); + editor.getSettings().setUseSoftWraps(true); + ((SoftWrapModelImpl)editor.getSoftWrapModel()).getApplianceManager().setWidthProvider(new SoftWrapApplianceManager.VisibleAreaWidthProvider() { + @Override + public int getVisibleAreaWidth() { + return 600; + } + }); + + myFixture.type('j'); + myFixture.checkResultByFile("softWrap_after.html"); + } + + @Override + protected String getBasePath() { + return "/xml/tests/testData/softWrap"; + } + + @Override + protected boolean isCommunity() { + return true; + } +} diff --git a/xml/tests/testData/softWrap/softWrap.html b/xml/tests/testData/softWrap/softWrap.html new file mode 100644 index 000000000000..dfddbbf95281 --- /dev/null +++ b/xml/tests/testData/softWrap/softWrap.html @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/xml/tests/testData/softWrap/softWrap_after.html b/xml/tests/testData/softWrap/softWrap_after.html new file mode 100644 index 000000000000..7d5c77a43e9a --- /dev/null +++ b/xml/tests/testData/softWrap/softWrap_after.html @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file