From 3c4d9529b92f278958fffbb071f276b7555a9404 Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Tue, 28 Apr 2020 20:41:41 +0100 Subject: [PATCH] editor: Add support for moving to file start/end. Add API to mainview/mainview panel. Also add key combination for ctrl+home and ctrl+end. --- src/bin/editor/edi_editor.c | 8 ++++ src/bin/mainview/edi_mainview.c | 16 +++++++ src/bin/mainview/edi_mainview.h | 14 ++++++ src/bin/mainview/edi_mainview_panel.c | 62 +++++++++++++++++++++++++++ src/bin/mainview/edi_mainview_panel.h | 18 ++++++++ 5 files changed, 118 insertions(+) diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c index 3521a82..cd8b013 100644 --- a/src/bin/editor/edi_editor.c +++ b/src/bin/editor/edi_editor.c @@ -911,6 +911,14 @@ _smart_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, { edi_mainview_goto_popup_show(); } + else if (!strcmp(ev->key, "Home")) + { + edi_mainview_goto_start(); + } + else if (!strcmp(ev->key, "End")) + { + edi_mainview_goto_end(); + } else if (edi_language_provider_has(editor) && !strcmp(ev->key, "space")) { _suggest_list_load(editor); diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c index ec67f09..fd20c35 100644 --- a/src/bin/mainview/edi_mainview.c +++ b/src/bin/mainview/edi_mainview.c @@ -410,6 +410,22 @@ edi_mainview_goto(unsigned int number) edi_mainview_panel_goto(_current_panel, number); } +void +edi_mainview_goto_start(void) +{ + if (edi_mainview_is_empty()) return; + + edi_mainview_panel_goto_start(_current_panel); +} + +void +edi_mainview_goto_end(void) +{ + if (edi_mainview_is_empty()) return; + + edi_mainview_panel_goto_end(_current_panel); +} + void edi_mainview_goto_position(unsigned int row, unsigned int col) { diff --git a/src/bin/mainview/edi_mainview.h b/src/bin/mainview/edi_mainview.h index 5e3e54c..20bdb32 100644 --- a/src/bin/mainview/edi_mainview.h +++ b/src/bin/mainview/edi_mainview.h @@ -221,6 +221,20 @@ void edi_mainview_search(); */ void edi_mainview_goto(unsigned int line); +/** + * Go to the beginning of the file in the current view. + * + * @ingroup Content + */ +void edi_mainview_goto_start(void); + +/** + * Go to the end of the file in the current view. + * + * @ingroup Content + */ +void edi_mainview_goto_end(void); + /** * Go to a requested line, column position in the current view's contents. * diff --git a/src/bin/mainview/edi_mainview_panel.c b/src/bin/mainview/edi_mainview_panel.c index c8b16a9..995b676 100644 --- a/src/bin/mainview/edi_mainview_panel.c +++ b/src/bin/mainview/edi_mainview_panel.c @@ -970,6 +970,68 @@ edi_mainview_panel_goto_position(Edi_Mainview_Panel *panel, unsigned int row, un elm_object_focus_set(editor->entry, EINA_TRUE); } + +void +edi_mainview_panel_goto_end(Edi_Mainview_Panel *panel) +{ + Edi_Editor *editor; + Elm_Code *code; + Elm_Code_Line *line; + const char *ch; + unsigned int row, tabstop, length = 0; + + if (!panel || !panel->current) + return; + + editor = (Edi_Editor *)evas_object_data_get(panel->current->view, "editor"); + if (!editor) + return; + + code = elm_code_widget_code_get(editor->entry); + if (!code) return; + + row = elm_code_file_lines_get(code->file); + if (row <= 0) return; + + line = elm_code_file_line_get(code->file, row); + if (!line) return; + + tabstop = elm_code_widget_tabstop_get(editor->entry); + + for (ch = line->content; *ch; ch++) + { + if (*ch == '\t') + length += tabstop; + else + length++; + } + + elm_code_widget_cursor_position_set(editor->entry, elm_code_file_lines_get(code->file), length); +} + +void +edi_mainview_panel_goto_start(Edi_Mainview_Panel *panel) +{ + Edi_Editor *editor; + Elm_Code *code; + unsigned int row; + + if (!panel || !panel->current) + return; + + editor = (Edi_Editor *)evas_object_data_get(panel->current->view, "editor"); + if (!editor) + return; + + code = elm_code_widget_code_get(editor->entry); + if (!code) return; + + row = elm_code_file_lines_get(code->file); + if (row <= 0) return; + + elm_code_widget_cursor_position_set(editor->entry, 1, 1); +} + static void _edi_mainview_panel_goto_popup_go_cb(void *data, Evas_Object *obj EINA_UNUSED, diff --git a/src/bin/mainview/edi_mainview_panel.h b/src/bin/mainview/edi_mainview_panel.h index 8a6748e..49f774f 100644 --- a/src/bin/mainview/edi_mainview_panel.h +++ b/src/bin/mainview/edi_mainview_panel.h @@ -319,6 +319,24 @@ void edi_mainview_panel_goto_popup_show(); */ unsigned int edi_mainview_panel_item_count(Edi_Mainview_Panel *panel); +/** + * Go to the beginning of the file in the panel's editor view. + * + * @param panel the mainview panel context + * + * @ingroup Content + */ +void edi_mainview_panel_goto_start(Edi_Mainview_Panel *panel); + +/** + * Go to the end of the file in the panel's editor view. + * + * @param panel the mainview panel context + * + * @ingroup Content + */ +void edi_mainview_panel_goto_end(Edi_Mainview_Panel *panel); + /** * @} *