poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 5db5e5b19ede56ab60ecc4c7b937b421b4feb2a8
родитељ d329da0530f307e56cda79d46808b65edf380b73
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sun, 28 Nov 2021 20:13:07 +0100

Change word-operations (C-R, C-T, C-W) to be more intuitive

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 2+-
Mpoe.c | 43+++++++++++++++++++++++++++++++------------
Mutil.c | 13+++++++++++++
Mutil.h | 3++-
измењених датотека: 4, додавања: 47(+), брисања: 14(-)

diff --git a/TODO b/TODO @@ -5,7 +5,7 @@ [x] Investigate backspace/insert at the end of a line longer than edit box width - [ ] Change the word-operations (C-W, C-R, C-T) to be more intuitive with + [x] Change the word-operations (C-W, C-R, C-T) to be more intuitive with regards to including spaces [ ] Fix very long comment line cutoff diff --git a/poe.c b/poe.c @@ -50,6 +50,7 @@ void erase_search_backwards(struct DrawState* state); void erase_search_forward(struct DrawState* state); void erase_search_to_start(struct DrawState* state); void erase_search_to_end(struct DrawState* state); +int is_word_boundary(const uint32_t ch); void move_search_prev_word(struct DrawState* state); void move_search_next_word(struct DrawState* state); void erase_search_prev_word(struct DrawState* state); @@ -747,15 +748,24 @@ erase_search_to_end(struct DrawState* state) next_match(state); } +int +is_word_boundary(const uint32_t ch) +{ + return u32_strchr((uint32_t*)L" \t()[]{},.;:/\\", ch) != NULL; +} + void move_search_prev_word(struct DrawState* state) { int i = state->search_column; uint32_t* pline = state->search; - while (i > 0 && (pline[i] == ' ' || pline[i] == '\t')) + if (i > 0 && is_word_boundary(pline[i - 1])) i--; - while (i > 0 && (pline[i] != ' ' && pline[i] != '\t')) + while (i > 0 && is_word_boundary(pline[i])) + i--; + while (i > 0 && !is_word_boundary(pline[i]) + && !is_word_boundary(pline[i - 1])) i--; state->search_column = i; @@ -781,9 +791,9 @@ move_search_next_word(struct DrawState* state) uint32_t* pline = state->search; size_t len = u32_strlen(state->search); - while (i < len && (pline[i] != ' ' && pline[i] != '\t')) + while (i < len && !is_word_boundary(pline[i])) i++; - while (i < len && (pline[i] == ' ' || pline[i] == '\t')) + while (i < len && is_word_boundary(pline[i])) i++; state->search_column = i; state->search_display_column @@ -807,9 +817,12 @@ erase_search_prev_word(struct DrawState* state) uint32_t* pline = state->search; - while (i > 0 && (pline[i] == ' ' || pline[i] == '\t')) + if (i > 0 && is_word_boundary(pline[i - 1])) + i--; + while (i > 0 && is_word_boundary(pline[i])) i--; - while (i > 0 && (pline[i] != ' ' && pline[i] != '\t')) + while (i > 0 && !is_word_boundary(pline[i]) + && !is_word_boundary(pline[i - 1])) i--; int d = state->search_column - i; @@ -1436,9 +1449,12 @@ move_prev_word(struct DrawState* state) int i = state->input_column; uint32_t* pline = state->input_buffer[state->input_row].text; - while (i > 0 && (pline[i] == ' ' || pline[i] == '\t')) + if (i > 0 && is_word_boundary(pline[i - 1])) i--; - while (i > 0 && (pline[i] != ' ' && pline[i] != '\t')) + while (i > 0 && is_word_boundary(pline[i])) + i--; + while (i > 0 && !is_word_boundary(pline[i]) + && !is_word_boundary(pline[i - 1])) i--; state->input_column = i; @@ -1462,9 +1478,9 @@ move_next_word(struct DrawState* state) uint32_t* pline = state->input_buffer[state->input_row].text; size_t len = state->input_buffer[state->input_row].length; - while (i < len && (pline[i] != ' ' && pline[i] != '\t')) + while (i < len && !is_word_boundary(pline[i])) i++; - while (i < len && (pline[i] == ' ' || pline[i] == '\t')) + while (i < len && is_word_boundary(pline[i])) i++; state->input_column = i; state->input_display_column = display_length(state, @@ -1490,9 +1506,12 @@ erase_prev_word(struct DrawState* state) uint32_t* pline = state->input_buffer[state->input_row].text; - while (i > 0 && (pline[i] == ' ' || pline[i] == '\t')) + if (i > 0 && is_word_boundary(pline[i - 1])) + i--; + while (i > 0 && is_word_boundary(pline[i])) i--; - while (i > 0 && (pline[i] != ' ' && pline[i] != '\t')) + while (i > 0 && !is_word_boundary(pline[i]) + && !is_word_boundary(pline[i - 1])) i--; int d = state->input_column - i; diff --git a/util.c b/util.c @@ -140,6 +140,19 @@ u32_strstr(uint32_t* haystack, const uint32_t* needle) return NULL; } +uint32_t* +u32_strchr(uint32_t* haystack, const uint32_t needle) +{ + uint32_t* ph = haystack; + while (*ph) + { + if (*ph == needle) + return ph; + ph++; + } + return NULL; +} + size_t u32_strncpy(uint32_t* to, const uint32_t* from, size_t max) { diff --git a/util.h b/util.h @@ -25,7 +25,7 @@ enum { #define MSGDELTA 1024 #define MAXPATH 1024 /* maximum chars for UTF-8 representations of Unicode chars, per Unicode char */ -#define UTF8REPMAX 6 +#define UTF8REPMAX 6 size_t u8_string_to_unicode(uint32_t* us, const char* s, const size_t max); size_t unicode_string_to_u8(char* s, const uint32_t* us, const size_t max); @@ -33,6 +33,7 @@ size_t u32_encode_tabs(uint32_t* s, size_t max); size_t u32_decode_tabs(uint32_t* s, size_t max); size_t u32_strlen(const uint32_t* s); uint32_t* u32_strstr(uint32_t* haystack, const uint32_t* needle); +uint32_t* u32_strchr(uint32_t* haystack, const uint32_t needle); size_t u32_strncpy(uint32_t* to, const uint32_t* from, size_t max); size_t u32_strncat(uint32_t* to, const uint32_t* from, size_t max); size_t u32_u8_strncpy(uint32_t* to, const char* from, size_t max);