diff --git a/DungeonShooting_Godot/editor/prefabs/IdePanel.tscn b/DungeonShooting_Godot/editor/prefabs/IdePanel.tscn index b2150bd..de1493b 100644 --- a/DungeonShooting_Godot/editor/prefabs/IdePanel.tscn +++ b/DungeonShooting_Godot/editor/prefabs/IdePanel.tscn @@ -29,12 +29,14 @@ highlight_current_line = true syntax_highlighting = true show_line_numbers = true +draw_tabs = true bookmark_gutter = true fold_gutter = true -wrap_enabled = true +context_menu_enabled = false minimap_draw = true caret_blink = true caret_blink_speed = 0.4 script = ExtResource( 1 ) [connection signal="resized" from="ScalePanel" to="." method="_on_ScalePanel_resized"] +[connection signal="text_changed" from="ScalePanel/TextEdit" to="ScalePanel/TextEdit" method="_on_TextEdit_text_changed"] diff --git a/DungeonShooting_Godot/editor/src/IdeTextEditor.cs b/DungeonShooting_Godot/editor/src/IdeTextEditor.cs index 16ad0f1..c520328 100644 --- a/DungeonShooting_Godot/editor/src/IdeTextEditor.cs +++ b/DungeonShooting_Godot/editor/src/IdeTextEditor.cs @@ -4,10 +4,12 @@ { public class IdeTextEditor : TextEdit { - private readonly Color KeyCodeColor = new Color(86 / 255f,156 / 255f,214 / 255f); - private readonly Color AnnotationColor = new Color(77 / 255f,144 / 255f,52 / 255f); - private readonly Color StringColor = new Color(214 / 255f,157 / 255f,133 / 255f); - private readonly string[] KeyCodes = { + private readonly Color KeyCodeColor = new Color(86 / 255f, 156 / 255f, 214 / 255f); + private readonly Color AnnotationColor = new Color(77 / 255f, 144 / 255f, 52 / 255f); + private readonly Color StringColor = new Color(214 / 255f, 157 / 255f, 133 / 255f); + + private readonly string[] KeyCodes = + { "var", "namespace", "this", @@ -41,7 +43,10 @@ "continue", "typeof" }; - + + private readonly string[] auto_compelete_right = { "'", "{", "\"", "(", "[" }; + private readonly string[] auto_compelete_left = { "'", "}", "\"", ")", "]" }; + public override void _Ready() { //添加关键字 @@ -49,6 +54,7 @@ { AddKeywordColor(KeyCodes[i], KeyCodeColor); } + AddColorRegion("//", "", AnnotationColor, true); AddColorRegion("/*", "*/", AnnotationColor); AddColorRegion("\"", "\"", StringColor); @@ -76,5 +82,22 @@ "; } + + private void _on_TextEdit_text_changed() + { + GD.Print(GetWordUnderCursor()); + GD.Print(GetPosAtLineColumn(1, 1)); + Select(CursorGetLine(), CursorGetColumn() - 1, CursorGetLine(), CursorGetColumn()); + var key = GetSelectionText(); + Select(CursorGetLine(), CursorGetColumn(), CursorGetLine(), CursorGetColumn()); + for (int i = 0; i < 5; i++) + { + if (key == auto_compelete_right[i]) + { + InsertTextAtCursor(auto_compelete_left[i]); + CursorSetColumn(CursorGetColumn() - 1); + } + } + } } } \ No newline at end of file