| /* |
| * Copyright 2000-2014 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.openapi.editor.impl; |
| |
| import com.intellij.codeInsight.folding.CodeFoldingManager; |
| import com.intellij.openapi.actionSystem.IdeActions; |
| import com.intellij.openapi.editor.Document; |
| import com.intellij.openapi.editor.VisualPosition; |
| import com.intellij.testFramework.EditorTestUtil; |
| |
| import java.io.IOException; |
| |
| public class EditorImplTest extends AbstractEditorTest { |
| public void testPositionCalculationForZeroWidthChars() throws Exception { |
| init("some\u2044text"); |
| VisualPosition pos = new VisualPosition(0, 6); |
| VisualPosition recalculatedPos = myEditor.xyToVisualPosition(myEditor.visualPositionToXY(pos)); |
| assertEquals(pos, recalculatedPos); |
| } |
| |
| public void testPositionCalculationOnEmptyLine() throws Exception { |
| init("text with\n" + |
| "\n" + |
| "empty line"); |
| VisualPosition pos = new VisualPosition(1, 0); |
| VisualPosition recalculatedPos = myEditor.xyToVisualPosition(myEditor.visualPositionToXY(pos)); |
| assertEquals(pos, recalculatedPos); |
| } |
| |
| public void testShiftDragAddsToSelection() throws Exception { |
| init("A quick brown fox"); |
| EditorTestUtil.setEditorVisibleSize(myEditor, 1000, 1000); // enable drag testing |
| mouse().clickAt(0, 1); |
| mouse().shift().clickAt(0, 2).dragTo(0, 3).release(); |
| checkResultByText("A<selection> q<caret></selection>uick brown fox"); |
| } |
| |
| public void testSoftWrapsRecalculationInASpecificCase() throws Exception { |
| configureFromFileText(getTestName(false) + ".java", |
| "<selection>class Foo {\n" + |
| "\t@Override\n" + |
| "\tpublic boolean equals(Object other) {\n" + |
| "\t\treturn this == other;\n" + |
| "\t}\n" + |
| "}</selection>"); |
| CodeFoldingManager.getInstance(ourProject).buildInitialFoldings(myEditor); |
| EditorTestUtil.configureSoftWraps(myEditor, 32); |
| Document document = myEditor.getDocument(); |
| for (int i = document.getLineCount() - 1; i >= 0; i--) { |
| document.insertString(document.getLineStartOffset(i), "//"); |
| } |
| |
| verifySoftWrapPositions(58, 93); |
| } |
| |
| public void testCorrectVisibleLineCountCalculation() throws Exception { |
| init("line containing FOLDED_REGION\n" + |
| "next <caret>line\n" + |
| "last line"); |
| foldOccurrences("FOLDED_REGION", "..."); |
| EditorTestUtil.configureSoftWraps(myEditor, 16); // wrap right at folded region start |
| verifySoftWrapPositions(16); |
| |
| executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN); |
| checkResultByText("line containing FOLDED_REGION\n" + |
| "next line\n" + |
| "last <caret>line"); |
| } |
| |
| public void testInsertingFirstTab() throws Exception { |
| init(" <caret>space-indented line"); |
| EditorTestUtil.configureSoftWraps(myEditor, 100); |
| myEditor.getSettings().setUseTabCharacter(true); |
| |
| executeAction(IdeActions.ACTION_EDITOR_TAB); |
| checkResultByText(" \t<caret>space-indented line"); |
| } |
| |
| private void init(String text) throws IOException { |
| configureFromFileText(getTestName(false) + ".txt", text); |
| } |
| } |