/[LeafOK_CVS]/lbbs/src/editor.c
ViewVC logotype

Diff of /lbbs/src/editor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.17 by sysadm, Thu Jun 12 12:53:49 2025 UTC Revision 1.18 by sysadm, Fri Jun 13 11:20:24 2025 UTC
# Line 395  int editor_data_insert(EDITOR_DATA *p_ed Line 395  int editor_data_insert(EDITOR_DATA *p_ed
395    
396          if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])          if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])
397          {          {
398                  *p_offset -= p_editor_data->display_line_lengths[*p_display_line];                  if (*p_display_line + 1 < p_editor_data->display_line_total)
   
                 if (*p_display_line + 1 >= p_editor_data->display_line_total)  
                 {  
                         log_error("*p_display_line(%d) >= display_line_total(%d)\n", *p_display_line, p_editor_data->display_line_total);  
                 }  
                 else  
399                  {                  {
400                            *p_offset -= p_editor_data->display_line_lengths[*p_display_line];
401                          (*p_display_line)++;                          (*p_display_line)++;
402                  }                  }
403          }          }
# Line 469  int editor_data_delete(EDITOR_DATA *p_ed Line 464  int editor_data_delete(EDITOR_DATA *p_ed
464                  }                  }
465          }          }
466    
467            if (offset_data_line >= len_data_line) // end-of-line
468            {
469                    return 0;
470            }
471    
472          // Check str to be deleted          // Check str to be deleted
473          if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)          if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)
474          {          {
# Line 480  int editor_data_delete(EDITOR_DATA *p_ed Line 480  int editor_data_delete(EDITOR_DATA *p_ed
480          }          }
481          else          else
482          {          {
483                  log_error("Some strange character at display_line %ld, offset %ld: %d %d %d %d\n",                  log_error("Some strange character at display_line %ld, offset %ld: %d %d\n",
484                                    display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1],                                    display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1]);
                                   p_data_line[offset_data_line + 2], p_data_line[offset_data_line + 3]);  
485                  str_len = 1;                  str_len = 1;
486          }          }
487    
# Line 552  int editor_data_delete(EDITOR_DATA *p_ed Line 551  int editor_data_delete(EDITOR_DATA *p_ed
551    
552          *p_last_updated_line = display_line + MIN(i, split_line_total - 1);          *p_last_updated_line = display_line + MIN(i, split_line_total - 1);
553    
554          if (display_line + i < last_display_line)          if (*p_last_updated_line < last_display_line)
555          {          {
556                  // Remove redundant display line after last_display_line                  // Remove redundant display line after last_display_line
557                  for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++)                  for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++)
558                  {                  {
559                          p_editor_data->p_display_lines[j - (last_display_line - (display_line + i))] = p_editor_data->p_display_lines[j];                          p_editor_data->p_display_lines[j - (last_display_line - *p_last_updated_line)] = p_editor_data->p_display_lines[j];
560                          p_editor_data->display_line_lengths[j - (last_display_line - (display_line + i))] = p_editor_data->display_line_lengths[j];                          p_editor_data->display_line_lengths[j - (last_display_line - *p_last_updated_line)] = p_editor_data->display_line_lengths[j];
561                  }                  }
562    
563                  (p_editor_data->display_line_total) -= (last_display_line - (display_line + i));                  j = p_editor_data->display_line_total;
564                  last_display_line = display_line + i;                  (p_editor_data->display_line_total) -= (last_display_line - *p_last_updated_line);
565                    *p_last_updated_line = MAX(j - 1, *p_last_updated_line);
                 *p_last_updated_line = p_editor_data->display_line_total - 1;  
566          }          }
567    
568          return str_len;          return str_len;
# Line 739  int editor_display(EDITOR_DATA *p_editor Line 737  int editor_display(EDITOR_DATA *p_editor
737                                  {                                  {
738                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
739                                          {                                          {
740                                                    if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden
741                                                    {
742                                                            input_ok = 0;
743                                                            continue;
744                                                    }
745    
746                                                  col_pos--;                                                  col_pos--;
747                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
748                                                  {                                                  {
# Line 789  int editor_display(EDITOR_DATA *p_editor Line 793  int editor_display(EDITOR_DATA *p_editor
793                                                          row_pos += scroll_rows;                                                          row_pos += scroll_rows;
794                                                          output_current_row = screen_begin_row;                                                          output_current_row = screen_begin_row;
795                                                          output_end_row = SCREEN_ROWS - 1;                                                          output_end_row = SCREEN_ROWS - 1;
                                                         clrline(output_current_row, SCREEN_ROWS);  
796                                                  }                                                  }
797    
798                                                    clrline(output_current_row, output_end_row);
799                                          }                                          }
800    
801                                          continue;                                          continue;
# Line 819  int editor_display(EDITOR_DATA *p_editor Line 824  int editor_display(EDITOR_DATA *p_editor
824                                          break;                                          break;
825                                  case Ctrl('B'): // Bottom of screen                                  case Ctrl('B'): // Bottom of screen
826                                  case KEY_CTRL_DOWN:                                  case KEY_CTRL_DOWN:
827                                          row_pos = SCREEN_ROWS - 1;                                          if (p_editor_data->display_line_total < screen_row_total)
828                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));                                          {
829                                                    row_pos = p_editor_data->display_line_total;
830                                            }
831                                            else
832                                            {
833                                                    row_pos = SCREEN_ROWS - 1;
834                                            }
835                                            if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
836                                            {
837                                                    // last display line does NOT have \n in the end
838                                                    col_pos = MIN(col_pos, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1);
839                                            }
840                                            else
841                                            {
842                                                    col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));
843                                            }
844                                          break;                                          break;
845                                  case KEY_INS:                                  case KEY_INS:
846                                          key_insert = !key_insert;                                          key_insert = !key_insert;
# Line 841  int editor_display(EDITOR_DATA *p_editor Line 861  int editor_display(EDITOR_DATA *p_editor
861                                          if (p_editor_data->display_line_total < screen_row_total)                                          if (p_editor_data->display_line_total < screen_row_total)
862                                          {                                          {
863                                                  row_pos = p_editor_data->display_line_total;                                                  row_pos = p_editor_data->display_line_total;
864                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                                  col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
865                                                  break;                                                  break;
866                                          }                                          }
867                                          line_current = p_editor_data->display_line_total - screen_row_total;                                          line_current = p_editor_data->display_line_total - screen_row_total;
868                                          output_current_row = screen_begin_row;                                          output_current_row = screen_begin_row;
869                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
870                                          row_pos = SCREEN_ROWS - 1;                                          row_pos = SCREEN_ROWS - 1;
871                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                          col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
872                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
873                                          break;                                          break;
874                                  case KEY_LEFT:                                  case KEY_LEFT:
# Line 895  int editor_display(EDITOR_DATA *p_editor Line 915  int editor_display(EDITOR_DATA *p_editor
915                                          }                                          }
916                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
917                                          {                                          {
918                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                                  // last display line does NOT have \n in the end
919                                                    col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
920                                                  break;                                                  break;
921                                          }                                          }
922                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1