mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.find;
|
||||
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
|
||||
public class EditorSearchComponentTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
private static final String THE_CODE = "public class A {\n" +
|
||||
" //First comment ABC, ABCD, abc\n" +
|
||||
" int ABC = 3;\n" +
|
||||
" int abcde = 4;\n" +
|
||||
" String literalString = \"ABC, ABCD, abc\";\n" +
|
||||
"}";
|
||||
|
||||
public void testSearchFieldSelection() {
|
||||
myFixture.configureByText("a.java", THE_CODE);
|
||||
String key = "ABC";
|
||||
int i = THE_CODE.indexOf(key);
|
||||
myFixture.getEditor().getSelectionModel().setSelection(i, i+key.length());
|
||||
myFixture.performEditorAction("Find");
|
||||
IdeEventQueue.getInstance().flushQueue();
|
||||
assertEquals(key, getEditorSearchComponent().getSearchTextComponent().getText());
|
||||
assertEquals(key, getEditorSearchComponent().getSearchTextComponent().getSelectedText());
|
||||
assertEquals(3, getEditorSearchComponent().getSearchTextComponent().getCaretPosition());
|
||||
assertTrue(getEditorSearchComponent().hasMatches());
|
||||
IdeFocusManager.findInstance().requestFocus(myFixture.getEditor().getContentComponent(), false);
|
||||
IdeEventQueue.getInstance().flushQueue();
|
||||
|
||||
myFixture.performEditorAction("Find");
|
||||
IdeEventQueue.getInstance().flushQueue();
|
||||
assertEquals(key, getEditorSearchComponent().getSearchTextComponent().getText());
|
||||
assertEquals(key, getEditorSearchComponent().getSearchTextComponent().getSelectedText());
|
||||
assertEquals(key.length(), getEditorSearchComponent().getSearchTextComponent().getCaretPosition());
|
||||
|
||||
getEditorSearchComponent().close();
|
||||
|
||||
key = "abcde";
|
||||
i = THE_CODE.indexOf(key);
|
||||
myFixture.getEditor().getSelectionModel().setSelection(i, i+key.length());
|
||||
IdeEventQueue.getInstance().flushQueue();
|
||||
myFixture.performEditorAction("Find");
|
||||
IdeEventQueue.getInstance().flushQueue();
|
||||
assertEquals(key, getEditorSearchComponent().getSearchTextComponent().getText());
|
||||
assertEquals(key, getEditorSearchComponent().getSearchTextComponent().getSelectedText());
|
||||
assertEquals(key.length(), getEditorSearchComponent().getSearchTextComponent().getCaretPosition());
|
||||
|
||||
}
|
||||
|
||||
private EditorSearchComponent getEditorSearchComponent() {
|
||||
return (EditorSearchComponent)myFixture.getEditor().getHeaderComponent();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -263,14 +263,18 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
|
||||
private void updateSearchComponent() {
|
||||
final int oldCaretPosition = mySearchTextComponent != null ? mySearchTextComponent.getCaretPosition() : 0;
|
||||
String oldText = mySearchTextComponent != null ? mySearchTextComponent.getText() : myFindModel.getStringToFind();
|
||||
boolean wasNull = mySearchTextComponent == null;
|
||||
String textToSet = mySearchTextComponent != null ? mySearchTextComponent.getText() : myFindModel.getStringToFind();
|
||||
|
||||
if (!updateTextComponent(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldText != null) {
|
||||
mySearchTextComponent.setText(oldText);
|
||||
if (textToSet != null) {
|
||||
mySearchTextComponent.setText(textToSet);
|
||||
if (wasNull) {
|
||||
mySearchTextComponent.selectAll();
|
||||
}
|
||||
}
|
||||
mySearchTextComponent.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
@@ -297,13 +301,14 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, SystemInfo.isMac ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK),
|
||||
JComponent.WHEN_FOCUSED);
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mySearchTextComponent.setCaretPosition(oldCaretPosition);
|
||||
}
|
||||
});
|
||||
if (!wasNull) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mySearchTextComponent.setCaretPosition(oldCaretPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
new RestorePreviousSettingsAction(this, mySearchTextComponent);
|
||||
new VariantsCompletionAction(mySearchTextComponent); // It registers a shortcut set automatically on construction
|
||||
@@ -381,11 +386,6 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
updateMultiLineStateIfNeed();
|
||||
}
|
||||
|
||||
private static void setupHistoryToSearchField(SearchTextField field, String[] strings) {
|
||||
field.setHistorySize(20);
|
||||
field.setHistory(ContainerUtil.reverse(Arrays.asList(strings)));
|
||||
}
|
||||
|
||||
private void initSearchToolbars() {
|
||||
DefaultActionGroup actionGroup1 = new DefaultActionGroup("search bar 1", false);
|
||||
mySearchActionsToolbar1 = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true);
|
||||
@@ -647,9 +647,10 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
if (UIUtil.isUnderGTKLookAndFeel()) {
|
||||
textComponent.setOpaque(false);
|
||||
}
|
||||
setupHistoryToSearchField(searchTextField, search
|
||||
searchTextField.setHistorySize(20);
|
||||
searchTextField.setHistory(ContainerUtil.reverse(Arrays.asList(search
|
||||
? FindSettings.getInstance().getRecentFindStrings()
|
||||
: FindSettings.getInstance().getRecentReplaceStrings());
|
||||
: FindSettings.getInstance().getRecentReplaceStrings())));
|
||||
textComponent.registerKeyboardAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
Reference in New Issue
Block a user