--- lbbs/src/editor.c 2025/11/08 12:32:16 1.56 +++ lbbs/src/editor.c 2025/12/17 03:47:00 1.61 @@ -6,6 +6,10 @@ * Copyright (C) 2004-2025 Leaflet */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "bbs.h" #include "common.h" #include "editor.h" @@ -77,6 +81,7 @@ EDITOR_DATA *editor_data_load(const char long line_offsets[MAX_EDITOR_DATA_LINES + 1]; long current_data_line_length = 0; long i; + int j; if (p_data == NULL) { @@ -123,6 +128,15 @@ EDITOR_DATA *editor_data_load(const char memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]); current_data_line_length += p_editor_data->display_line_lengths[i]; + // Convert \t to single space + for (j = 0; j < p_editor_data->display_line_lengths[i]; j++) + { + if (p_editor_data->p_display_lines[i][j] == '\t') + { + p_editor_data->p_display_lines[i][j] = ' '; + } + } + // Trim \n from last line if (i + 1 == p_editor_data->display_line_total && p_editor_data->display_line_lengths[i] > 0 && @@ -669,6 +683,7 @@ int editor_display(EDITOR_DATA *p_editor int i, j; char *p_str; int del_line; + int tab_width = 0; clrline(output_current_row, SCREEN_ROWS); @@ -707,6 +722,7 @@ int editor_display(EDITOR_DATA *p_editor moveto((int)row_pos, (int)col_pos); iflush(); + tab_width = 0; str_len = 0; ch = igetch_t(BBS_max_user_idle_time); while (!SYS_server_exit) @@ -722,6 +738,12 @@ int editor_display(EDITOR_DATA *p_editor goto cleanup; } + if (ch == '\t') + { + ch = ' '; + tab_width = TAB_SIZE - ((int)(col_pos - 1) % TAB_SIZE) - 1; + } + if (ch < 256 && (ch & 0x80)) // head of multi-byte character { str_len = 0; @@ -840,10 +862,17 @@ int editor_display(EDITOR_DATA *p_editor break; } - ch = igetch(0); - if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input + if (ch == ' ' && tab_width > 0) { - break; + tab_width--; + } + else + { + ch = igetch(0); + if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input + { + break; + } } str_len = 0; @@ -945,7 +974,9 @@ int editor_display(EDITOR_DATA *p_editor switch (ch) { case KEY_NULL: +#ifdef _DEBUG log_error("KEY_NULL\n"); +#endif goto cleanup; case KEY_TIMEOUT: log_error("User input timeout\n");