11package com .cleanroommc .modularui .widgets .textfield ;
22
3+ import com .cleanroommc .modularui .ModularUI ;
34import com .cleanroommc .modularui .ModularUIConfig ;
45import com .cleanroommc .modularui .api .ITheme ;
56import com .cleanroommc .modularui .api .widget .IFocusedWidget ;
1415import com .cleanroommc .modularui .widget .scroll .ScrollData ;
1516import com .cleanroommc .modularui .widgets .VoidWidget ;
1617
18+ import net .minecraft .client .Minecraft ;
1719import net .minecraft .client .gui .GuiScreen ;
1820
1921import org .jetbrains .annotations .NotNull ;
@@ -42,6 +44,7 @@ public class BaseTextFieldWidget<W extends BaseTextFieldWidget<W>> extends Abstr
4244 private static final Pattern BASE_PATTERN = Pattern .compile ("[^§]" );
4345
4446 private static final int CURSOR_BLINK_RATE = 10 ;
47+ private static final int DOUBLE_CLICK_THRESHOLD = 300 ; // max time between clicks to count as double-click in ms
4548
4649 protected TextFieldHandler handler = new TextFieldHandler (this );
4750 protected TextFieldRenderer renderer = new TextFieldRenderer (this .handler );
@@ -51,6 +54,7 @@ public class BaseTextFieldWidget<W extends BaseTextFieldWidget<W>> extends Abstr
5154 protected float scale = 1f ;
5255 protected boolean focusOnGuiOpen ;
5356 private int cursorTimer ;
57+ protected long lastClickTime = 0 ;
5458
5559 protected Integer textColor ;
5660 protected Integer markedColor ;
@@ -171,7 +175,27 @@ public void onRemoveFocus(ModularGuiContext context) {
171175 // the current transformation does not include the transformation of the children (the scroll) so we need to manually transform here
172176 int x = getContext ().getMouseX () + getScrollX ();
173177 int y = getContext ().getMouseY () + getScrollY ();
178+ long now = Minecraft .getSystemTime ();
179+ if (this .lastClickTime < 0 ) {
180+ // triple click
181+ if (now + this .lastClickTime < DOUBLE_CLICK_THRESHOLD ) {
182+ this .handler .markAll ();
183+ this .lastClickTime = 0 ;
184+ return Result .SUCCESS ;
185+ }
186+ this .lastClickTime = 0 ;
187+ } else if (this .lastClickTime > 0 ) {
188+ // double click
189+ if (now - this .lastClickTime < DOUBLE_CLICK_THRESHOLD ) {
190+ this .handler .markCurrentLine ();
191+ this .lastClickTime = -Minecraft .getSystemTime ();
192+ return Result .SUCCESS ;
193+ }
194+ this .lastClickTime = 0 ;
195+ }
196+ // single click
174197 this .handler .setCursor (this .renderer .getCursorPos (this .handler .getText (), x , y ), true );
198+ this .lastClickTime = Minecraft .getSystemTime ();
175199 }
176200 return Result .SUCCESS ;
177201 }
0 commit comments