[editor] Support space insertion instead of tabs
Elm_Code support and option in Edi to use spaces when the Tab key is pressed - make this default too.
This commit is contained in:
parent
0d11f3d7d8
commit
70471e0ad8
|
@ -1006,6 +1006,30 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text
|
|||
eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget)
|
||||
{
|
||||
Elm_Code_Widget_Data *pd;
|
||||
unsigned int col, row;
|
||||
|
||||
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
||||
if (!pd->tab_inserts_spaces)
|
||||
{
|
||||
_elm_code_widget_text_at_cursor_insert(widget, "\t", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
eo_do(widget,
|
||||
elm_obj_code_widget_cursor_position_get(&col, &row));
|
||||
col = (col - 1) % pd->tabstop;
|
||||
|
||||
while (col < pd->tabstop)
|
||||
{
|
||||
_elm_code_widget_text_at_cursor_insert(widget, " ", 1);
|
||||
col++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_widget_newline(Elm_Code_Widget *widget)
|
||||
{
|
||||
|
@ -1215,6 +1239,8 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
|
|||
_elm_code_widget_backspace(widget);
|
||||
else if (!strcmp(ev->key, "Delete"))
|
||||
_elm_code_widget_delete(widget);
|
||||
else if (!strcmp(ev->key, "Tab"))
|
||||
_elm_code_widget_tab_at_cursor_insert(widget);
|
||||
|
||||
else if (ev->string && strlen(ev->string) == 1)
|
||||
_elm_code_widget_text_at_cursor_insert(widget, ev->string, 1);
|
||||
|
@ -1445,6 +1471,19 @@ _elm_code_widget_show_whitespace_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *
|
|||
return pd->show_whitespace;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_code_widget_tab_inserts_spaces_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool spaces)
|
||||
{
|
||||
pd->tab_inserts_spaces = spaces;
|
||||
_elm_code_widget_fill(obj);
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Bool
|
||||
_elm_code_widget_tab_inserts_spaces_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
||||
{
|
||||
return pd->tab_inserts_spaces;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line)
|
||||
{
|
||||
|
|
|
@ -130,6 +130,17 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text)
|
|||
show_whitespace: Eina_Bool; [[Whether or not we show whitespace characters]]
|
||||
}
|
||||
}
|
||||
@property tab_inserts_spaces {
|
||||
set {
|
||||
[[Set whether space characters should be inserted instead of tabs.]]
|
||||
}
|
||||
get {
|
||||
[[Get whether or not space characters will be inserted instead of tabs.]]
|
||||
}
|
||||
values {
|
||||
tab_inserts_spaces: Eina_Bool; [[EINA_TRUE if we should insert space characters instead of a tab when the Tab key is pressed]]
|
||||
}
|
||||
}
|
||||
@property cursor_position {
|
||||
set {
|
||||
[[Set the current location of the text cursor.]]
|
||||
|
|
|
@ -23,7 +23,7 @@ typedef struct
|
|||
Eina_Bool editable, focussed;
|
||||
Eina_Bool show_line_numbers;
|
||||
unsigned int line_width_marker, tabstop;
|
||||
Eina_Bool show_whitespace;
|
||||
Eina_Bool show_whitespace, tab_inserts_spaces;
|
||||
|
||||
Elm_Code_Widget_Selection_Data *selection;
|
||||
Evas_Object *tooltip;
|
||||
|
|
Loading…
Reference in New Issue