IDEA-135089 Search and replace multiline text allows to input only three lines
authorVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Wed, 14 Jan 2015 13:29:01 +0000 (16:29 +0300)
committerVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Wed, 14 Jan 2015 13:30:52 +0000 (16:30 +0300)
platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java
platform/util/src/com/intellij/util/ui/UIUtil.java

index 747cea82df93c9ca197f22c9a6938369805b6a18..f30da0b39b4b820da46d16fa3407dee51dbade09 100644 (file)
@@ -450,6 +450,9 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
     else {
       nothingToSearchFor();
     }
+    if (mySearchField instanceof JTextArea) {
+      UIUtil.adjustRows((JTextArea)mySearchField, 2, 6);
+    }
   }
 
   public boolean isRegexp() {
@@ -637,6 +640,9 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
   private void replaceFieldDocumentChanged() {
     setMatchesLimit(LivePreviewController.MATCHES_LIMIT);
     myFindModel.setStringToReplace(myReplaceField.getText());
+    if (myReplaceField instanceof JTextArea) {
+        UIUtil.adjustRows((JTextArea)myReplaceField, 2, 6);
+    }
   }
 
   private boolean canReplaceCurrent() {
@@ -697,12 +703,17 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
           super.paintBorder(g);
           paintBorderOfTextField(g);
         }
+
+        @Override
+        public Dimension getPreferredSize() {
+          return super.getPreferredSize();
+        }
       };
       ((JTextArea)editorTextField).setColumns(25);
-      ((JTextArea)editorTextField).setRows(3);
+      ((JTextArea)editorTextField).setRows(2);
       final JScrollPane scrollPane = new JBScrollPane(editorTextField,
-                                                     ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
-                                                     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+                                                     ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+                                                     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
       myLeftComponent.add(scrollPane, constraint);
       componentRef.set(scrollPane);
     }
index 02bed0eedf02bb566317c190dbc47cdc036e92a7..6af544af77557b47bc2edf0365d19a6d28022b15 100644 (file)
@@ -3215,6 +3215,10 @@ public class UIUtil {
     textComponent.getActionMap().put("redoKeystroke", REDO_ACTION);
   }
 
+  public static void adjustRows(JTextArea area, int minRows, int maxRows) {
+    area.setRows(Math.max(minRows, Math.min(maxRows, area.getText().split("\n").length)));
+  }
+
   public static void playSoundFromResource(final String resourceName) {
     final Class callerClass = ReflectionUtil.getGrandCallerClass();
     if (callerClass == null) return;