Repository: godotengine/godot
File: editor/gui/filter_line_edit.cpp (C++)

Code before:
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "filter_line_edit.h"

void FilterLineEdit::gui_input(const Ref<InputEvent> &p_event) {
	Ref<InputEventKey> key = p_event;
	if (key.is_null()) {
		LineEdit::gui_input(p_event);
		return;
	}

	// Redirect navigational key events to the control.
	if (key->is_action(SNAME("ui_up"), true) || key->is_action(SNAME("ui_down"), true) || key->is_action(SNAME("ui_page_up")) || key->is_action(SNAME("ui_page_down"))) {
		forward_control->gui_input(key);
		accept_event();
		return;
	}
	LineEdit::gui_input(p_event);
}

void FilterLineEdit::set_forward_control(Control *p_control) {
	ERR_FAIL_NULL(p_control);
	forward_control = p_control;
}


Review comment (bug):
```suggestion
void FilterLineEdit::gui_input(const Ref<InputEvent> &p_event) {
	ERR_FAIL_NULL(forward_control);
```
We should probably make sure it is set.

Code after:
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "filter_line_edit.h"

void FilterLineEdit::_notification(int p_what) {
	if (p_what == NOTIFICATION_THEME_CHANGED) {
		set_right_icon(get_editor_theme_icon(SNAME("Search")));
	}
}

void FilterLineEdit::gui_input(const Ref<InputEvent> &p_event) {
	ERR_FAIL_NULL(forward_control);

	Ref<InputEventKey> key = p_event;
	if (key.is_null()) {
		LineEdit::gui_input(p_event);
		return;
	}

	// Redirect navigational key events to the control.
	if (key->is_action(SNAME("ui_up"), true) || key->is_action(SNAME("ui_down"), true) || key->is_action(SNAME("ui_page_up")) || key->is_action(SNAME("ui_page_down"))) {
		forward_control->gui_input(key);
		accept_event();
		return;
	}
	LineEdit::gui_input(p_event);
}

void FilterLineEdit::set_forward_control(Control *p_control) {
	ERR_FAIL_NULL(p_control);
	forward_control = p_control;
}

FilterLineEdit::FilterLineEdit() {
	set_clear_button_enabled(true);
}