Skip to content

Commit 907f232

Browse files
committed
Fix BetterLineEdit text selection bug
1 parent eb8cb30 commit 907f232

18 files changed

+53
-103
lines changed

src/ui_elements/BetterLineEdit.gd

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const ContextPopup = preload("res://src/ui_elements/context_popup.tscn")
99

1010
var hovered := false
1111

12-
@export var code_font_tooltip := false ## Use the mono font for the tooltip.
12+
## When turned on, uses the mono font for the tooltip.
13+
@export var code_font_tooltip := false
1314

1415
func _init() -> void:
1516
context_menu_enabled = false
@@ -23,11 +24,15 @@ func _ready() -> void:
2324
text_submitted.connect(release_focus.unbind(1))
2425

2526
func _input(event: InputEvent) -> void:
26-
if has_focus() and event is InputEventMouseButton:
27-
if event.is_pressed() and not get_global_rect().has_point(event.position):
28-
release_focus()
29-
text_submitted.emit(text)
30-
elif event.is_released() and first_click and not has_selection():
27+
if has_focus():
28+
if event is InputEventMouseButton:
29+
if event.is_pressed() and not get_global_rect().has_point(event.position):
30+
release_focus()
31+
text_submitted.emit(text)
32+
elif event.is_released() and first_click and not has_selection():
33+
first_click = false
34+
select_all()
35+
elif first_click:
3136
first_click = false
3237
select_all()
3338

src/ui_elements/color_field.gd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func _ready() -> void:
4040
set_value(attribute.get_value())
4141
attribute.value_changed.connect(set_value)
4242
color_edit.tooltip_text = attribute_name
43+
color_button.resized.connect(queue_redraw)
4344

4445

4546
func _on_button_pressed() -> void:
@@ -86,11 +87,6 @@ func is_valid(text: String) -> bool:
8687
return ColorParser.is_valid(ColorParser.add_hash_if_hex(text))
8788

8889

89-
func _on_button_resized() -> void:
90-
# Not sure why this is needed, but the button doesn't have a correct size at first
91-
# which screws with the drawing logic.
92-
queue_redraw()
93-
9490
func _on_text_changed(new_text: String) -> void:
9591
color_edit.add_theme_color_override("font_color",
9692
GlobalSettings.get_validity_color(!is_valid(new_text)))

src/ui_elements/color_field.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ theme_type_variation = &"LeftConnectedButtonTransparent"
3232
[connection signal="text_submitted" from="LineEdit" to="." method="_on_text_submitted"]
3333
[connection signal="gui_input" from="Button" to="." method="_on_button_gui_input"]
3434
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
35-
[connection signal="resized" from="Button" to="." method="_on_button_resized"]

src/ui_elements/enum_field.gd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func _on_button_pressed() -> void:
3131
var value_picker := ContextPopup.instantiate()
3232
var btn_arr: Array[Button] = []
3333
for enum_constant in attribute.possible_values:
34-
var btn := Utils.create_btn(enum_constant, _on_option_pressed.bind(enum_constant),
34+
var btn := Utils.create_btn(enum_constant, set_value.bind(enum_constant),
3535
enum_constant == attribute.get_value())
3636
if enum_constant == attribute.default:
3737
btn.add_theme_font_override("font", bold_font)
@@ -40,9 +40,6 @@ func _on_button_pressed() -> void:
4040
value_picker.setup(btn_arr, false, size.x)
4141
Utils.popup_under_rect(value_picker, indicator.get_global_rect(), get_viewport())
4242

43-
func _on_option_pressed(option: String) -> void:
44-
set_value(option)
45-
4643

4744
func _on_focus_entered() -> void:
4845
indicator.remove_theme_color_override("font_color")

src/ui_elements/good_color_picker.gd

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ func setup_color(new_color: String) -> void:
9797
update()
9898

9999
func _ready() -> void:
100-
alpha_slider.visible = alpha_enabled
100+
# Set up signals.
101+
widgets_arr[0].gui_input.connect(parse_slider_input.bind(0, true))
102+
for i in [1, 2, 3]:
103+
widgets_arr[i].gui_input.connect(parse_slider_input.bind(i))
104+
if alpha_enabled:
105+
alpha_slider.visible = alpha_enabled
106+
widgets_arr[4].gui_input.connect(parse_slider_input.bind(4))
107+
# Set up the rest.
101108
RenderingServer.canvas_item_set_parent(color_wheel_surface,
102109
color_wheel_drawn.get_canvas_item())
103110

@@ -238,21 +245,6 @@ func parse_slider_input(event: InputEvent, idx: int, is_slider_vertical := false
238245
elif Utils.is_event_drag_end(event):
239246
end_slider_drag(idx)
240247

241-
func _on_side_slider_gui_input(event: InputEvent) -> void:
242-
parse_slider_input(event, 0, true)
243-
244-
func _on_slider1_gui_input(event: InputEvent) -> void:
245-
parse_slider_input(event, 1)
246-
247-
func _on_slider2_gui_input(event: InputEvent) -> void:
248-
parse_slider_input(event, 2)
249-
250-
func _on_slider3_gui_input(event: InputEvent) -> void:
251-
parse_slider_input(event, 3)
252-
253-
func _on_slider4_gui_input(event: InputEvent) -> void:
254-
parse_slider_input(event, 4)
255-
256248
func _on_slider1_text_submitted(new_text: String) -> void:
257249
var new_color := display_color
258250
match slider_mode:

src/ui_elements/good_color_picker.tscn

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ script = ExtResource("6_aqyoh")
312312

313313
[connection signal="gui_input" from="ShapeContainer/ColorWheel" to="." method="_on_color_wheel_gui_input"]
314314
[connection signal="draw" from="ShapeContainer/SideSlider" to="." method="_on_side_slider_draw"]
315-
[connection signal="gui_input" from="ShapeContainer/SideSlider" to="." method="_on_side_slider_gui_input"]
316315
[connection signal="pressed" from="ColorContainer/NoneButton" to="." method="_on_none_button_pressed"]
317316
[connection signal="draw" from="ColorContainer/ColorsDisplay/StartColorRect" to="." method="_on_start_color_rect_draw"]
318317
[connection signal="draw" from="ColorContainer/ColorsDisplay/ColorRect" to="." method="_on_color_rect_draw"]
@@ -321,18 +320,14 @@ script = ExtResource("6_aqyoh")
321320
[connection signal="pressed" from="SliderContainer/ColorSpaceContainer/RGB" to="." method="_on_rgb_pressed"]
322321
[connection signal="pressed" from="SliderContainer/ColorSpaceContainer/HSV" to="." method="_on_hsv_pressed"]
323322
[connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/MarginContainer" to="." method="_on_slider1_draw"]
324-
[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/MarginContainer" to="." method="_on_slider1_gui_input"]
325323
[connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/MarginContainer/ColorTrack" to="." method="_on_track_resized"]
326324
[connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider1/IntField" to="." method="_on_slider1_text_submitted"]
327325
[connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/MarginContainer" to="." method="_on_slider2_draw"]
328-
[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/MarginContainer" to="." method="_on_slider2_gui_input"]
329326
[connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/MarginContainer/ColorTrack" to="." method="_on_track_resized"]
330327
[connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider2/IntField" to="." method="_on_slider2_text_submitted"]
331328
[connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/MarginContainer" to="." method="_on_slider3_draw"]
332-
[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/MarginContainer" to="." method="_on_slider3_gui_input"]
333329
[connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/MarginContainer/ColorTrack" to="." method="_on_track_resized"]
334330
[connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider3/IntField" to="." method="_on_slider3_text_submitted"]
335331
[connection signal="draw" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/MarginContainer" to="." method="_on_slider4_draw"]
336-
[connection signal="gui_input" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/MarginContainer" to="." method="_on_slider4_gui_input"]
337332
[connection signal="resized" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/MarginContainer/ColorTrack" to="." method="_on_track_resized"]
338333
[connection signal="text_submitted" from="SliderContainer/HBoxContainer/TracksContainer/Slider4/IntField" to="." method="_on_slider4_text_submitted"]

src/ui_elements/number_field_with_slider.gd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func _ready() -> void:
5454
set_value(attribute.get_value())
5555
attribute.value_changed.connect(set_value)
5656
num_edit.tooltip_text = attribute_name
57+
slider.resized.connect(queue_redraw) # Whyyyyy are their sizes wrong at first...
5758

5859
func _on_focus_entered() -> void:
5960
num_edit.remove_theme_color_override("font_color")
@@ -124,9 +125,6 @@ func _draw() -> void:
124125
draw_rect(Rect2(0, 1 + slider_size.y - 4 - fill_height,
125126
slider_size.x - 2, fill_height), Color("#def8"))
126127

127-
func _on_slider_resized() -> void:
128-
queue_redraw() # Whyyyyy are their sizes wrong at first...
129-
130128
func _on_slider_gui_input(event: InputEvent) -> void:
131129
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and\
132130
event.is_pressed():

src/ui_elements/number_field_with_slider.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ keep_pressed_outside = true
3434
[connection signal="text_submitted" from="LineEdit" to="." method="_on_text_submitted"]
3535
[connection signal="gui_input" from="Slider" to="." method="_on_slider_gui_input"]
3636
[connection signal="mouse_exited" from="Slider" to="." method="_on_slider_mouse_exited"]
37-
[connection signal="resized" from="Slider" to="." method="_on_slider_resized"]

src/ui_elements/path_command_editor.gd

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func _on_relative_button_pressed() -> void:
3737
func _ready() -> void:
3838
Indications.selection_changed.connect(determine_selection_state)
3939
Indications.hover_changed.connect(determine_selection_state)
40+
mouse_entered.connect(_on_mouse_entered)
41+
mouse_exited.connect(_on_mouse_exited)
4042
setup()
4143

4244
func setup() -> void:
@@ -217,6 +219,21 @@ func _on_mouse_entered() -> void:
217219
if not active:
218220
activate()
219221

222+
func _on_mouse_exited() -> void:
223+
Indications.remove_hovered(tid, cmd_idx)
224+
225+
if active:
226+
active = false
227+
for field in fields:
228+
if field.has_focus():
229+
active = true
230+
# Should switch out the controls for fake outs. This is safe even when
231+
# you've focused a BetterLineEdit, because it pauses the tree.
232+
if not active:
233+
clear_children()
234+
queue_redraw()
235+
236+
220237
func activate() -> void:
221238
active = true
222239
# Setup the relative button.
@@ -308,20 +325,6 @@ func setup_fields(spacings: Array, names: Array) -> void:
308325
for i in fields.size() - 1:
309326
fields[i + 1].position.x = fields[i].get_end().x + spacings[i]
310327

311-
func _on_mouse_exited() -> void:
312-
Indications.remove_hovered(tid, cmd_idx)
313-
314-
if active:
315-
active = false
316-
for field in fields:
317-
if field.has_focus():
318-
active = true
319-
# Should switch out the controls for fake outs. This is safe even when
320-
# you've focused a BetterLineEdit, because it pauses the tree.
321-
if not active:
322-
clear_children()
323-
queue_redraw()
324-
325328
func clear_children() -> void:
326329
fields = []
327330
relative_button = null

src/ui_elements/path_command_editor.tscn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,3 @@ absolute_button_pressed = SubResource("StyleBoxFlat_sbcff")
111111
relative_button_normal = SubResource("StyleBoxFlat_gs8ph")
112112
relative_button_hovered = SubResource("StyleBoxFlat_tyaol")
113113
relative_button_pressed = SubResource("StyleBoxFlat_cbymw")
114-
115-
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
116-
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]

0 commit comments

Comments
 (0)