mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-105705: select word at caret: expand selection document wide for non-physical documents - fix for CamelHumps enabled
This commit is contained in:
+10
-12
@@ -72,21 +72,19 @@ public class SelectWordAtCaretAction extends TextComponentEditorAction implement
|
||||
|
||||
if (ranges.isEmpty()) return;
|
||||
|
||||
int startWordOffset = Math.max(0, ranges.get(0).getStartOffset());
|
||||
int endWordOffset = Math.min(ranges.get(0).getEndOffset(), document.getTextLength());
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
final TextRange selectionRange = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
|
||||
|
||||
final SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (camel && ranges.size() == 2 && selectionModel.getSelectionStart() == startWordOffset &&
|
||||
selectionModel.getSelectionEnd() == endWordOffset) {
|
||||
startWordOffset = Math.max(0, ranges.get(1).getStartOffset());
|
||||
endWordOffset = Math.min(ranges.get(1).getEndOffset(), document.getTextLength());
|
||||
TextRange minimumRange = new TextRange(0, editor.getDocument().getTextLength());
|
||||
for (TextRange range : ranges) {
|
||||
if (range.contains(selectionRange) && !range.equals(selectionRange)) {
|
||||
if (minimumRange.contains(range)) {
|
||||
minimumRange = range;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (startWordOffset >= selectionModel.getSelectionStart() && selectionModel.getSelectionEnd() >= endWordOffset && ranges.size() == 1) {
|
||||
startWordOffset = 0;
|
||||
endWordOffset = document.getTextLength();
|
||||
}
|
||||
selectionModel.setSelection(startWordOffset, endWordOffset);
|
||||
selectionModel.setSelection(minimumRange.getStartOffset(), minimumRange.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-9
@@ -181,6 +181,25 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Editor configureFromFileTextWithoutPSI(@NonNls @NotNull final String fileText) {
|
||||
return new WriteCommandAction<Editor>(null) {
|
||||
@Override
|
||||
protected void run(@NotNull Result<Editor> result) throws Throwable {
|
||||
final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);
|
||||
EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
|
||||
|
||||
String newFileText = fakeDocument.getText();
|
||||
Document document = EditorFactory.getInstance().createDocument(newFileText);
|
||||
final Editor editor = EditorFactory.getInstance().createEditor(document);
|
||||
((EditorImpl)editor).setCaretActive();
|
||||
|
||||
EditorTestUtil.setCaretsAndSelection(editor, caretsState);
|
||||
result.setResult(editor);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
protected static Editor createEditor(@NotNull VirtualFile file) {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
Editor editor = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file, 0), false);
|
||||
@@ -325,29 +344,34 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
protected void checkResultByText(final String message, @NotNull final String fileText, final boolean ignoreTrailingSpaces, final String filePath) {
|
||||
bringRealEditorBack();
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
checkResultByText(message, myEditor, fileText, ignoreTrailingSpaces, filePath);
|
||||
}
|
||||
|
||||
protected static void checkResultByText(final String message,
|
||||
@NotNull final Editor editor,
|
||||
@NotNull final String fileText,
|
||||
final boolean ignoreTrailingSpaces,
|
||||
final String filePath) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Document document = EditorFactory.getInstance().createDocument(fileText);
|
||||
final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);
|
||||
|
||||
if (ignoreTrailingSpaces) {
|
||||
((DocumentImpl)document).stripTrailingSpaces(getProject());
|
||||
((DocumentImpl)fakeDocument).stripTrailingSpaces(getProject());
|
||||
}
|
||||
|
||||
EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(document);
|
||||
EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
|
||||
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
String newFileText = document.getText();
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
String fileText = myFile.getText();
|
||||
String newFileText = fakeDocument.getText();
|
||||
String fileText = editor.getDocument().getText();
|
||||
String failMessage = getMessage("Text mismatch", message);
|
||||
if (filePath != null && !newFileText.equals(fileText)) {
|
||||
throw new FileComparisonFailure(failMessage, newFileText, fileText, filePath);
|
||||
}
|
||||
assertEquals(failMessage, newFileText, fileText);
|
||||
|
||||
EditorTestUtil.verifyCaretAndSelectionState(myEditor, carets, message);
|
||||
EditorTestUtil.verifyCaretAndSelectionState(editor, carets, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user