summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2020-04-28 20:41:41 +0100
committerAlastair Poole <netstar@gmail.com>2020-04-28 20:41:41 +0100
commit3c4d9529b92f278958fffbb071f276b7555a9404 (patch)
tree23adb06c8eaef33326f0289b2cfa6423a3e0ae74
parent5a3e9864faa6b91470ea2a24234e065f7e9eed0e (diff)
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.
-rw-r--r--src/bin/editor/edi_editor.c8
-rw-r--r--src/bin/mainview/edi_mainview.c16
-rw-r--r--src/bin/mainview/edi_mainview.h14
-rw-r--r--src/bin/mainview/edi_mainview_panel.c62
-rw-r--r--src/bin/mainview/edi_mainview_panel.h18
5 files changed, 118 insertions, 0 deletions
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
@@ -411,6 +411,22 @@ edi_mainview_goto(unsigned int 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)
{
if (edi_mainview_is_empty()) return;
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
@@ -222,6 +222,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.
*
* @param row the line number (1 based) to scroll to
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
@@ -320,6 +320,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);
+
+/**
* @}
*
*/