elm_code: Fix tab behaviour following API changes
Moved the tabwidth calculations to widget as that's where they actually make sense
This commit is contained in:
parent
1cc89c78a2
commit
cfa86db750
|
@ -209,12 +209,6 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length
|
|||
|
||||
/* generic text functions */
|
||||
|
||||
EAPI unsigned int
|
||||
elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop)
|
||||
{
|
||||
return tabstop - (position % tabstop);
|
||||
}
|
||||
|
||||
EAPI int
|
||||
elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen)
|
||||
{
|
||||
|
|
|
@ -48,8 +48,6 @@ EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position,
|
|||
*
|
||||
*/
|
||||
|
||||
EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop);
|
||||
|
||||
EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char *search, int offset);
|
||||
|
||||
EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen);
|
||||
|
|
|
@ -350,7 +350,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
|
|||
|
||||
charwidth = 1;
|
||||
if (unichr == '\t')
|
||||
charwidth = elm_code_text_tabwidth_at_position(x - gutter, pd->tabstop);
|
||||
charwidth = elm_code_widget_text_tabwidth_at_column_get(widget, x - gutter + 1);
|
||||
for (i = x + 1; i < x + charwidth; i++)
|
||||
{
|
||||
cells[i].codepoint = 0;
|
||||
|
@ -1081,11 +1081,12 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget)
|
|||
|
||||
line = elm_code_file_line_get(code->file, row);
|
||||
|
||||
position = elm_code_widget_line_text_position_for_column_get(widget, line, col - 1);
|
||||
char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col) - position;
|
||||
start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position);
|
||||
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
||||
start_col = elm_code_widget_line_text_column_width_to_position(widget, line,
|
||||
elm_code_widget_line_text_position_for_column_get(widget, line, col - 1));
|
||||
char_width = position - elm_code_widget_line_text_position_for_column_get(widget, line, start_col);
|
||||
|
||||
elm_code_line_text_remove(line, position, char_width?char_width:1);
|
||||
elm_code_line_text_remove(line, position - char_width, char_width);
|
||||
eo_do(widget,
|
||||
elm_obj_code_widget_cursor_position_set(start_col, row));
|
||||
|
||||
|
|
|
@ -245,6 +245,12 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text)
|
|||
}
|
||||
return: uint;
|
||||
}
|
||||
text_tabwidth_at_column_get {
|
||||
params {
|
||||
column: uint;
|
||||
}
|
||||
return: uint;
|
||||
}
|
||||
}
|
||||
implements {
|
||||
class.constructor;
|
||||
|
|
|
@ -35,7 +35,7 @@ _elm_code_widget_text_left_gutter_width_get(Eo *obj, Elm_Code_Widget_Data *pd)
|
|||
}
|
||||
|
||||
static unsigned int
|
||||
_elm_code_widget_line_text_column_width_to_position(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int position)
|
||||
_elm_code_widget_line_text_column_width_to_position(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line, unsigned int position)
|
||||
{
|
||||
Eina_Unicode unicode;
|
||||
unsigned int count = 1;
|
||||
|
@ -59,7 +59,7 @@ _elm_code_widget_line_text_column_width_to_position(Eo *obj EINA_UNUSED, Elm_Cod
|
|||
break;
|
||||
|
||||
if (unicode == '\t')
|
||||
count += elm_code_text_tabwidth_at_position(count, pd->tabstop);
|
||||
count += elm_code_widget_text_tabwidth_at_column_get(obj, count);
|
||||
else
|
||||
count++;
|
||||
}
|
||||
|
@ -74,10 +74,10 @@ _elm_code_widget_line_text_column_width_get(Eo *obj, Elm_Code_Widget_Data *pd, E
|
|||
}
|
||||
|
||||
static unsigned int
|
||||
_elm_code_widget_line_text_position_for_column_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int column)
|
||||
_elm_code_widget_line_text_position_for_column_get(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line, unsigned int column)
|
||||
{
|
||||
Eina_Unicode unicode;
|
||||
unsigned int count = 1;
|
||||
unsigned int count = 1, position = 0;
|
||||
int index = 0;
|
||||
const char *chars;
|
||||
|
||||
|
@ -89,17 +89,25 @@ _elm_code_widget_line_text_position_for_column_get(Eo *obj EINA_UNUSED, Elm_Code
|
|||
else
|
||||
chars = line->content;
|
||||
|
||||
while ((unsigned int) count < column && index < (int) line->length)
|
||||
while ((unsigned int) count <= column && index <= (int) line->length)
|
||||
{
|
||||
position = (unsigned int) index;
|
||||
unicode = eina_unicode_utf8_next_get(chars, &index);
|
||||
|
||||
if (unicode == 0)
|
||||
return line->length;
|
||||
else if (unicode == '\t')
|
||||
count += elm_code_text_tabwidth_at_position(count, pd->tabstop);
|
||||
count += elm_code_widget_text_tabwidth_at_column_get(obj, count);
|
||||
else
|
||||
count++;
|
||||
}
|
||||
|
||||
return (unsigned int) index;
|
||||
return position;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
_elm_code_widget_text_tabwidth_at_column_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int column)
|
||||
{
|
||||
return pd->tabstop - ((column - 1) % pd->tabstop);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ elm_code_test_line.c \
|
|||
elm_code_test_parse.c \
|
||||
elm_code_test_text.c \
|
||||
widget/elm_code_test_widget.c \
|
||||
widget/elm_code_test_widget_text.c \
|
||||
widget/elm_code_test_widget_selection.c \
|
||||
elm_code_suite.c
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ static const struct {
|
|||
{ "text", elm_code_test_text },
|
||||
{ "basic", elm_code_test_basic },
|
||||
{ "widget", elm_code_test_widget },
|
||||
{ "widget_text", elm_code_test_widget_text },
|
||||
{ "widget_selection", elm_code_test_widget_selection },
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ void elm_code_test_line(TCase *tc);
|
|||
void elm_code_test_parse(TCase *tc);
|
||||
void elm_code_test_text(TCase *tc);
|
||||
void elm_code_test_widget(TCase *tc);
|
||||
void elm_code_test_widget_text(TCase *tc);
|
||||
void elm_code_test_widget_selection(TCase *tc);
|
||||
|
||||
#endif /* _EDLM_CODE_SUITE_H */
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "elm_code_suite.h"
|
||||
|
||||
START_TEST (elm_code_test_widget_text_tab_width)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_Widget *widget;
|
||||
Evas_Object *win;
|
||||
|
||||
elm_init(1, NULL);
|
||||
code = elm_code_create();
|
||||
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
|
||||
widget = elm_code_widget_add(win, code);
|
||||
elm_code_widget_tabstop_set(widget, 8);
|
||||
|
||||
ck_assert_int_eq(8, elm_code_widget_text_tabwidth_at_column_get(widget, 1));
|
||||
ck_assert_int_eq(8, elm_code_widget_text_tabwidth_at_column_get(widget, 9));
|
||||
ck_assert_int_eq(6, elm_code_widget_text_tabwidth_at_column_get(widget, 3));
|
||||
|
||||
elm_code_free(code);
|
||||
elm_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (elm_code_test_widget_text_position)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_File *file;
|
||||
Elm_Code_Line *line;
|
||||
Elm_Code_Widget *widget;
|
||||
Evas_Object *win;
|
||||
|
||||
elm_init(1, NULL);
|
||||
code = elm_code_create();
|
||||
file = elm_code_file_new(code);
|
||||
elm_code_file_line_append(file, "a\tb", 4, NULL);
|
||||
line = elm_code_file_line_get(file, 1);
|
||||
|
||||
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
|
||||
widget = elm_code_widget_add(win, code);
|
||||
elm_code_widget_tabstop_set(widget, 8);
|
||||
|
||||
ck_assert_int_eq(0, elm_code_widget_line_text_position_for_column_get(widget, line, 1));
|
||||
ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 2));
|
||||
|
||||
ck_assert_int_eq(2, elm_code_widget_line_text_position_for_column_get(widget, line, 9));
|
||||
ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 7));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void elm_code_test_widget_text(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, elm_code_test_widget_text_tab_width);
|
||||
tcase_add_test(tc, elm_code_test_widget_text_position);
|
||||
}
|
||||
|
Loading…
Reference in New Issue