39
39
#include " editor/plugins/script_editor_plugin.h"
40
40
#include " editor/themes/editor_scale.h"
41
41
#include " editor/themes/editor_theme_manager.h"
42
+ #include " scene/gui/line_edit.h"
42
43
#include " scene/gui/menu_button.h"
43
44
#include " scene/gui/separator.h"
44
45
#include " scene/resources/font.h"
45
46
46
- void GotoLineDialog ::popup_find_line (CodeEdit *p_edit ) {
47
- text_editor = p_edit ;
47
+ void GotoLinePopup ::popup_find_line (CodeTextEditor *p_text_editor ) {
48
+ text_editor = p_text_editor ;
48
49
49
- // Add 1 because text_editor->get_caret_line() starts from 0, but the editor user interface starts from 1.
50
- line->set_text (itos (text_editor->get_caret_line () + 1 ));
51
- line->select_all ();
52
- popup_centered (Size2 (180 , 80 ) * EDSCALE);
53
- line->grab_focus ();
54
- }
50
+ original_state = text_editor->get_navigation_state ();
51
+
52
+ // Add 1 because the TextEdit starts from 0, but the editor user interface starts from 1.
53
+ TextEdit *text_edit = text_editor->get_text_editor ();
54
+ int original_line = text_edit->get_caret_line () + 1 ;
55
+ line_input->set_text (itos (original_line));
56
+ text_editor->set_preview_navigation_change (true );
55
57
56
- int GotoLineDialog::get_line () const {
57
- return line->get_text ().to_int ();
58
+ Rect2i parent_rect = text_editor->get_global_rect ();
59
+ Point2i centered_pos (parent_rect.get_center ().x - get_contents_minimum_size ().x / 2.0 , parent_rect.position .y );
60
+ popup_on_parent (Rect2i (centered_pos, Size2 ()));
61
+ reset_size ();
62
+ line_input->grab_focus ();
58
63
}
59
64
60
- void GotoLineDialog::ok_pressed () {
61
- // Subtract 1 because the editor user interface starts from 1, but text_editor->set_caret_line(n) starts from 0.
62
- const int line_number = get_line () - 1 ;
63
- if (line_number < 0 || line_number >= text_editor->get_line_count ()) {
65
+ void GotoLinePopup::_goto_line () {
66
+ if (line_input->get_text ().is_empty ()) {
64
67
return ;
65
68
}
66
- text_editor->remove_secondary_carets ();
67
- text_editor->unfold_line (line_number);
68
- text_editor->set_caret_line (line_number);
69
- text_editor->set_code_hint (" " );
70
- text_editor->cancel_code_completion ();
69
+
70
+ PackedStringArray line_col_strings = line_input->get_text ().split (" :" );
71
+ // Subtract 1 because the editor user interface starts from 1, but the TextEdit starts from 0.
72
+ const int line_number = line_col_strings[0 ].to_int () - 1 ;
73
+ if (line_number < 0 || line_number >= text_editor->get_text_editor ()->get_line_count ()) {
74
+ return ;
75
+ }
76
+
77
+ int column_number = 0 ;
78
+ if (line_col_strings.size () >= 2 ) {
79
+ column_number = line_col_strings[1 ].to_int () - 1 ;
80
+ }
81
+ text_editor->goto_line_centered (line_number, column_number);
82
+ }
83
+
84
+ void GotoLinePopup::_submit () {
85
+ _goto_line ();
71
86
hide ();
72
87
}
73
88
74
- GotoLineDialog::GotoLineDialog () {
89
+ void GotoLinePopup::_notification (int p_what) {
90
+ switch (p_what) {
91
+ case NOTIFICATION_VISIBILITY_CHANGED: {
92
+ if (!is_visible ()) {
93
+ text_editor->set_preview_navigation_change (false );
94
+ }
95
+ } break ;
96
+ }
97
+ }
98
+
99
+ void GotoLinePopup::_input_from_window (const Ref<InputEvent> &p_event) {
100
+ if (p_event->is_action_pressed (SNAME (" ui_cancel" ), false , true )) {
101
+ // Cancelled, go back to original state.
102
+ text_editor->set_edit_state (original_state);
103
+ }
104
+ PopupPanel::_input_from_window (p_event);
105
+ }
106
+
107
+ GotoLinePopup::GotoLinePopup () {
75
108
set_title (TTR (" Go to Line" ));
76
109
77
110
VBoxContainer *vbc = memnew (VBoxContainer);
@@ -85,14 +118,12 @@ GotoLineDialog::GotoLineDialog() {
85
118
l->set_text (TTR (" Line Number:" ));
86
119
vbc->add_child (l);
87
120
88
- line = memnew (LineEdit);
89
- vbc->add_child (line);
90
- register_text_enter (line);
91
- text_editor = nullptr ;
92
-
93
- line_label = nullptr ;
94
-
95
- set_hide_on_ok (false );
121
+ line_input = memnew (LineEdit);
122
+ line_input->set_custom_minimum_size (Size2 (100 , 0 ) * EDSCALE);
123
+ line_input->set_select_all_on_focus (true );
124
+ line_input->connect (SceneStringName (text_changed), callable_mp (this , &GotoLinePopup::_goto_line).unbind (1 ));
125
+ line_input->connect (SceneStringName (text_submitted), callable_mp (this , &GotoLinePopup::_submit).unbind (1 ));
126
+ vbc->add_child (line_input);
96
127
}
97
128
98
129
void FindReplaceBar::_notification (int p_what) {
@@ -1393,6 +1424,20 @@ void CodeTextEditor::store_previous_state() {
1393
1424
previous_state = get_navigation_state ();
1394
1425
}
1395
1426
1427
+ bool CodeTextEditor::is_previewing_navigation_change () const {
1428
+ return preview_navigation_change;
1429
+ }
1430
+
1431
+ void CodeTextEditor::set_preview_navigation_change (bool p_preview) {
1432
+ if (preview_navigation_change == p_preview) {
1433
+ return ;
1434
+ }
1435
+ preview_navigation_change = p_preview;
1436
+ if (!preview_navigation_change) {
1437
+ emit_signal (" navigation_preview_ended" );
1438
+ }
1439
+ }
1440
+
1396
1441
void CodeTextEditor::set_edit_state (const Variant &p_state) {
1397
1442
Dictionary state = p_state;
1398
1443
@@ -1761,6 +1806,7 @@ void CodeTextEditor::_bind_methods() {
1761
1806
ADD_SIGNAL (MethodInfo (" load_theme_settings" ));
1762
1807
ADD_SIGNAL (MethodInfo (" show_errors_panel" ));
1763
1808
ADD_SIGNAL (MethodInfo (" show_warnings_panel" ));
1809
+ ADD_SIGNAL (MethodInfo (" navigation_preview_ended" ));
1764
1810
ADD_SIGNAL (MethodInfo (" zoomed" , PropertyInfo (Variant::FLOAT, " p_zoom_factor" )));
1765
1811
}
1766
1812
0 commit comments