sled

Једноставни уређивач текста
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување c50e8b615937c9a36fec499a87daef6f11958e7e
родитељ 575dfc36cc4999a241851b706ac6bca2d30becdf
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Mon, 14 Mar 2022 21:01:48 +0100

Merge branch 'word-wrap'

Diffstat:
MTODO | 2+-
Mconfig.def.h | 3+++
Mconfig.h | 3+++
Msled.c | 34++++++++++++++++++++++++++++++++++
измењених датотека: 4, додавања: 41(+), брисања: 1(-)

diff --git a/TODO b/TODO @@ -1,7 +1,7 @@ TODO ==== - [ ] Word wrap (patch) + [x] Word wrap [ ] Replace (patch) diff --git a/config.def.h b/config.def.h @@ -2,6 +2,9 @@ /* Comment out to not create backups */ #define CREATE_BACKUPS +/* Comment out to not wrap lines */ +#define ENABLE_WRAP +#define WRAP_WIDTH 80 #ifdef SLED_C_GLOBALS static const char* backup_suffix = "~"; diff --git a/config.h b/config.h @@ -2,6 +2,9 @@ /* Comment out to not create backups */ #define CREATE_BACKUPS +/* Comment out to not wrap lines */ +#define ENABLE_WRAP +#define WRAP_WIDTH 80 #ifdef SLED_C_GLOBALS static const char* backup_suffix = "~"; diff --git a/sled.c b/sled.c @@ -412,6 +412,40 @@ insert_char(struct DrawState* state, uint32_t ch) position_to(state, state->row, state->column + 1); if (add_null) buffer_line->text[state->column] = 0; + +#ifdef ENABLE_WRAP +check_wrap: + if (state->display_column >= WRAP_WIDTH) + { + int saved_column = state->column; + state->column = WRAP_WIDTH - 1; + while (state->column > 0 + && u32_is_word_boundary(buffer_line->text[state->column + - 1], + 0)) + state->column--; + if (state->column == 0) + { + state->column = saved_column; + goto skip_insert_line; + } + while (state->column > 0 + && !u32_is_word_boundary(buffer_line->text[state->column + - 1], + 0)) + state->column--; + if (state->column == 0) + { + state->column = saved_column; + goto skip_insert_line; + } + insert_line(state); + move_end(state); + goto check_wrap; + skip_insert_line:; + } +#endif /* ENABLE_WRAP */ + state->dirty = 1; return 0;