mirror of https://github.com/godotengine/godot
Merge pull request #52848 from Paulb23/code-edit-tests
This commit is contained in:
commit
1e93e3fc49
|
|
@ -455,10 +455,10 @@ void Main::test_cleanup() {
|
||||||
ResourceLoader::remove_custom_loaders();
|
ResourceLoader::remove_custom_loaders();
|
||||||
ResourceSaver::remove_custom_savers();
|
ResourceSaver::remove_custom_savers();
|
||||||
|
|
||||||
|
unregister_driver_types();
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
EditorNode::unregister_editor_types();
|
EditorNode::unregister_editor_types();
|
||||||
#endif
|
#endif
|
||||||
unregister_driver_types();
|
|
||||||
unregister_module_types();
|
unregister_module_types();
|
||||||
unregister_platform_apis();
|
unregister_platform_apis();
|
||||||
unregister_scene_types();
|
unregister_scene_types();
|
||||||
|
|
|
||||||
|
|
@ -467,7 +467,7 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MISC */
|
/* MISC */
|
||||||
if (k->is_action("ui_cancel", true)) {
|
if (!code_hint.is_empty() && k->is_action("ui_cancel", true)) {
|
||||||
set_code_hint("");
|
set_code_hint("");
|
||||||
accept_event();
|
accept_event();
|
||||||
return;
|
return;
|
||||||
|
|
@ -1725,14 +1725,17 @@ bool CodeEdit::is_code_completion_enabled() const {
|
||||||
void CodeEdit::set_code_completion_prefixes(const TypedArray<String> &p_prefixes) {
|
void CodeEdit::set_code_completion_prefixes(const TypedArray<String> &p_prefixes) {
|
||||||
code_completion_prefixes.clear();
|
code_completion_prefixes.clear();
|
||||||
for (int i = 0; i < p_prefixes.size(); i++) {
|
for (int i = 0; i < p_prefixes.size(); i++) {
|
||||||
code_completion_prefixes.insert(p_prefixes[i]);
|
const String prefix = p_prefixes[i];
|
||||||
|
|
||||||
|
ERR_CONTINUE_MSG(prefix.is_empty(), "Code completion prefix cannot be empty.");
|
||||||
|
code_completion_prefixes.insert(prefix[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedArray<String> CodeEdit::get_code_completion_prefixes() const {
|
TypedArray<String> CodeEdit::get_code_completion_prefixes() const {
|
||||||
TypedArray<String> prefixes;
|
TypedArray<String> prefixes;
|
||||||
for (Set<String>::Element *E = code_completion_prefixes.front(); E; E = E->next()) {
|
for (const Set<char32_t>::Element *E = code_completion_prefixes.front(); E; E = E->next()) {
|
||||||
prefixes.push_back(E->get());
|
prefixes.push_back(String::chr(E->get()));
|
||||||
}
|
}
|
||||||
return prefixes;
|
return prefixes;
|
||||||
}
|
}
|
||||||
|
|
@ -1795,9 +1798,9 @@ void CodeEdit::request_code_completion(bool p_force) {
|
||||||
String line = get_line(get_caret_line());
|
String line = get_line(get_caret_line());
|
||||||
int ofs = CLAMP(get_caret_column(), 0, line.length());
|
int ofs = CLAMP(get_caret_column(), 0, line.length());
|
||||||
|
|
||||||
if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) {
|
if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(line[ofs - 1]))) {
|
||||||
emit_signal(SNAME("request_code_completion"));
|
emit_signal(SNAME("request_code_completion"));
|
||||||
} else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(String::chr(line[ofs - 2]))) {
|
} else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(line[ofs - 2])) {
|
||||||
emit_signal(SNAME("request_code_completion"));
|
emit_signal(SNAME("request_code_completion"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1969,7 +1972,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
|
||||||
end_complex_operation();
|
end_complex_operation();
|
||||||
|
|
||||||
cancel_code_completion();
|
cancel_code_completion();
|
||||||
if (code_completion_prefixes.has(String::chr(last_completion_char))) {
|
if (code_completion_prefixes.has(last_completion_char)) {
|
||||||
request_code_completion();
|
request_code_completion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2764,7 +2767,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
|
||||||
bool prev_is_word = false;
|
bool prev_is_word = false;
|
||||||
|
|
||||||
/* Cancel if we are at the close of a string. */
|
/* Cancel if we are at the close of a string. */
|
||||||
if (in_string == -1 && first_quote_col == cofs - 1) {
|
if (caret_column > 0 && in_string == -1 && first_quote_col == cofs - 1) {
|
||||||
cancel_code_completion();
|
cancel_code_completion();
|
||||||
return;
|
return;
|
||||||
/* In a string, therefore we are trying to complete the string text. */
|
/* In a string, therefore we are trying to complete the string text. */
|
||||||
|
|
@ -2790,9 +2793,9 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
|
||||||
/* If all else fails, check for a prefix. */
|
/* If all else fails, check for a prefix. */
|
||||||
/* Single space between caret and prefix is okay. */
|
/* Single space between caret and prefix is okay. */
|
||||||
bool prev_is_prefix = false;
|
bool prev_is_prefix = false;
|
||||||
if (cofs > 0 && code_completion_prefixes.has(String::chr(line[cofs - 1]))) {
|
if (cofs > 0 && code_completion_prefixes.has(line[cofs - 1])) {
|
||||||
prev_is_prefix = true;
|
prev_is_prefix = true;
|
||||||
} else if (cofs > 1 && line[cofs - 1] == ' ' && code_completion_prefixes.has(String::chr(line[cofs - 2]))) {
|
} else if (cofs > 1 && line[cofs - 1] == ' ' && code_completion_prefixes.has(line[cofs - 2])) {
|
||||||
prev_is_prefix = true;
|
prev_is_prefix = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ private:
|
||||||
int code_completion_longest_line = 0;
|
int code_completion_longest_line = 0;
|
||||||
Rect2i code_completion_rect;
|
Rect2i code_completion_rect;
|
||||||
|
|
||||||
Set<String> code_completion_prefixes;
|
Set<char32_t> code_completion_prefixes;
|
||||||
List<ScriptCodeCompletionOption> code_completion_option_submitted;
|
List<ScriptCodeCompletionOption> code_completion_option_submitted;
|
||||||
List<ScriptCodeCompletionOption> code_completion_option_sources;
|
List<ScriptCodeCompletionOption> code_completion_option_sources;
|
||||||
String code_completion_base;
|
String code_completion_base;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -131,8 +131,12 @@ int register_test_command(String p_command, TestFunc p_function);
|
||||||
register_test_command(m_command, m_function); \
|
register_test_command(m_command, m_function); \
|
||||||
DOCTEST_GLOBAL_NO_WARNINGS_END()
|
DOCTEST_GLOBAL_NO_WARNINGS_END()
|
||||||
|
|
||||||
// Utility macro to send an action event to a given object
|
// Utility macros to send an event actions to a given object
|
||||||
// Requires Message Queue and InputMap to be setup.
|
// Requires Message Queue and InputMap to be setup.
|
||||||
|
// SEND_GUI_ACTION - takes an object and a input map key. e.g SEND_GUI_ACTION(code_edit, "ui_text_newline").
|
||||||
|
// SEND_GUI_KEY_EVENT - takes an object and a keycode set. e.g SEND_GUI_KEY_EVENT(code_edit, KEY_A | KEY_MASK_CMD).
|
||||||
|
// SEND_GUI_MOUSE_EVENT - takes an object, position, mouse button and mouse mask e.g SEND_GUI_MOUSE_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE);
|
||||||
|
// SEND_GUI_DOUBLE_CLICK - takes an object and a postion. e.g SEND_GUI_DOUBLE_CLICK(code_edit, Vector2(50, 50));
|
||||||
|
|
||||||
#define SEND_GUI_ACTION(m_object, m_action) \
|
#define SEND_GUI_ACTION(m_object, m_action) \
|
||||||
{ \
|
{ \
|
||||||
|
|
@ -144,6 +148,37 @@ int register_test_command(String p_command, TestFunc p_function);
|
||||||
MessageQueue::get_singleton()->flush(); \
|
MessageQueue::get_singleton()->flush(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SEND_GUI_KEY_EVENT(m_object, m_input) \
|
||||||
|
{ \
|
||||||
|
Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
|
||||||
|
event->set_pressed(true); \
|
||||||
|
m_object->gui_input(event); \
|
||||||
|
MessageQueue::get_singleton()->flush(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask) \
|
||||||
|
Ref<InputEventMouseButton> event; \
|
||||||
|
event.instantiate(); \
|
||||||
|
event->set_position(m_local_pos); \
|
||||||
|
event->set_button_index(m_input); \
|
||||||
|
event->set_button_mask(m_mask); \
|
||||||
|
event->set_pressed(true);
|
||||||
|
|
||||||
|
#define SEND_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask) \
|
||||||
|
{ \
|
||||||
|
_CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask); \
|
||||||
|
m_object->get_viewport()->push_input(event); \
|
||||||
|
MessageQueue::get_singleton()->flush(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SEND_GUI_DOUBLE_CLICK(m_object, m_local_pos) \
|
||||||
|
{ \
|
||||||
|
_CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, MOUSE_BUTTON_LEFT, MOUSE_BUTTON_LEFT); \
|
||||||
|
event->set_double_click(true); \
|
||||||
|
m_object->get_viewport()->push_input(event); \
|
||||||
|
MessageQueue::get_singleton()->flush(); \
|
||||||
|
}
|
||||||
|
|
||||||
// Utility class / macros for testing signals
|
// Utility class / macros for testing signals
|
||||||
//
|
//
|
||||||
// Use SIGNAL_WATCH(*object, "signal_name") to start watching
|
// Use SIGNAL_WATCH(*object, "signal_name") to start watching
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue