| 54 |
p_editor_data->display_line_lengths[i] = line_offsets[i + 1] - line_offsets[i]; |
p_editor_data->display_line_lengths[i] = line_offsets[i + 1] - line_offsets[i]; |
| 55 |
|
|
| 56 |
if (i == 0 || |
if (i == 0 || |
| 57 |
(current_data_line_length + p_editor_data->display_line_lengths[i] + 1) >= MAX_EDITOR_DATA_LINE_LENGTH || |
current_data_line_length + p_editor_data->display_line_lengths[i] + 1 > MAX_EDITOR_DATA_LINE_LENGTH || |
| 58 |
(p_editor_data->display_line_lengths[i - 1] > 0 && p_data[line_offsets[i - 1] + p_editor_data->display_line_lengths[i - 1] - 1] == '\n')) |
(p_editor_data->display_line_lengths[i - 1] > 0 && p_data[line_offsets[i - 1] + p_editor_data->display_line_lengths[i - 1] - 1] == '\n')) |
| 59 |
{ |
{ |
| 60 |
|
if (p_editor_data->data_line_total >= MAX_EDITOR_DATA_LINES) |
| 61 |
|
{ |
| 62 |
|
log_error("Append line error, data_line_total(%ld) reach limit(%d)\n", p_editor_data->data_line_total, MAX_EDITOR_DATA_LINES); |
| 63 |
|
return NULL; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
// Allocate new data line |
// Allocate new data line |
| 67 |
p_editor_data->p_data_lines[p_editor_data->data_line_total] = malloc(MAX_EDITOR_DATA_LINE_LENGTH); |
p_editor_data->p_data_lines[p_editor_data->data_line_total] = malloc(MAX_EDITOR_DATA_LINE_LENGTH); |
| 68 |
if (p_editor_data->p_data_lines[p_editor_data->data_line_total] == NULL) |
if (p_editor_data->p_data_lines[p_editor_data->data_line_total] == NULL) |
| 79 |
|
|
| 80 |
p_editor_data->p_display_lines[i] = p_editor_data->p_data_lines[p_editor_data->data_line_total]; |
p_editor_data->p_display_lines[i] = p_editor_data->p_data_lines[p_editor_data->data_line_total]; |
| 81 |
(p_editor_data->data_line_total)++; |
(p_editor_data->data_line_total)++; |
| 82 |
|
current_data_line_length = 0; |
| 83 |
} |
} |
| 84 |
else |
else |
| 85 |
{ |
{ |
| 86 |
p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1] + p_editor_data->display_line_lengths[i - 1]; |
p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1] + p_editor_data->display_line_lengths[i - 1]; |
|
current_data_line_length = 0; |
|
| 87 |
} |
} |
| 88 |
|
|
| 89 |
memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]); |
memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]); |
|
p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i]] = '\0'; |
|
|
|
|
| 90 |
current_data_line_length += p_editor_data->display_line_lengths[i]; |
current_data_line_length += p_editor_data->display_line_lengths[i]; |
| 91 |
|
p_editor_data->p_data_lines[p_editor_data->data_line_total - 1][current_data_line_length] = '\0'; |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
return p_editor_data; |
return p_editor_data; |
| 135 |
for (i = p_editor_data->data_line_total - 1; i >= 0; i--) |
for (i = p_editor_data->data_line_total - 1; i >= 0; i--) |
| 136 |
{ |
{ |
| 137 |
free(p_editor_data->p_data_lines[i]); |
free(p_editor_data->p_data_lines[i]); |
| 138 |
|
p_editor_data->p_data_lines[i] = NULL; |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
free(p_editor_data); |
free(p_editor_data); |
| 142 |
} |
} |
| 143 |
|
|
| 144 |
static int editor_display_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
int editor_data_insert(EDITOR_DATA *p_editor_data, long display_line, long offset, |
| 145 |
|
const char *str, int str_len, long *p_last_updated_line) |
| 146 |
|
{ |
| 147 |
|
int len; |
| 148 |
|
int display_len; |
| 149 |
|
int eol; |
| 150 |
|
char *p_data_line; |
| 151 |
|
long len_data_line; |
| 152 |
|
long offset_data_line; |
| 153 |
|
long last_display_line; // of data line |
| 154 |
|
char buf_insert[MAX_EDITOR_DATA_LINE_LENGTH]; |
| 155 |
|
long len_insert; |
| 156 |
|
int display_len_insert; |
| 157 |
|
char buf_catenate[MAX_EDITOR_DATA_LINE_LENGTH]; |
| 158 |
|
long len_catenate; |
| 159 |
|
long i; |
| 160 |
|
|
| 161 |
|
if (p_editor_data == NULL || p_last_updated_line == NULL) |
| 162 |
|
{ |
| 163 |
|
log_error("editor_data_op() error: NULL pointer\n"); |
| 164 |
|
return -1; |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
memcpy(buf_insert, str, (size_t)str_len); |
| 168 |
|
buf_insert[str_len] = '\0'; |
| 169 |
|
len_insert = str_len; |
| 170 |
|
|
| 171 |
|
// Get accurate offset of first character of CJK at offset position |
| 172 |
|
for (i = 0; i < offset; i++) |
| 173 |
|
{ |
| 174 |
|
if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK |
| 175 |
|
{ |
| 176 |
|
i++; |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
|
if (i > offset) // offset was skipped |
| 180 |
|
{ |
| 181 |
|
offset--; |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
// Get length of current data line |
| 185 |
|
len_data_line = 0; |
| 186 |
|
p_data_line = p_editor_data->p_display_lines[display_line]; |
| 187 |
|
for (i = display_line - 1; i >= 0; i--) |
| 188 |
|
{ |
| 189 |
|
if (p_editor_data->display_line_lengths[i] > 0 && |
| 190 |
|
p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of prior data line |
| 191 |
|
{ |
| 192 |
|
break; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
len_data_line += p_editor_data->display_line_lengths[i]; |
| 196 |
|
p_data_line = p_editor_data->p_display_lines[i]; |
| 197 |
|
} |
| 198 |
|
offset_data_line = len_data_line + offset; |
| 199 |
|
last_display_line = p_editor_data->display_line_total - 1; |
| 200 |
|
for (i = display_line; i < p_editor_data->display_line_total; i++) |
| 201 |
|
{ |
| 202 |
|
len_data_line += p_editor_data->display_line_lengths[i]; |
| 203 |
|
|
| 204 |
|
if (p_editor_data->display_line_lengths[i] > 0 && |
| 205 |
|
p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line |
| 206 |
|
{ |
| 207 |
|
last_display_line = i; |
| 208 |
|
break; |
| 209 |
|
} |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
// Split current data line if over-length |
| 213 |
|
if (len_data_line + str_len + 1 > MAX_EDITOR_DATA_LINE_LENGTH) |
| 214 |
|
{ |
| 215 |
|
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES || p_editor_data->data_line_total >= MAX_EDITOR_DATA_LINES) |
| 216 |
|
{ |
| 217 |
|
log_error("Split line error, display_line_total(%ld) or data_line_total(%ld) reach limit(%d)\n", |
| 218 |
|
p_editor_data->display_line_total, p_editor_data->data_line_total, MAX_EDITOR_DATA_LINES); |
| 219 |
|
return -2; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
// Allocate new data line |
| 223 |
|
p_editor_data->p_data_lines[p_editor_data->data_line_total] = malloc(MAX_EDITOR_DATA_LINE_LENGTH); |
| 224 |
|
if (p_editor_data->p_data_lines[p_editor_data->data_line_total] == NULL) |
| 225 |
|
{ |
| 226 |
|
log_error("malloc(MAX_EDITOR_DATA_LINE_LENGTH) error: OOM\n"); |
| 227 |
|
return -2; |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
// Copy rest part of current data line since next display line to new data line |
| 231 |
|
memcpy(p_editor_data->p_data_lines[p_editor_data->data_line_total], |
| 232 |
|
p_editor_data->p_display_lines[display_line + 1], |
| 233 |
|
(size_t)(len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line))); |
| 234 |
|
p_editor_data->p_data_lines[p_editor_data->data_line_total] |
| 235 |
|
[len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)] = '\0'; |
| 236 |
|
|
| 237 |
|
p_data_line = p_editor_data->p_display_lines[display_line + 1]; |
| 238 |
|
for (i = display_line + 1; i <= last_display_line; i++) |
| 239 |
|
{ |
| 240 |
|
p_editor_data->p_display_lines[i] += |
| 241 |
|
(p_editor_data->p_data_lines[p_editor_data->data_line_total] - p_data_line); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
// Copy rest part of current display line to buffer |
| 245 |
|
if (offset_data_line >= MAX_EDITOR_DATA_LINE_LENGTH / 2) |
| 246 |
|
{ |
| 247 |
|
memcpy(buf_insert + len_insert, |
| 248 |
|
p_editor_data->p_display_lines[display_line] + offset, |
| 249 |
|
(size_t)(p_editor_data->display_line_lengths[display_line] - offset)); |
| 250 |
|
len_insert += (p_editor_data->display_line_lengths[display_line] - offset); |
| 251 |
|
} |
| 252 |
|
else |
| 253 |
|
{ |
| 254 |
|
memcpy(buf_insert, |
| 255 |
|
p_editor_data->p_display_lines[display_line] + offset, |
| 256 |
|
(size_t)(p_editor_data->display_line_lengths[display_line] - offset)); |
| 257 |
|
len_insert = (p_editor_data->display_line_lengths[display_line] - offset); |
| 258 |
|
} |
| 259 |
|
buf_insert[len_insert] = '\0'; |
| 260 |
|
|
| 261 |
|
if (offset_data_line >= MAX_EDITOR_DATA_LINE_LENGTH / 2) |
| 262 |
|
{ |
| 263 |
|
// Add line ending to current display line (data line) |
| 264 |
|
p_editor_data->p_display_lines[display_line][offset] = '\n'; |
| 265 |
|
p_editor_data->p_display_lines[display_line][offset + 1] = '\0'; |
| 266 |
|
p_editor_data->display_line_lengths[display_line] = offset + 1; |
| 267 |
|
} |
| 268 |
|
else |
| 269 |
|
{ |
| 270 |
|
memcpy(p_editor_data->p_display_lines[display_line] + offset, str, (size_t)str_len); |
| 271 |
|
|
| 272 |
|
// Add line ending to current display line (data line) |
| 273 |
|
p_editor_data->p_display_lines[display_line][offset + str_len] = '\n'; |
| 274 |
|
p_editor_data->p_display_lines[display_line][offset + str_len + 1] = '\0'; |
| 275 |
|
p_editor_data->display_line_lengths[display_line] = offset + str_len + 1; |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
display_line++; |
| 279 |
|
offset = 0; |
| 280 |
|
|
| 281 |
|
*p_last_updated_line = p_editor_data->display_line_total; |
| 282 |
|
|
| 283 |
|
last_display_line++; |
| 284 |
|
(p_editor_data->display_line_total)++; |
| 285 |
|
(p_editor_data->data_line_total)++; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
for (i = display_line; len_insert > 0 && i <= last_display_line; i++) |
| 289 |
|
{ |
| 290 |
|
len = split_line(buf_insert, SCREEN_COLS, &eol, &display_len_insert); |
| 291 |
|
if (len != len_insert) |
| 292 |
|
{ |
| 293 |
|
log_error("buf_insert is truncated at display_line(%ld): len(%d) != len_insert(%d), buf_insert: %s\n", |
| 294 |
|
i, len, len_insert, buf_insert); |
| 295 |
|
return -3; |
| 296 |
|
} |
| 297 |
|
|
| 298 |
|
memcpy(buf_catenate, p_editor_data->p_display_lines[i], (size_t)p_editor_data->display_line_lengths[i]); |
| 299 |
|
buf_catenate[p_editor_data->display_line_lengths[i]] = '\0'; |
| 300 |
|
|
| 301 |
|
len = split_line(buf_catenate, SCREEN_COLS - display_len_insert, &eol, &display_len); |
| 302 |
|
if (len < offset) // have no space to insert |
| 303 |
|
{ |
| 304 |
|
offset = 0; |
| 305 |
|
continue; // retry at next display line |
| 306 |
|
} |
| 307 |
|
|
| 308 |
|
// move \n to next display line if current line is full |
| 309 |
|
if (len > 0 && buf_catenate[len - 1] == '\n' && display_len + display_len_insert >= SCREEN_COLS) |
| 310 |
|
{ |
| 311 |
|
len--; |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
memcpy(buf_catenate, p_editor_data->p_display_lines[i], (size_t)offset); |
| 315 |
|
memcpy(buf_catenate + offset, buf_insert, (size_t)len_insert); |
| 316 |
|
memcpy(buf_catenate + offset + len_insert, p_editor_data->p_display_lines[i] + offset, (size_t)(len - offset)); |
| 317 |
|
len_catenate = len_insert + len; |
| 318 |
|
buf_catenate[len_catenate] = '\0'; |
| 319 |
|
|
| 320 |
|
offset = 0; |
| 321 |
|
len_insert = p_editor_data->display_line_lengths[i] - len; |
| 322 |
|
if (len_insert > 0) |
| 323 |
|
{ |
| 324 |
|
memcpy(buf_insert, p_editor_data->p_display_lines[i] + len, (size_t)len_insert); |
| 325 |
|
buf_insert[len_insert] = '\0'; |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
memcpy(p_editor_data->p_display_lines[i], buf_catenate, (size_t)len_catenate); |
| 329 |
|
p_editor_data->display_line_lengths[i] = len_catenate; |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
*p_last_updated_line = MAX(i, *p_last_updated_line); |
| 333 |
|
|
| 334 |
|
if (len_insert > 0) |
| 335 |
|
{ |
| 336 |
|
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) |
| 337 |
|
{ |
| 338 |
|
log_error("Append line error, display_line_total(%ld) reach limit(%d)\n", |
| 339 |
|
p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); |
| 340 |
|
return -2; |
| 341 |
|
} |
| 342 |
|
|
| 343 |
|
// Prepare one blank display line after last_display_line |
| 344 |
|
for (i = p_editor_data->display_line_total; i > last_display_line + 1; i--) |
| 345 |
|
{ |
| 346 |
|
p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1]; |
| 347 |
|
p_editor_data->display_line_lengths[i] = p_editor_data->display_line_lengths[i - 1]; |
| 348 |
|
} |
| 349 |
|
p_editor_data->p_display_lines[last_display_line + 1] = |
| 350 |
|
p_editor_data->p_display_lines[last_display_line] + p_editor_data->display_line_lengths[last_display_line]; |
| 351 |
|
p_editor_data->display_line_lengths[last_display_line + 1] = 0; |
| 352 |
|
|
| 353 |
|
(p_editor_data->display_line_total)++; |
| 354 |
|
last_display_line++; |
| 355 |
|
|
| 356 |
|
// Fill data into blank display line |
| 357 |
|
memcpy(p_editor_data->p_display_lines[last_display_line], buf_insert, (size_t)len_insert); |
| 358 |
|
p_editor_data->p_display_lines[last_display_line][len_insert] = '\0'; |
| 359 |
|
p_editor_data->display_line_lengths[last_display_line] = len_insert; |
| 360 |
|
|
| 361 |
|
*p_last_updated_line = MAX(last_display_line, *p_last_updated_line); |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
return 0; |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset, |
| 368 |
|
long *p_last_updated_line) |
| 369 |
|
{ |
| 370 |
|
return 0; |
| 371 |
|
} |
| 372 |
|
|
| 373 |
|
static int editor_display_key_handler(int *p_key, EDITOR_CTX *p_ctx) |
| 374 |
{ |
{ |
| 375 |
switch (*p_key) |
switch (*p_key) |
| 376 |
{ |
{ |
| 377 |
case 0: // Set msg |
case 0: // Set msg |
| 378 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 379 |
"| ·µ»Ø[\033[32m¡û\033[33m,\033[32mESC\033[33m] | " |
"| Í˳ö[\033[32mCtrl-C\033[33m] | °ïÖú[\033[32mh\033[33m] |"); |
|
"ÒÆ¶¯[\033[32m¡ü\033[33m/\033[32m¡ý\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | " |
|
|
"°ïÖú[\033[32mh\033[33m] |"); |
|
| 380 |
break; |
break; |
| 381 |
} |
} |
| 382 |
|
|
| 387 |
{ |
{ |
| 388 |
static int show_help = 1; |
static int show_help = 1; |
| 389 |
char buffer[MAX_EDITOR_DATA_LINE_LENGTH]; |
char buffer[MAX_EDITOR_DATA_LINE_LENGTH]; |
| 390 |
DISPLAY_CTX ctx; |
EDITOR_CTX ctx; |
| 391 |
int ch = 0; |
int ch = 0; |
| 392 |
|
char hz_ch[4]; |
| 393 |
|
int hz_len; |
| 394 |
int input_ok, screen_current_line; |
int input_ok, screen_current_line; |
| 395 |
const int screen_begin_line = 1; |
const int screen_begin_line = 1; |
| 396 |
int screen_end_line = SCREEN_ROWS - 1; |
int screen_end_line = SCREEN_ROWS - 1; |
| 397 |
const int screen_line_total = screen_end_line - screen_begin_line + 1; |
const int screen_line_total = screen_end_line - screen_begin_line + 1; |
| 398 |
long int line_current = 0; |
long int line_current = 0; |
| 399 |
long int len; |
long int len; |
|
long int percentile; |
|
| 400 |
int loop; |
int loop; |
| 401 |
int eol, display_len; |
int eol, display_len; |
| 402 |
long row_pos = 1, col_pos = 1; |
long row_pos = 1, col_pos = 1; |
| 403 |
|
long last_updated_line = 0; |
| 404 |
|
int insert = 1; |
| 405 |
|
|
| 406 |
screen_current_line = screen_begin_line; |
screen_current_line = screen_begin_line; |
| 407 |
clrline(screen_begin_line, SCREEN_ROWS); |
clrline(screen_begin_line, SCREEN_ROWS); |
| 417 |
{ |
{ |
| 418 |
if (line_current >= p_editor_data->display_line_total || screen_current_line > screen_end_line) |
if (line_current >= p_editor_data->display_line_total || screen_current_line > screen_end_line) |
| 419 |
{ |
{ |
| 420 |
ctx.reach_begin = (line_current < screen_current_line ? 1 : 0); |
ctx.line_cursor = line_current - screen_current_line + row_pos + 1; |
|
|
|
|
if (line_current - (screen_current_line - screen_begin_line) + screen_line_total < p_editor_data->display_line_total) |
|
|
{ |
|
|
percentile = (line_current - (screen_current_line - screen_begin_line) + screen_line_total) * 100 / p_editor_data->display_line_total; |
|
|
ctx.reach_end = 0; |
|
|
} |
|
|
else |
|
|
{ |
|
|
percentile = 100; |
|
|
ctx.reach_end = 1; |
|
|
} |
|
|
|
|
|
ctx.line_top = line_current - (screen_current_line - screen_begin_line) + 1; |
|
|
ctx.line_bottom = MIN(line_current - (screen_current_line - screen_begin_line) + screen_line_total, p_editor_data->display_line_total); |
|
| 421 |
|
|
| 422 |
snprintf(buffer, sizeof(buffer), |
snprintf(buffer, sizeof(buffer), |
| 423 |
"\033[1;44;33mµÚ\033[32m%ld\033[33m-\033[32m%ld\033[33mÐÐ (\033[32m%ld%%\033[33m) %s", |
"\033[1;44;33m[\033[32m%ld\033[33m;\033[32m%ld\033[33m] " |
| 424 |
ctx.line_top, |
"µÚ\033[32m%ld\033[33m/\033[32m%ld\033[33mÐÐ " |
| 425 |
ctx.line_bottom, |
"%s", |
| 426 |
percentile, |
row_pos, col_pos, |
| 427 |
|
ctx.line_cursor, p_editor_data->display_line_total, |
| 428 |
ctx.msg); |
ctx.msg); |
| 429 |
|
|
| 430 |
len = split_line(buffer, SCREEN_COLS, &eol, &display_len); |
len = split_line(buffer, SCREEN_COLS, &eol, &display_len); |
| 453 |
goto cleanup; |
goto cleanup; |
| 454 |
} |
} |
| 455 |
|
|
| 456 |
|
if (ch >= 32 && ch < 127) // printable character |
| 457 |
|
{ |
| 458 |
|
last_updated_line = line_current; |
| 459 |
|
|
| 460 |
|
if (editor_data_insert(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1, |
| 461 |
|
(const char *)&ch, 1, &last_updated_line) < 0) |
| 462 |
|
{ |
| 463 |
|
log_error("editor_data_op(INSERT ch) error\n"); |
| 464 |
|
} |
| 465 |
|
else |
| 466 |
|
{ |
| 467 |
|
screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current)); |
| 468 |
|
line_current -= (screen_current_line - row_pos); |
| 469 |
|
screen_current_line = (int)row_pos; |
| 470 |
|
|
| 471 |
|
col_pos++; |
| 472 |
|
if (col_pos <= p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]) |
| 473 |
|
{ |
| 474 |
|
continue; |
| 475 |
|
} |
| 476 |
|
col_pos = 1; |
| 477 |
|
ch = KEY_DOWN; |
| 478 |
|
} |
| 479 |
|
} |
| 480 |
|
else if (ch > 127 && ch <= 255) // CJK character |
| 481 |
|
{ |
| 482 |
|
hz_ch[hz_len] = (char)(ch - 256); |
| 483 |
|
hz_len++; |
| 484 |
|
|
| 485 |
|
if (hz_len == 2) // GBK |
| 486 |
|
{ |
| 487 |
|
hz_len = 0; |
| 488 |
|
last_updated_line = line_current; |
| 489 |
|
|
| 490 |
|
if (editor_data_insert(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1, |
| 491 |
|
hz_ch, 2, &last_updated_line) < 0) |
| 492 |
|
{ |
| 493 |
|
log_error("editor_data_op(INSERT hz) error\n"); |
| 494 |
|
} |
| 495 |
|
else |
| 496 |
|
{ |
| 497 |
|
screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current)); |
| 498 |
|
line_current -= (screen_current_line - row_pos); |
| 499 |
|
screen_current_line = (int)row_pos; |
| 500 |
|
|
| 501 |
|
col_pos += 2; |
| 502 |
|
if (col_pos <= p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]) |
| 503 |
|
{ |
| 504 |
|
continue; |
| 505 |
|
} |
| 506 |
|
col_pos = 1; |
| 507 |
|
ch = KEY_DOWN; |
| 508 |
|
} |
| 509 |
|
} |
| 510 |
|
} |
| 511 |
|
else if (ch == KEY_DEL) // Del |
| 512 |
|
{ |
| 513 |
|
last_updated_line = line_current; |
| 514 |
|
|
| 515 |
|
if (editor_data_delete(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1, |
| 516 |
|
&last_updated_line) < 0) |
| 517 |
|
{ |
| 518 |
|
log_error("editor_data_op(DELETE) error\n"); |
| 519 |
|
} |
| 520 |
|
else |
| 521 |
|
{ |
| 522 |
|
screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current)); |
| 523 |
|
} |
| 524 |
|
|
| 525 |
|
continue; |
| 526 |
|
} |
| 527 |
|
|
| 528 |
|
hz_len = 0; |
| 529 |
|
|
| 530 |
switch (ch) |
switch (ch) |
| 531 |
{ |
{ |
| 532 |
case KEY_NULL: |
case KEY_NULL: |
| 535 |
case Ctrl('C'): |
case Ctrl('C'): |
| 536 |
loop = 0; |
loop = 0; |
| 537 |
break; |
break; |
| 538 |
case Ctrl('H'): |
case KEY_CTRL_LEFT: |
| 539 |
col_pos = 1; |
col_pos = 1; |
| 540 |
break; |
break; |
| 541 |
case Ctrl('E'): |
case KEY_CTRL_RIGHT: |
| 542 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]); |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]); |
| 543 |
break; |
break; |
| 544 |
|
case KEY_CTRL_UP: |
| 545 |
|
row_pos = screen_begin_line; |
| 546 |
|
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])); |
| 547 |
|
break; |
| 548 |
|
case KEY_CTRL_DOWN: |
| 549 |
|
row_pos = SCREEN_ROWS - 1; |
| 550 |
|
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])); |
| 551 |
|
break; |
| 552 |
|
case KEY_INS: |
| 553 |
|
insert = !insert; |
| 554 |
|
break; |
| 555 |
case KEY_HOME: |
case KEY_HOME: |
| 556 |
row_pos = 1; |
row_pos = 1; |
| 557 |
col_pos = 1; |
col_pos = 1; |
| 594 |
} |
} |
| 595 |
if (line_current - screen_current_line < 0) // Reach begin |
if (line_current - screen_current_line < 0) // Reach begin |
| 596 |
{ |
{ |
| 597 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]); |
col_pos = 1; |
| 598 |
break; |
break; |
| 599 |
} |
} |
| 600 |
line_current -= screen_current_line; |
line_current -= screen_current_line; |
| 627 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]); |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]); |
| 628 |
break; |
break; |
| 629 |
} |
} |
| 630 |
line_current += (screen_line_total - (screen_current_line - screen_begin_line)); |
screen_current_line--; |
|
screen_current_line = screen_line_total; |
|
| 631 |
screen_end_line = SCREEN_ROWS - 1; |
screen_end_line = SCREEN_ROWS - 1; |
| 632 |
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])); |
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])); |
| 633 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |