Added a double-click listener in UIText, allowing user to select all the text
import org.terasology.rendering.nui.events.NUIMouseClickEvent;
import org.terasology.rendering.nui.events.NUIMouseDragEvent;
import org.terasology.rendering.nui.events.NUIMouseReleaseEvent;
+import org.terasology.rendering.nui.events.NUIMouseDoubleClickEvent;
import org.terasology.utilities.Assets;
import java.awt.Toolkit;
@@ -149,6 +150,23 @@ public void onMouseRelease(NUIMouseReleaseEvent event) {
dragging = false;
}
}
+
+ /**
+ * Defines what to do when the user double-clicks a mouse button while pointing at the widget. More specifically,
+ * it selects all the text, if there is any.
+ *
+ * @param event The event corresponding to the mouse double-click
+ * @return Whether a left mouse double-click was successfully detected and handled
+ */
+ @Override
+ public boolean onMouseDoubleClick(NUIMouseDoubleClickEvent event) {
+ if (!getText().isEmpty() && event.getMouseButton() == MouseInput.MOUSE_LEFT){
+ setCursorPosition(getText().length());
+ selectionStart = 0;
+ return true;
+ }
+ return false;
+ }
};
/* The placeholder hint text. */
