2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.editor;
18 import com.intellij.openapi.actionSystem.IdeActions;
19 import com.intellij.openapi.editor.ex.EditorEx;
20 import com.intellij.openapi.editor.impl.AbstractEditorTest;
22 import java.io.IOException;
24 public class EditorMultiCaretColumnModeTest extends AbstractEditorTest {
25 public void testUpDown() throws Exception {
30 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
31 checkResultByText("line1\n" +
35 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION); // hitting document bottom
36 checkResultByText("line1\n" +
40 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
41 checkResultByText("line1\n" +
45 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION); // hitting document top
46 checkResultByText("li<caret>ne1\n" +
50 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
51 checkResultByText("li<caret>ne1\n" +
55 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
56 checkResultByText("line1\n" +
61 public void testPageUpDown() throws Exception {
69 setEditorVisibleSize(1000, 3);
71 executeAction("EditorPageUpWithSelection");
72 checkResultByText("line1\n" +
80 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
81 checkResultByText("line<caret>1\n" +
89 executeAction("EditorPageDownWithSelection");
90 checkResultByText("line1\n" +
98 executeAction("EditorPageDownWithSelection");
99 checkResultByText("line1\n" +
107 executeAction("EditorPageUpWithSelection");
108 checkResultByText("line1\n" +
117 public void testSelectionWithKeyboard() throws Exception {
122 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
123 checkResultByText("line1\n" +
124 "li<selection>n<caret></selection>e2\n" +
127 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
128 checkResultByText("line1\n" +
129 "li<selection>n<caret></selection>e2\n" +
130 "li<selection>n<caret></selection>e3");
132 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT_WITH_SELECTION);
133 checkResultByText("line1\n" +
137 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT_WITH_SELECTION);
138 checkResultByText("line1\n" +
139 "l<selection><caret>i</selection>ne2\n" +
140 "l<selection><caret>i</selection>ne3");
142 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
143 checkResultByText("line1\n" +
144 "l<selection><caret>i</selection>ne2\n" +
147 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
148 checkResultByText("l<selection><caret>i</selection>ne1\n" +
149 "l<selection><caret>i</selection>ne2\n" +
152 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
153 checkResultByText("li<caret>ne1\n" +
157 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
158 checkResultByText("li<selection>n<caret></selection>e1\n" +
159 "li<selection>n<caret></selection>e2\n" +
162 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
163 checkResultByText("line1\n" +
164 "li<selection>n<caret></selection>e2\n" +
167 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT_WITH_SELECTION);
168 checkResultByText("line1\n" +
173 public void testSelectNextPrevWord() throws Exception {
174 init("aaa aaa<caret>\n" +
176 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
177 executeAction("EditorPreviousWordWithSelection");
178 checkResultByText("aaa <selection><caret>aaa</selection>\n" +
179 "bbbb <selection><caret>bb</selection>bb");
180 executeAction("EditorNextWordWithSelection");
181 checkResultByText("aaa aaa<caret>\n" +
182 "bbbb bb<selection>bb<caret></selection>");
185 public void testMoveToSelectionStart() throws Exception {
187 mouse().clickAt(0, 2).dragTo(0, 4).release();
188 verifyCaretsAndSelections(0, 4, 2, 4);
190 executeAction("EditorLeft");
191 verifyCaretsAndSelections(0, 2, 2, 2);
194 public void testMoveToSelectionEnd() throws Exception {
196 mouse().clickAt(0, 4).dragTo(0, 2).release();
197 verifyCaretsAndSelections(0, 2, 2, 4);
199 executeAction("EditorRight");
200 verifyCaretsAndSelections(0, 4, 4, 4);
203 public void testReverseBlockSelection() throws Exception {
205 mouse().clickAt(0, 4).dragTo(0, 3).release();
206 verifyCaretsAndSelections(0, 3, 3, 4);
208 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
209 verifyCaretsAndSelections(0, 4, 4, 4);
212 public void testSelectionWithKeyboardInEmptySpace() throws Exception {
214 mouse().clickAt(1, 1);
215 verifyCaretsAndSelections(1, 1, 1, 1);
217 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
218 verifyCaretsAndSelections(1, 2, 1, 2);
220 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
221 verifyCaretsAndSelections(1, 2, 1, 2,
224 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT_WITH_SELECTION);
225 verifyCaretsAndSelections(1, 1, 1, 1,
228 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT_WITH_SELECTION);
229 verifyCaretsAndSelections(1, 0, 0, 1,
232 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
233 verifyCaretsAndSelections(1, 0, 0, 1);
235 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
236 verifyCaretsAndSelections(0, 0, 0, 1,
239 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
240 verifyCaretsAndSelections(0, 1, 1, 1,
243 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
244 verifyCaretsAndSelections(0, 2, 1, 2,
247 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
248 verifyCaretsAndSelections(1, 2, 1, 2);
250 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT_WITH_SELECTION);
251 verifyCaretsAndSelections(1, 1, 1, 1);
254 public void testBlockSelection() throws Exception {
258 mouse().clickAt(2, 4).dragTo(0, 1).release();
259 verifyCaretsAndSelections(0, 1, 1, 4,
264 public void testTyping() throws Exception {
268 mouse().clickAt(0, 2).dragTo(2, 3).release();
270 checkResultByText("a S<caret>\n" +
275 public void testCopyPasteOfShortLines() throws Exception {
279 mouse().clickAt(0, 2).dragTo(2, 4).release();
280 executeAction("EditorCopy");
281 executeAction("EditorLineStart");
282 executeAction("EditorPaste");
283 checkResultByText(" <caret>a\n" +
288 public void testPasteOfBlockToASingleCaret() throws Exception {
292 mouse().clickAt(1, 2).dragTo(2, 4).release();
293 executeAction("EditorCopy");
294 mouse().clickAt(0, 2);
295 executeAction("EditorPaste");
296 checkResultByText("a b <caret>\n" +
301 public void testSelectToDocumentStart() throws Exception {
306 mouse().clickAt(1, 1).dragTo(2, 2).release();
307 executeAction("EditorTextStartWithSelection");
308 checkResultByText("<selection><caret>l</selection>ine1\n" +
309 "<selection><caret>l</selection>ine2\n" +
314 public void testSelectToDocumentEnd() throws Exception {
319 mouse().clickAt(1, 1).dragTo(2, 2).release();
320 executeAction("EditorTextEndWithSelection");
321 checkResultByText("line1\n" +
322 "l<selection>ine2<caret></selection>\n" +
323 "l<selection>ine3<caret></selection>\n" +
324 "l<selection>ine4<caret></selection>");
327 public void testToggleCaseToLower() throws Exception {
331 mouse().clickAt(1, 2).dragTo(2, 4).release();
332 executeAction("EditorToggleCase");
333 checkResultByText("a\n" +
336 verifyCaretsAndSelections(1, 4, 2, 4,
340 public void testToggleCaseToUpper() throws Exception {
344 mouse().clickAt(1, 2).dragTo(2, 4).release();
345 executeAction("EditorToggleCase");
346 checkResultByText("a\n" +
349 verifyCaretsAndSelections(1, 4, 2, 4,
353 public void testSeparatedCarets() throws Exception {
361 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
362 checkResultByText("\n" +
369 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
370 checkResultByText("\n" +
377 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
378 checkResultByText("\n" +
385 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
386 checkResultByText("\n" +
393 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
394 checkResultByText("\n" +
401 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP_WITH_SELECTION);
402 checkResultByText("<caret>\n" +
409 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
410 checkResultByText("\n" +
417 executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN_WITH_SELECTION);
418 checkResultByText("\n" +
427 private void init(String text) throws IOException {
428 configureFromFileText(getTestName(false) + ".txt", text);
429 setEditorVisibleSize(1000, 1000);
430 ((EditorEx)myEditor).setColumnMode(true);