Fix text editor cursor motion with tabs

- Moving the cursor to the beginning/end of the line didn't work
  with word-wrap enabled.
- Moving the cursor up/down without word-wrap enabled
  didn't maintain the column.

Resolve using column conversion functions with tab support.
This commit is contained in:
Campbell Barton
2023-09-18 12:11:07 +10:00
parent 66028c8c97
commit b091195a8a
2 changed files with 12 additions and 6 deletions

View File

@@ -776,9 +776,11 @@ void txt_move_up(Text *text, const bool sel)
}
if ((*linep)->prev) {
int column = BLI_str_utf8_offset_to_column((*linep)->line, (*linep)->len, *charp);
int column = BLI_str_utf8_offset_to_column_with_tabs(
(*linep)->line, (*linep)->len, *charp, TXT_TABSIZE);
*linep = (*linep)->prev;
*charp = BLI_str_utf8_offset_from_column((*linep)->line, (*linep)->len, column);
*charp = BLI_str_utf8_offset_from_column_with_tabs(
(*linep)->line, (*linep)->len, column, TXT_TABSIZE);
}
else {
txt_move_bol(text, sel);
@@ -806,9 +808,11 @@ void txt_move_down(Text *text, const bool sel)
}
if ((*linep)->next) {
int column = BLI_str_utf8_offset_to_column((*linep)->line, (*linep)->len, *charp);
int column = BLI_str_utf8_offset_to_column_with_tabs(
(*linep)->line, (*linep)->len, *charp, TXT_TABSIZE);
*linep = (*linep)->next;
*charp = BLI_str_utf8_offset_from_column((*linep)->line, (*linep)->len, column);
*charp = BLI_str_utf8_offset_from_column_with_tabs(
(*linep)->line, (*linep)->len, column, TXT_TABSIZE);
}
else {
txt_move_eol(text, sel);

View File

@@ -1981,7 +1981,8 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
if (j >= oldc) {
if (ch == '\0') {
*charp = BLI_str_utf8_offset_from_column((*linep)->line, (*linep)->len, start);
*charp = BLI_str_utf8_offset_from_column_with_tabs(
(*linep)->line, (*linep)->len, start, TXT_TABSIZE);
}
loop = 0;
break;
@@ -1997,7 +1998,8 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
}
else if (ELEM(ch, ' ', '-', '\0')) {
if (j >= oldc) {
*charp = BLI_str_utf8_offset_from_column((*linep)->line, (*linep)->len, start);
*charp = BLI_str_utf8_offset_from_column_with_tabs(
(*linep)->line, (*linep)->len, start, TXT_TABSIZE);
loop = 0;
break;
}