From 806253660f6de843761ec5a0069d86d3eee8bdfe Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Thu, 3 Sep 2020 18:10:09 +0200 Subject: [PATCH] Fix caret position when using history --- main.tscn | 10 +++++++--- node.tscn | 8 ++++---- repository.gd | 7 ++++++- repository.tscn | 10 +++++++++- terminal.gd | 5 +++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/main.tscn b/main.tscn index cd0e062..0461c56 100644 --- a/main.tscn +++ b/main.tscn @@ -45,6 +45,7 @@ __meta__ = { [node name="Output" type="TextEdit" parent="Terminal/Control"] margin_right = 700.0 margin_bottom = 1038.0 +focus_mode = 0 size_flags_vertical = 3 custom_styles/read_only = SubResource( 1 ) custom_fonts/font = ExtResource( 5 ) @@ -123,9 +124,10 @@ __meta__ = { [node name="Repositories" type="HBoxContainer" parent="."] margin_left = 5.0 -margin_top = 75.0 +margin_top = 5.0 margin_right = 1203.0 margin_bottom = 1079.0 +mouse_filter = 2 custom_constants/separation = 0 __meta__ = { "_edit_use_anchors_": false @@ -137,9 +139,10 @@ anchor_bottom = 0.0 margin_left = 0.0 margin_top = 0.0 margin_right = 599.0 -margin_bottom = 1004.0 +margin_bottom = 1074.0 size_flags_horizontal = 3 size_flags_vertical = 3 +label = "Goal" [node name="ActiveRepository" parent="Repositories" instance=ExtResource( 3 )] anchor_right = 0.0 @@ -147,8 +150,9 @@ anchor_bottom = 0.0 margin_left = 599.0 margin_top = 0.0 margin_right = 1198.0 -margin_bottom = 1004.0 +margin_bottom = 1074.0 size_flags_horizontal = 3 size_flags_vertical = 3 +label = "Yours!" [connection signal="text_entered" from="Terminal/Control/Input" to="Terminal" method="send_command"] [connection signal="pressed" from="CommitMessage/SaveButton" to="." method="save_commit_message"] diff --git a/node.tscn b/node.tscn index b710c6d..37c85b7 100644 --- a/node.tscn +++ b/node.tscn @@ -23,10 +23,10 @@ __meta__ = { [node name="ID" type="Label" parent="."] visible = false -margin_left = -14.6409 -margin_top = -12.4902 -margin_right = 134.359 -margin_bottom = 40.5098 +margin_left = -19.9265 +margin_top = -12.0097 +margin_right = 129.073 +margin_bottom = 40.9903 custom_fonts/font = ExtResource( 2 ) custom_colors/font_color = Color( 1, 1, 1, 1 ) text = "object_id" diff --git a/repository.gd b/repository.gd index 989b541..7d6d9d7 100644 --- a/repository.gd +++ b/repository.gd @@ -1,5 +1,6 @@ extends Container +export var label: String setget set_label export var path: String setget set_path, get_path var objects = {} @@ -28,6 +29,10 @@ func set_path(new_path): func get_path(): return path +func set_label(new_label): + label = new_label + $Label.text = new_label + func update_index(): $Index.text = git("ls-files") @@ -100,7 +105,7 @@ func apply_forces(): var center_of_gravity = rect_size/2 var d = o.position.distance_to(center_of_gravity) var dir = (o.position - center_of_gravity).normalized() - var f = (d+0.00001)*0.01 + var f = (d+0.00001)*Vector2(0.03, 0.01) o.position -= dir*f func git(args, splitlines = false): diff --git a/repository.tscn b/repository.tscn index 2f3d4a8..64f7065 100644 --- a/repository.tscn +++ b/repository.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://repository.gd" type="Script" id=1] +[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] [node name="Repository" type="Container"] anchor_right = 1.0 @@ -9,6 +10,7 @@ margin_left = 2.0 margin_top = 3.0 margin_right = -6.0 margin_bottom = -4.0 +mouse_filter = 2 script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false @@ -47,4 +49,10 @@ text = "Update" __meta__ = { "_edit_use_anchors_": false } + +[node name="Label" type="Label" parent="."] +margin_left = 20.0 +margin_top = 20.0 +custom_fonts/font = ExtResource( 2 ) +text = "Repo name" [connection signal="pressed" from="Button" to="." method="update_everything"] diff --git a/terminal.gd b/terminal.gd index 670f827..9041cde 100644 --- a/terminal.gd +++ b/terminal.gd @@ -14,10 +14,15 @@ func _input(event): history_position -= 1 history_position %= history.size() input.text = history[history_position] + input.caret_position = input.text.length() + # This prevents the Input taking the arrow as a "skip to beginning" command. + get_tree().set_input_as_handled() if event.is_action_pressed("ui_down"): history_position += 1 history_position %= history.size() input.text = history[history_position] + input.caret_position = input.text.length() + get_tree().set_input_as_handled() func send_command(command): history.push_back(command)