Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r--source/blender/blenkernel/intern/text.c74
1 files changed, 18 insertions, 56 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index b2ea5b12603..1a3e42a7da2 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -703,50 +703,6 @@ bool txt_cursor_is_line_end(Text *text)
/* Cursor movement functions */
/*****************************/
-int txt_utf8_offset_to_index(const char *str, int offset)
-{
- int index = 0, pos = 0;
- while (pos != offset) {
- pos += BLI_str_utf8_size(str + pos);
- index++;
- }
- return index;
-}
-
-int txt_utf8_index_to_offset(const char *str, int index)
-{
- int offset = 0, pos = 0;
- while (pos != index) {
- offset += BLI_str_utf8_size(str + offset);
- pos++;
- }
- return offset;
-}
-
-int txt_utf8_offset_to_column(const char *str, int offset)
-{
- int column = 0, pos = 0;
- while (pos < offset) {
- column += BLI_str_utf8_char_width_safe(str + pos);
- pos += BLI_str_utf8_size_safe(str + pos);
- }
- return column;
-}
-
-int txt_utf8_column_to_offset(const char *str, int column)
-{
- int offset = 0, pos = 0, col;
- while (*(str + offset) && pos < column) {
- col = BLI_str_utf8_char_width_safe(str + offset);
- if (pos + col > column) {
- break;
- }
- offset += BLI_str_utf8_size_safe(str + offset);
- pos += col;
- }
- return offset;
-}
-
void txt_move_up(Text *text, const bool sel)
{
TextLine **linep;
@@ -764,9 +720,9 @@ void txt_move_up(Text *text, const bool sel)
}
if ((*linep)->prev) {
- int column = txt_utf8_offset_to_column((*linep)->line, *charp);
+ int column = BLI_str_utf8_offset_to_column((*linep)->line, *charp);
*linep = (*linep)->prev;
- *charp = txt_utf8_column_to_offset((*linep)->line, column);
+ *charp = BLI_str_utf8_offset_from_column((*linep)->line, column);
}
else {
txt_move_bol(text, sel);
@@ -794,9 +750,9 @@ void txt_move_down(Text *text, const bool sel)
}
if ((*linep)->next) {
- int column = txt_utf8_offset_to_column((*linep)->line, *charp);
+ int column = BLI_str_utf8_offset_to_column((*linep)->line, *charp);
*linep = (*linep)->next;
- *charp = txt_utf8_column_to_offset((*linep)->line, column);
+ *charp = BLI_str_utf8_offset_from_column((*linep)->line, column);
}
else {
txt_move_eol(text, sel);
@@ -1977,7 +1933,7 @@ bool txt_replace_char(Text *text, unsigned int add)
*/
static void txt_select_prefix(Text *text, const char *add)
{
- int len, num, curc_old;
+ int len, num, curc_old, selc_old;
char *tmp;
const int indentlen = strlen(add);
@@ -1985,6 +1941,7 @@ static void txt_select_prefix(Text *text, const char *add)
BLI_assert(!ELEM(NULL, text->curl, text->sell));
curc_old = text->curc;
+ selc_old = text->selc;
num = 0;
while (true) {
@@ -2022,19 +1979,24 @@ static void txt_select_prefix(Text *text, const char *add)
num++;
}
}
- if (!curc_old) {
- text->curc = 0;
- }
- else {
- text->curc = curc_old + indentlen;
- }
while (num > 0) {
text->curl = text->curl->prev;
num--;
}
- /* caller must handle undo */
+ /* Keep the cursor left aligned if we don't have a selection. */
+ if (curc_old == 0 && !(text->curl == text->sell && curc_old == selc_old)) {
+ if (text->curl == text->sell) {
+ if (text->curc == text->selc) {
+ text->selc = 0;
+ }
+ }
+ text->curc = 0;
+ }
+ else {
+ text->curc = curc_old + indentlen;
+ }
}
/**