mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-131657 Don't expand foldings on 'Move Caret to Next/Previous Word' actions
This commit is contained in:
@@ -46,6 +46,8 @@ public interface IdeActions {
|
||||
@NonNls String ACTION_EDITOR_MOVE_CARET_PAGE_DOWN = "EditorPageDown";
|
||||
@NonNls String ACTION_EDITOR_NEXT_WORD = "EditorNextWord";
|
||||
@NonNls String ACTION_EDITOR_PREVIOUS_WORD = "EditorPreviousWord";
|
||||
@NonNls String ACTION_EDITOR_NEXT_WORD_WITH_SELECTION = "EditorNextWordWithSelection";
|
||||
@NonNls String ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION = "EditorPreviousWordWithSelection";
|
||||
@NonNls String ACTION_EDITOR_TAB = "EditorTab";
|
||||
@NonNls String ACTION_EDITOR_ESCAPE = "EditorEscape";
|
||||
@NonNls String ACTION_EDITOR_JOIN_LINES = "EditorJoinLines";
|
||||
|
||||
+43
-19
@@ -603,23 +603,35 @@ public class EditorActionUtil {
|
||||
: caretModel.getLogicalPosition();
|
||||
|
||||
int offset = caretModel.getOffset();
|
||||
CharSequence text = document.getCharsSequence();
|
||||
if (offset == document.getTextLength()) {
|
||||
return;
|
||||
}
|
||||
int newOffset = offset + 1;
|
||||
int lineNumber = caretModel.getLogicalPosition().line;
|
||||
if (lineNumber >= document.getLineCount()) return;
|
||||
int maxOffset = document.getLineEndOffset(lineNumber);
|
||||
if (newOffset > maxOffset) {
|
||||
if (lineNumber + 1 >= document.getLineCount()) {
|
||||
return;
|
||||
}
|
||||
maxOffset = document.getLineEndOffset(lineNumber + 1);
|
||||
|
||||
int newOffset;
|
||||
|
||||
FoldRegion currentFoldRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(offset);
|
||||
if (currentFoldRegion != null) {
|
||||
newOffset = currentFoldRegion.getEndOffset();
|
||||
}
|
||||
for (; newOffset < maxOffset; newOffset++) {
|
||||
if (isWordOrLexemeStart(editor, newOffset, camel)) {
|
||||
break;
|
||||
else {
|
||||
newOffset = offset + 1;
|
||||
int lineNumber = caretModel.getLogicalPosition().line;
|
||||
if (lineNumber >= document.getLineCount()) return;
|
||||
int maxOffset = document.getLineEndOffset(lineNumber);
|
||||
if (newOffset > maxOffset) {
|
||||
if (lineNumber + 1 >= document.getLineCount()) {
|
||||
return;
|
||||
}
|
||||
maxOffset = document.getLineEndOffset(lineNumber + 1);
|
||||
}
|
||||
for (; newOffset < maxOffset; newOffset++) {
|
||||
if (isWordOrLexemeStart(editor, newOffset, camel)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
FoldRegion foldRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(newOffset);
|
||||
if (foldRegion != null) {
|
||||
newOffset = foldRegion.getStartOffset();
|
||||
}
|
||||
}
|
||||
caretModel.moveToOffset(newOffset);
|
||||
@@ -687,13 +699,25 @@ public class EditorActionUtil {
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
if (offset == 0) return;
|
||||
|
||||
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
|
||||
CharSequence text = document.getCharsSequence();
|
||||
int newOffset = offset - 1;
|
||||
int minOffset = lineNumber > 0 ? document.getLineEndOffset(lineNumber - 1) : 0;
|
||||
for (; newOffset > minOffset; newOffset--) {
|
||||
if (isWordOrLexemeStart(editor, newOffset, camel)) break;
|
||||
int newOffset;
|
||||
|
||||
FoldRegion currentFoldRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(offset - 1);
|
||||
if (currentFoldRegion != null) {
|
||||
newOffset = currentFoldRegion.getStartOffset();
|
||||
}
|
||||
else {
|
||||
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
|
||||
newOffset = offset - 1;
|
||||
int minOffset = lineNumber > 0 ? document.getLineEndOffset(lineNumber - 1) : 0;
|
||||
for (; newOffset > minOffset; newOffset--) {
|
||||
if (isWordOrLexemeStart(editor, newOffset, camel)) break;
|
||||
}
|
||||
FoldRegion foldRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(newOffset);
|
||||
if (foldRegion != null && newOffset > foldRegion.getStartOffset()) {
|
||||
newOffset = foldRegion.getEndOffset();
|
||||
}
|
||||
}
|
||||
|
||||
editor.getCaretModel().moveToOffset(newOffset);
|
||||
EditorModificationUtil.scrollToCaret(editor);
|
||||
|
||||
|
||||
+42
@@ -16,6 +16,8 @@
|
||||
package com.intellij.openapi.editor.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.editor.FoldRegion;
|
||||
import com.intellij.testFramework.EditorTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
|
||||
/**
|
||||
@@ -52,4 +54,44 @@ public class NextPrevWordTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD);
|
||||
myFixture.checkResult("class Foo { String s = \"a\\x<caret>b\"; }");
|
||||
}
|
||||
|
||||
public void testPrevNextWordWithFolding() {
|
||||
myFixture.configureByText("a.txt", "<caret>brown fox");
|
||||
EditorTestUtil.addFoldRegion(myFixture.getEditor(), 4, 7, "...", true);
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
|
||||
myFixture.checkResult("brow<caret>n fox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
|
||||
myFixture.checkResult("brown f<caret>ox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
|
||||
myFixture.checkResult("brown fox<caret>");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD);
|
||||
myFixture.checkResult("brown f<caret>ox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD);
|
||||
myFixture.checkResult("brow<caret>n fox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD);
|
||||
myFixture.checkResult("<caret>brown fox");
|
||||
FoldRegion[] foldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions();
|
||||
assertEquals(1, foldRegions.length);
|
||||
assertFalse(foldRegions[0].isExpanded());
|
||||
}
|
||||
|
||||
public void testPrevNextWordWithSelectionAndFolding() {
|
||||
myFixture.configureByText("a.txt", "<caret>brown fox");
|
||||
EditorTestUtil.addFoldRegion(myFixture.getEditor(), 4, 7, "...", true);
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION);
|
||||
myFixture.checkResult("<selection>brow<caret></selection>n fox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION);
|
||||
myFixture.checkResult("<selection>brown f<caret></selection>ox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION);
|
||||
myFixture.checkResult("<selection>brown fox<caret></selection>");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION);
|
||||
myFixture.checkResult("<selection>brown f<caret></selection>ox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION);
|
||||
myFixture.checkResult("<selection>brow<caret></selection>n fox");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION);
|
||||
myFixture.checkResult("<caret>brown fox");
|
||||
FoldRegion[] foldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions();
|
||||
assertEquals(1, foldRegions.length);
|
||||
assertFalse(foldRegions[0].isExpanded());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user