Fix set value
authorKevin Lamonte <kevin.lamonte@gmail.com>
Mon, 11 Feb 2019 20:32:27 +0000 (14:32 -0600)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Mon, 11 Feb 2019 20:32:27 +0000 (14:32 -0600)
src/jexer/TComboBox.java
src/jexer/TList.java

index 5748c36fd2819524b572bb529b4a8340e6b3eded..0814177d495d858ee02d6df734336dcd4fe41019 100644 (file)
@@ -282,11 +282,29 @@ public class TComboBox extends TWidget {
      * @param text the new text in the edit field
      */
     public void setText(final String text) {
+        setText(text, true);
+    }
+
+    /**
+     * Set combobox text value.
+     *
+     * @param text the new text in the edit field
+     * @param caseSensitive if true, perform a case-sensitive search for the
+     * list item
+     */
+    public void setText(final String text, final boolean caseSensitive) {
         field.setText(text);
         for (int i = 0; i < list.getMaxSelectedIndex(); i++) {
-            if (list.getSelected().equals(text)) {
-                list.setSelectedIndex(i);
-                return;
+            if (caseSensitive == true) {
+                if (list.getListItem(i).equals(text)) {
+                    list.setSelectedIndex(i);
+                    return;
+                }
+            } else {
+                if (list.getListItem(i).toLowerCase().equals(text.toLowerCase())) {
+                    list.setSelectedIndex(i);
+                    return;
+                }
             }
         }
         list.setSelectedIndex(-1);
index da60af18745737dbc5ed5ecaf7d3a9a08730f430..0ed7a070c5839da8147ba829bd5ff0a0dc7772fd 100644 (file)
@@ -406,6 +406,16 @@ public class TList extends TScrollableWidget {
         selectedString = index;
     }
 
+    /**
+     * Get a selectable string by index.
+     *
+     * @param idx index into list
+     * @return the string at idx in the list
+     */
+    public final String getListItem(final int idx) {
+        return strings.get(idx);
+    }
+
     /**
      * Get the selected string.
      *