Ticket #1447: 0001-Implementation-of-soft-wraps-screen-only-division-of.patch
File 0001-Implementation-of-soft-wraps-screen-only-division-of.patch, 112.2 KB (added by psprint, 15 months ago) |
---|
-
lib/keybind.h
From 25445612b3fe895cb5b64a3d45ebce415d1b3128 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski <sgniazdowski@gmail.com> Date: Thu, 17 Aug 2023 11:14:33 -0500 Subject: [PATCH] =?UTF-8?q?Implementation=20of=20soft=20wraps=20=E2=80=93?= =?UTF-8?q?=C2=A0screen=20only=20division=20of=20too=20long=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/keybind.h | 1 + lib/util.h | 7 + src/editor/edit-impl.h | 13 +- src/editor/edit.c | 501 ++++++++++++++++++++++++++------- src/editor/edit.h | 5 + src/editor/editbuffer.c | 151 ++++++++-- src/editor/editbuffer.h | 22 +- src/editor/editcmd.c | 42 +-- src/editor/editdraw.c | 579 ++++++++++++++++++++++++++------------- src/editor/editoptions.c | 16 +- src/editor/editsearch.c | 2 +- src/editor/editwidget.c | 32 ++- src/editor/editwidget.h | 11 +- src/editor/format.c | 12 +- src/setup.c | 1 + 15 files changed, 1020 insertions(+), 375 deletions(-) diff --git a/lib/keybind.h b/lib/keybind.h index 9c0fe98a1..8ec763523 100644
a b enum 39 39 40 40 /* common */ 41 41 CK_Enter = 1L, 42 CK_SoftFolds, 42 43 CK_ChangePanel, 43 44 CK_Up, 44 45 CK_Down, -
lib/util.h
diff --git a/lib/util.h b/lib/util.h index ec8b25ec5..d72d252a4 100644
a b 38 38 #define MC_PIPE_ERROR_CREATE_PIPE_STREAM -4 39 39 #define MC_PIPE_ERROR_READ -5 40 40 41 #define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME 42 #define WMSG2(x,y) send_message(WIDGET(x), NULL, y, -1, NULL) 43 #define WMSG3(x,y,p) send_message(WIDGET(x), NULL, y, p, NULL) 44 #define WMSG4(x,y,p,q) send_message(WIDGET(x), NULL, y, p, q) 45 #define WMSG(...) GET_MACRO(__VA_ARGS__, WMSG4, WMSG3, WMSG2)(__VA_ARGS__) 46 47 41 48 /* gnulib efa15594e17fc20827dba66414fb391e99905394 42 49 43 50 *_GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2. -
src/editor/edit-impl.h
diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 3d0054537..4beab55df 100644
a b extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO]; 128 128 129 129 extern int max_undo; 130 130 extern gboolean auto_syntax; 131 132 131 extern gboolean search_create_bookmark; 133 132 134 133 extern char *edit_window_state_char; 135 134 extern char *edit_window_close_char; 136 135 137 136 /*** declarations of public functions ************************************************************/ 137 #define sum_plines_to_row(x,y) sum_plines_to_row_full(x,y,1) 138 int sum_plines_to_row_full(GPtrArray *page_line_data, int row, gboolean count_only_second_etc_lines); 138 139 139 140 gboolean edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline); 140 141 WEdit *edit_find_editor (const WDialog * h); … … void edit_menu_cmd (WDialog * h); 144 145 void user_menu (WEdit * edit, const char *menu_file, int selected_entry); 145 146 void edit_init_menu (WMenuBar * menubar); 146 147 void edit_save_mode_cmd (void); 147 off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto );148 off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto, gboolean as_btes, off_t len_limit); 148 149 void edit_scroll_screen_over_cursor (WEdit * edit); 149 150 void edit_render_keypress (WEdit * edit); 150 151 void edit_scroll_upward (WEdit * edit, long i); 151 152 void edit_scroll_downward (WEdit * edit, long i); 152 153 void edit_scroll_right (WEdit * edit, long i); 153 154 void edit_scroll_left (WEdit * edit, long i); 154 void edit_move_up (WEdit * edit, long i, gboolean do_scroll );155 void edit_move_down (WEdit * edit, long i, gboolean do_scroll );155 void edit_move_up (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines); 156 void edit_move_down (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines); 156 157 void edit_move_to_prev_col (WEdit * edit, off_t p); 157 158 long edit_get_col (const WEdit * edit); 158 159 void edit_update_curs_row (WEdit * edit); … … void edit_delete_line (WEdit * edit); 168 169 169 170 int edit_delete (WEdit * edit, gboolean byte_delete); 170 171 int edit_backspace (WEdit * edit, gboolean byte_delete); 172 void edit_move_to_top (WEdit * edit); 173 void edit_move_to_bottom (WEdit * edit); 174 void edit_cursor_to_bol (WEdit * edit, gboolean screen_lines); 175 void edit_cursor_to_eol (WEdit * edit, gboolean screen_lines); 171 176 void edit_insert (WEdit * edit, int c); 172 177 void edit_insert_over (WEdit * edit); 173 178 void edit_cursor_move (WEdit * edit, off_t increment); -
src/editor/edit.c
diff --git a/src/editor/edit.c b/src/editor/edit.c index dc3b3228b..0e3ef47c2 100644
a b edit_options_t edit_options = { 107 107 }; 108 108 109 109 int max_undo = 32768; 110 int soft_last_row; 110 111 111 112 gboolean enable_show_tabs_tws = TRUE; 112 113 … … edit_find_filter (const vfs_path_t * filename_vpath) 256 257 return -1; 257 258 } 258 259 260 /* --------------------------------------------------------------------------------------------- */ 261 gboolean edit_set_end_column(WEdit *edit) 262 { 263 gboolean ret = FALSE; 264 Widget *w = WIDGET(edit); 265 Widget *wh = WIDGET(WIDGET(edit)->owner); 266 int x1, x2, last_column, start_column = 0, end_column; 267 268 int wh_cols = wh ? wh->rect.cols : COLS; 269 int wh_x = 0; 270 271 x1 = w->rect.x; 272 x2 = w->rect.x + w->rect.cols - 1; 273 if (x2 < x1 || x2 < wh_x) 274 { 275 /* Still, set a good, not overcomplicated, value */ 276 edit->end_col = edit->buffer.end_col = w->rect.cols-1; 277 return ret; /* false */ 278 } 279 280 last_column = wh_x + wh_cols-1; 281 if (x2 <= last_column) 282 end_column = w->rect.cols-1; 283 else if (x1 >= wh_x) 284 end_column = wh_cols-1-x1; 285 else 286 end_column = start_column+wh_cols-1; 287 288 ret = (end_column<=COLS-1) && (end_column>0); 289 if (!ret) 290 end_column = 80; 291 292 edit->end_col = end_column; 293 edit->buffer.end_col = end_column; 294 295 return ret; 296 } 297 259 298 /* --------------------------------------------------------------------------------------------- */ 260 299 261 300 static char * … … edit_load_file (WEdit * edit) 437 476 438 477 if (fast_load) 439 478 { 440 edit_buffer_init ( &edit->buffer, edit->stat1.st_size);479 edit_buffer_init (edit, &edit->buffer, edit->stat1.st_size); 441 480 442 481 if (!edit_load_file_fast (&edit->buffer, edit->filename_vpath)) 443 482 { … … edit_load_file (WEdit * edit) 447 486 } 448 487 else 449 488 { 450 edit_buffer_init ( &edit->buffer, 0);489 edit_buffer_init (edit, &edit->buffer, 0); 451 490 452 491 if (edit->filename_vpath != NULL 453 492 && *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) != '\0') … … is_blank (const edit_buffer_t * buf, off_t offset) 678 717 { 679 718 off_t s, f; 680 719 681 s = edit_buffer_get_bol (buf, offset );682 f = edit_buffer_get_eol (buf, offset ) - 1;720 s = edit_buffer_get_bol (buf, offset, FALSE); 721 f = edit_buffer_get_eol (buf, offset, FALSE) - 1; 683 722 while (s <= f) 684 723 { 685 724 int c; … … edit_find_line (WEdit * edit, long line) 708 747 edit->line_numbers[1] = edit->buffer.curs_line; 709 748 edit->line_offsets[1] = edit_buffer_get_current_bol (&edit->buffer); 710 749 edit->line_numbers[2] = edit->buffer.lines; 711 edit->line_offsets[2] = edit_buffer_get_bol (&edit->buffer, edit->buffer.size );750 edit->line_offsets[2] = edit_buffer_get_bol (&edit->buffer, edit->buffer.size, FALSE); 712 751 edit->caches_valid = TRUE; 713 752 } 714 753 if (line >= edit->buffer.lines) … … edit_find_line (WEdit * edit, long line) 736 775 if (line > edit->line_numbers[j]) 737 776 edit->line_offsets[i] = 738 777 edit_buffer_get_forward_offset (&edit->buffer, edit->line_offsets[j], 739 line - edit->line_numbers[j], 0 );778 line - edit->line_numbers[j], 0, FALSE); 740 779 else 741 780 edit->line_offsets[i] = 742 781 edit_buffer_get_backward_offset (&edit->buffer, edit->line_offsets[j], 743 edit->line_numbers[j] - line );782 edit->line_numbers[j] - line, FALSE); 744 783 edit->line_numbers[i] = line; 745 784 return edit->line_offsets[i]; 746 785 } … … edit_move_up_paragraph (WEdit * edit, gboolean do_scroll) 779 818 } 780 819 } 781 820 782 edit_move_up (edit, edit->buffer.curs_line - i, do_scroll );821 edit_move_up (edit, edit->buffer.curs_line - i, do_scroll, FALSE); 783 822 } 784 823 785 824 /* --------------------------------------------------------------------------------------------- */ … … edit_move_down_paragraph (WEdit * edit, gboolean do_scroll) 814 853 if (edit_line_is_blank (edit, i) || i >= edit->buffer.lines) 815 854 break; 816 855 } 817 edit_move_down (edit, i - edit->buffer.curs_line, do_scroll );856 edit_move_down (edit, i - edit->buffer.curs_line, do_scroll, FALSE); 818 857 } 819 858 820 859 /* --------------------------------------------------------------------------------------------- */ … … static void 823 862 edit_begin_page (WEdit * edit) 824 863 { 825 864 edit_update_curs_row (edit); 826 edit_move_up (edit, edit->curs_row, FALSE );865 edit_move_up (edit, edit->curs_row, FALSE, FALSE); 827 866 } 828 867 829 868 /* --------------------------------------------------------------------------------------------- */ … … static void 832 871 edit_end_page (WEdit * edit) 833 872 { 834 873 edit_update_curs_row (edit); 835 edit_move_down (edit, WIDGET (edit)->rect.lines - edit->curs_row - 1, FALSE );874 edit_move_down (edit, WIDGET (edit)->rect.lines - edit->curs_row - 1, FALSE, FALSE); 836 875 } 837 876 838 877 839 878 /* --------------------------------------------------------------------------------------------- */ 840 879 /** goto beginning of text */ 841 880 842 staticvoid881 void 843 882 edit_move_to_top (WEdit * edit) 844 883 { 845 884 if (edit->buffer.curs_line != 0) … … edit_move_to_top (WEdit * edit) 855 894 /* --------------------------------------------------------------------------------------------- */ 856 895 /** goto end of text */ 857 896 858 staticvoid897 void 859 898 edit_move_to_bottom (WEdit * edit) 860 899 { 861 900 if (edit->buffer.curs_line < edit->buffer.lines) 862 901 { 863 edit_move_down (edit, edit->buffer.lines - edit->curs_row, FALSE );902 edit_move_down (edit, edit->buffer.lines - edit->curs_row, FALSE, FALSE); 864 903 edit->start_display = edit->buffer.size; 865 904 edit->start_line = edit->buffer.lines; 866 905 edit_scroll_upward (edit, WIDGET (edit)->rect.lines - 1); … … edit_move_to_bottom (WEdit * edit) 871 910 /* --------------------------------------------------------------------------------------------- */ 872 911 /** goto beginning of line */ 873 912 874 staticvoid875 edit_cursor_to_bol (WEdit * edit )913 void 914 edit_cursor_to_bol (WEdit * edit, gboolean screen_lines) 876 915 { 877 edit_cursor_move (edit, edit_buffer_get_current_bol (&edit->buffer) - edit->buffer.curs1); 916 off_t bol = edit_buffer_get_bol(&edit->buffer, edit->buffer.curs1 - edit->flag, screen_lines); 917 screen_lines &= edit_options.soft_wrap; 918 edit->flag2 = TRUE; 919 edit->flag = FALSE; 920 edit_cursor_move (edit, bol - edit->buffer.curs1); 878 921 edit->search_start = edit->buffer.curs1; 879 922 edit->prev_col = edit_get_col (edit); 880 923 edit->over_col = 0; … … edit_cursor_to_bol (WEdit * edit) 883 926 /* --------------------------------------------------------------------------------------------- */ 884 927 /** goto end of line */ 885 928 886 staticvoid887 edit_cursor_to_eol (WEdit * edit )929 void 930 edit_cursor_to_eol (WEdit * edit, gboolean screen_lines) 888 931 { 889 edit_cursor_move (edit, edit_buffer_get_current_eol (&edit->buffer) - edit->buffer.curs1); 932 screen_lines &= edit_options.soft_wrap; 933 if (edit->flag) 934 return; 935 edit->flag2 = 0; 936 off_t eol = edit_buffer_get_eol(&edit->buffer, edit->buffer.curs1, screen_lines); 937 938 edit_cursor_move (edit, eol - edit->buffer.curs1); 890 939 edit->search_start = edit->buffer.curs1; 891 940 edit->prev_col = edit_get_col (edit); 892 941 edit->over_col = 0; … … edit_left_char_move_cmd (WEdit * edit) 1068 1117 */ 1069 1118 1070 1119 static void 1071 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction )1120 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction, gboolean screen_lines) 1072 1121 { 1073 1122 long p; 1074 long l = direction ? edit->buffer.curs_line : edit->buffer.lines - edit->buffer.curs_line; 1123 long l, cnt_; 1124 off_t curs1 = edit->buffer.curs1; 1125 off_t boln = edit_buffer_get_bol (&edit->buffer, curs1, FALSE); 1126 int col, real_col, end_col; 1075 1127 1128 screen_lines &= edit_options.soft_wrap; 1129 if (do_scroll) 1130 screen_lines = FALSE; 1131 if (direction) 1132 { 1133 l = edit_buffer_count_lines(&edit->buffer, 0, curs1, screen_lines); 1134 if (l==0) 1135 l++; 1136 p = edit_move_forward3 (edit, boln, 0, curs1, FALSE, 0); 1137 /* Count possible only "touched"/started screen line */ 1138 cnt_ = (p%edit->end_col==0) ? 1:0; 1139 l+=cnt_-1; 1140 } 1141 else 1142 { 1143 l = edit->buffer.lines - edit->buffer.curs_line; 1144 if (screen_lines && l < lines) 1145 { 1146 GPtrArray *page_line_data = edit->page_line_data; 1147 if (edit->page_line_data == NULL) 1148 page_line_data = edit->page_line_data = g_ptr_array_new_full(LINES, g_free); 1149 g_ptr_array_set_size(edit->page_line_data, LINES); 1150 cnt_ = sum_plines_to_row_full(page_line_data, soft_last_row+1, FALSE); 1151 l += cnt_; 1152 cnt_ = sum_plines_to_row_full(page_line_data, edit->array_row, FALSE); 1153 l -= 1 + cnt_; 1154 p = edit_move_forward3 (edit, boln, 0, curs1, FALSE, 0); 1155 cnt_ = p/edit->end_col - ((p%edit->end_col==0)?1:0); 1156 l -= cnt_; 1157 } 1158 } 1076 1159 if (lines > l) 1077 1160 lines = l; 1078 1161 … … edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi 1088 1171 else 1089 1172 edit_scroll_downward (edit, lines); 1090 1173 } 1091 p = edit_buffer_get_current_bol (&edit->buffer); 1092 p = direction ? edit_buffer_get_backward_offset (&edit->buffer, p, lines) : 1093 edit_buffer_get_forward_offset (&edit->buffer, p, lines, 0); 1094 edit_cursor_move (edit, p - edit->buffer.curs1); 1095 edit_move_to_prev_col (edit, p); 1174 p = edit_get_cursor_offset (edit); 1175 edit_update_curs_col(edit); 1176 col=edit->curs_col; 1177 end_col=edit->end_col; 1178 1179 if (/*m.right*/curs1==edit->prev_curs1+1 && col == 0 && curs1 != boln && 1180 /*not flagged */ !edit->flag) 1181 real_col=end_col; 1182 else if (/*m.left*/curs1==edit->prev_curs1-1 && 1183 col == end_col-1 && 1184 !edit->flag) 1185 real_col=end_col; 1186 else if (ABS(curs1-edit->prev_curs1) != 1 && col == 0 && curs1 != boln && !edit->flag2) 1187 real_col=end_col; 1188 else 1189 real_col=col; 1190 1191 if (direction) 1192 p=edit_buffer_get_backward_offset (&edit->buffer, p, lines, screen_lines); 1193 else 1194 p=edit_buffer_get_forward_offset (&edit->buffer, p, lines, 0, screen_lines); 1195 1196 int offset=edit_move_forward3(edit, p, col, 0, FALSE, 0); 1197 int offset2=edit_move_forward3(edit, p, real_col % end_col, 0, FALSE, 0); 1198 if (real_col == end_col && offset-1 > 0 && edit_buffer_get_byte_ex(&edit->buffer, offset-1) == '\n' && edit_buffer_get_byte_ex(&edit->buffer, offset) != '\n') 1199 offset2=offset-1; 1200 edit_cursor_move(edit, offset2 - curs1); 1096 1201 1097 1202 #ifdef HAVE_CHARSET 1098 1203 /* search start of current multibyte char (like CJK) */ 1099 if ( edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size1204 if (0 && edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size 1100 1205 && edit_buffer_get_current_byte (&edit->buffer) >= 256) 1101 1206 { 1102 1207 edit_right_char_move_cmd (edit); … … static void 1158 1263 edit_do_undo (WEdit * edit) 1159 1264 { 1160 1265 long ac; 1161 long count = 0;1162 1266 1163 1267 edit->undo_stack_disable = 1; /* don't record undo's onto undo stack! */ 1164 1268 edit->over_col = 0; … … edit_do_undo (WEdit * edit) 1200 1304 { 1201 1305 edit->mark1 = ac - MARK_1; 1202 1306 edit->column1 = 1203 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1 ),1204 0, edit->mark1 );1307 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1, TRUE), 1308 0, edit->mark1, FALSE, 0); 1205 1309 } 1206 1310 if (ac >= MARK_2 - 2 && ac < MARK_CURS - 2) 1207 1311 { 1208 1312 edit->mark2 = ac - MARK_2; 1209 1313 edit->column2 = 1210 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2 ),1211 0, edit->mark2 );1314 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2, TRUE), 1315 0, edit->mark2, FALSE, 0); 1212 1316 } 1213 1317 else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS) 1214 1318 { 1215 1319 edit->end_mark_curs = ac - MARK_CURS; 1216 1320 } 1217 if (count++) 1218 edit->force |= REDRAW_PAGE; /* more than one pop usually means something big */ 1321 edit->force |= REDRAW_PAGE; 1219 1322 } 1220 1323 1221 1324 if (edit->start_display > ac - KEY_PRESS) 1222 1325 { 1223 edit->start_line -= 1224 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display);1326 edit->start_line -= 1327 edit_buffer_count_lines(&edit->buffer, ac - KEY_PRESS, edit->start_display, FALSE) - 1; 1225 1328 edit->force |= REDRAW_PAGE; 1226 1329 } 1227 1330 else if (edit->start_display < ac - KEY_PRESS) 1228 1331 { 1229 1332 edit->start_line += 1230 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS );1333 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS, FALSE) - 1; 1231 1334 edit->force |= REDRAW_PAGE; 1232 1335 } 1233 1336 edit->start_display = ac - KEY_PRESS; /* see push and pop above */ … … static void 1243 1346 edit_do_redo (WEdit * edit) 1244 1347 { 1245 1348 long ac; 1246 long count = 0;1247 1349 1248 1350 if (edit->redo_stack_reset) 1249 1351 return; … … edit_do_redo (WEdit * edit) 1285 1387 { 1286 1388 edit->mark1 = ac - MARK_1; 1287 1389 edit->column1 = 1288 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1 ),1289 0, edit->mark1 );1390 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1, TRUE), 1391 0, edit->mark1, FALSE, 0); 1290 1392 } 1291 1393 else if (ac >= MARK_2 - 2 && ac < KEY_PRESS) 1292 1394 { 1293 1395 edit->mark2 = ac - MARK_2; 1294 1396 edit->column2 = 1295 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2 ),1296 0, edit->mark2 );1397 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2, TRUE), 1398 0, edit->mark2, FALSE, 0); 1297 1399 } 1298 /* more than one pop usually means something big */ 1299 if (count++) 1300 edit->force |= REDRAW_PAGE; 1400 edit->force |= REDRAW_PAGE; 1301 1401 } 1302 1402 1303 1403 if (edit->start_display > ac - KEY_PRESS) 1304 1404 { 1305 1405 edit->start_line -= 1306 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display );1406 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display, FALSE) -1; 1307 1407 edit->force |= REDRAW_PAGE; 1308 1408 } 1309 1409 else if (edit->start_display < ac - KEY_PRESS) 1310 1410 { 1311 1411 edit->start_line += 1312 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS );1412 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS, FALSE) -1; 1313 1413 edit->force |= REDRAW_PAGE; 1314 1414 } 1315 1415 edit->start_display = ac - KEY_PRESS; /* see push and pop above */ … … edit_auto_indent (WEdit * edit) 1404 1504 1405 1505 p = edit->buffer.curs1; 1406 1506 /* use the previous line as a template */ 1407 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1 );1507 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1, FALSE); 1408 1508 /* copy the leading whitespace of the line */ 1409 1509 while (TRUE) 1410 1510 { /* no range check - the line _is_ \n-terminated */ … … edit_move_block_to_right (WEdit * edit) 1604 1704 if (!eval_marks (edit, &start_mark, &end_mark)) 1605 1705 return; 1606 1706 1607 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark );1608 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1 );1707 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark, FALSE); 1708 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1, FALSE); 1609 1709 1610 1710 do 1611 1711 { … … edit_move_block_to_right (WEdit * edit) 1617 1717 else 1618 1718 edit_insert (edit, '\t'); 1619 1719 edit_cursor_move (edit, 1620 edit_buffer_get_bol (&edit->buffer, cur_bol ) - edit->buffer.curs1);1720 edit_buffer_get_bol (&edit->buffer, cur_bol, FALSE) - edit->buffer.curs1); 1621 1721 } 1622 1722 1623 1723 if (cur_bol == 0) 1624 1724 break; 1625 1725 1626 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1 );1726 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1, FALSE); 1627 1727 } 1628 1728 while (cur_bol >= start_bol); 1629 1729 … … edit_move_block_to_left (WEdit * edit) 1641 1741 if (!eval_marks (edit, &start_mark, &end_mark)) 1642 1742 return; 1643 1743 1644 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark );1645 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1 );1744 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark, FALSE); 1745 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1, FALSE); 1646 1746 1647 1747 do 1648 1748 { … … edit_move_block_to_left (WEdit * edit) 1671 1771 if (cur_bol == 0) 1672 1772 break; 1673 1773 1674 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1 );1774 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1, FALSE); 1675 1775 } 1676 1776 while (cur_bol >= start_bol); 1677 1777 … … edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * 1748 1848 } 1749 1849 } 1750 1850 1751 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0 ) - edit->buffer.curs1);1851 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0, FALSE, 0) - edit->buffer.curs1); 1752 1852 1753 1853 for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) 1754 1854 edit_insert (edit, ' '); … … edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * 1769 1869 /*** public functions ****************************************************************************/ 1770 1870 /* --------------------------------------------------------------------------------------------- */ 1771 1871 1872 1873 void 1874 edit_apply_curs_exceptions(WEdit *e) 1875 { 1876 off_t bol_m2 = edit_buffer_get_bol (&e->buffer, e->buffer.curs1 +(e->buffer.curs1-2>=0 ? -2:0), TRUE); 1877 off_t bol = edit_buffer_get_bol (&e->buffer, e->buffer.curs1, TRUE); 1878 off_t boln = edit_buffer_get_bol (&e->buffer, e->buffer.curs1, FALSE); 1879 off_t eol = edit_buffer_get_eol(&e->buffer, e->buffer.curs1, TRUE); 1880 off_t curs1 = e->buffer.curs1, prev_curs1 = e->prev_curs1; 1881 long size=e->buffer.size, psize=e->prev_size; 1882 long cnt_m2=edit_move_forward3(e, bol_m2, 0, eol, FALSE, 0); 1883 long col=edit_move_forward3(e, bol, 0, curs1, FALSE, 0); 1884 long end_col=e->end_col; 1885 edit_update_curs_row(e); 1886 1887 /* First one exception is turned on – the one 1888 * that increases cursor y position when at 1889 * first column and not at bol */ 1890 if (curs1 != boln && curs1 == bol && col == 0) 1891 { 1892 e->curs_row ++; 1893 if (cnt_m2 <= end_col-2) 1894 e->flag2=1; 1895 } 1896 1897 if (curs1 == bol && /*m.left*/curs1<prev_curs1) 1898 e->flag2 = TRUE; 1899 1900 /* Remaining apply only for screen-long lines */ 1901 if (cnt_m2 <= end_col-2) 1902 return; 1903 1904 /* The second exception – when moving at 1905 * col == 0 from a lower curs1 position (right), 1906 * meaning that it should be an end_col position 1907 */ 1908 if (/*m.right*/curs1==prev_curs1+1 && col == 0 && curs1 != boln && /*not flagged */ !e->flag) 1909 { 1910 if (psize + 1 != size) 1911 { 1912 e->flag=TRUE; 1913 e->curs_col=e->end_col; 1914 e->curs_row --; 1915 } 1916 e->flag2=0; 1917 } 1918 else if (/*m.right*/curs1==prev_curs1+1 && col == 1 && curs1 >= boln+1 && 1919 /* flagged */ e->flag) 1920 { 1921 if (psize + 1 != size) 1922 { 1923 edit_cursor_move(e, -1); 1924 e->flag=FALSE; 1925 e->curs_col=0; 1926 } 1927 e->flag2=1; 1928 } 1929 else if (/*m.left*/curs1==prev_curs1-1 && 1930 col == end_col-1 && 1931 !e->flag) 1932 { 1933 if (psize != size + 1) 1934 { 1935 edit_cursor_move (e, 1); 1936 e->flag=TRUE; 1937 e->curs_col=end_col; 1938 } 1939 e->flag2=0; 1940 } 1941 else if (ABS(curs1-prev_curs1) != 1 && col == 0 && curs1 != boln && !e->flag2) 1942 { 1943 e->curs_col=end_col; 1944 e->curs_row --; 1945 e->flag=TRUE; 1946 } 1947 else 1948 { 1949 e->flag=0; 1950 } 1951 } 1952 1772 1953 /** User edit menu, like user menu (F2) but only in editor. */ 1773 1954 1774 1955 void … … edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath) 2085 2266 * cursor on that line and show it in the middle of the screen. 2086 2267 */ 2087 2268 2088 WEdit * 2089 edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, long line) 2269 WEdit *edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, long line) 2090 2270 { 2091 2271 gboolean to_free = FALSE; 2092 2272 … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2124 2304 edit_save_size (edit); 2125 2305 } 2126 2306 2307 if (edit->page_line_data == NULL) 2308 edit->page_line_data = g_ptr_array_new_full(LINES, g_free); 2309 g_ptr_array_set_size(edit->page_line_data, LINES); 2310 2127 2311 edit->drag_state = MCEDIT_DRAG_NONE; 2128 2312 2129 2313 edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2153 2337 edit_set_codeset (edit); 2154 2338 #endif 2155 2339 2340 edit_set_end_column (edit); 2156 2341 if (!edit_load_file (edit)) 2157 2342 { 2158 2343 /* edit_load_file already gives an error message */ … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2179 2364 edit_move_to_line (edit, line - 1); 2180 2365 } 2181 2366 2367 2182 2368 edit_load_macro_cmd (edit); 2183 2369 2184 2370 return edit; … … edit_push_redo_action (WEdit * edit, long c) 2508 2694 edit->redo_stack_bottom = edit->redo_stack_pointer = 0; 2509 2695 } 2510 2696 2697 2698 /* --------------------------------------------------------------------------------------------- */ 2699 2511 2700 /* --------------------------------------------------------------------------------------------- */ 2512 2701 /** 2513 2702 Basic low level single character buffer alterations and movements at the cursor. … … edit_insert (WEdit * edit, int c) 2531 2720 /* now we must update some info on the file and check if a redraw is required */ 2532 2721 if (c == '\n') 2533 2722 { 2723 edit->buffer.line_begin_offset = edit->buffer.curs1; 2534 2724 book_mark_inc (edit, edit->buffer.curs_line); 2535 2725 edit->buffer.curs_line++; 2536 2726 edit->buffer.lines++; … … edit_backspace (WEdit * edit, gboolean byte_delete) 2724 2914 void 2725 2915 edit_cursor_move (WEdit * edit, off_t increment) 2726 2916 { 2917 gboolean scroll = FALSE; 2918 off_t idx; 2727 2919 if (increment < 0) 2728 2920 { 2729 for ( ; increment < 0 && edit->buffer.curs1 != 0; increment++)2921 for (idx = 0; idx > increment && edit->buffer.curs1 != 0; idx--) 2730 2922 { 2731 2923 int c; 2732 2924 … … edit_cursor_move (WEdit * edit, off_t increment) 2737 2929 c = edit_buffer_backspace (&edit->buffer); 2738 2930 if (c == '\n') 2739 2931 { 2932 edit->buffer.line_begin_offset = 0; 2933 for (int i=edit->buffer.curs1-1; i>0; i --) 2934 { 2935 unsigned char ch = edit_buffer_get_byte(&edit->buffer, i); 2936 if (ch == '\n') 2937 { 2938 edit->buffer.line_begin_offset = i + 1; 2939 break; 2940 } 2941 } 2740 2942 edit->buffer.curs_line--; 2741 2943 edit->force |= REDRAW_LINE_BELOW; 2944 if (edit->buffer.curs_line < edit->start_line) 2945 scroll = TRUE; 2742 2946 } 2743 2947 } 2948 if (scroll) 2949 { 2950 edit_scroll_upward (edit, edit->start_line - edit->buffer.curs_line); 2951 } 2744 2952 } 2745 2953 else 2746 2954 { 2747 for ( ; increment > 0 && edit->buffer.curs2 != 0; increment--)2955 for (idx = 0; idx < increment && edit->buffer.curs2 != 0; idx ++) 2748 2956 { 2749 2957 int c; 2750 2958 … … edit_cursor_move (WEdit * edit, off_t increment) 2755 2963 c = edit_buffer_delete (&edit->buffer); 2756 2964 if (c == '\n') 2757 2965 { 2966 edit->buffer.line_begin_offset = edit->buffer.curs1; 2758 2967 edit->buffer.curs_line++; 2968 if (edit->buffer.curs_line - edit->start_line >= soft_last_row) 2969 scroll = TRUE; 2759 2970 edit->force |= REDRAW_LINE_ABOVE; 2760 2971 } 2761 2972 } 2973 if (scroll) 2974 { 2975 edit_scroll_downward(edit, (edit->buffer.curs_line - edit->start_line) - soft_last_row); 2976 edit->force |= REDRAW_PAGE; 2977 } 2762 2978 } 2763 2979 } 2764 2980 … … edit_cursor_move (WEdit * edit, off_t increment) 2767 2983 /* If upto is zero returns index of cols across from current. */ 2768 2984 2769 2985 off_t 2770 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto )2986 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto, gboolean as_bytes, off_t col_limit) 2771 2987 { 2772 2988 off_t p, q; 2773 long col; 2989 long col, col_acc = 0, btes = 0, prev_len = 0; 2990 int char_length = 1; 2991 int utf_ch; 2774 2992 2775 2993 if (upto != 0) 2776 2994 { … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2778 2996 cols = -10; 2779 2997 } 2780 2998 else 2781 q = edit->buffer.size + 2;2999 q = edit->buffer.size + 1; 2782 3000 2783 3001 for (col = 0, p = current; p < q; p++) 2784 3002 { … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2797 3015 #ifdef HAVE_CHARSET 2798 3016 if (edit->utf8) 2799 3017 { 2800 int utf_ch; 2801 int char_length = 1; 2802 3018 char_length = 1; 2803 3019 utf_ch = edit_buffer_get_utf (&edit->buffer, p, &char_length); 3020 2804 3021 if (mc_global.utf8_display) 2805 3022 { 2806 3023 if (char_length > 1) … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2814 3031 2815 3032 c = convert_to_display_c (c); 2816 3033 #endif 3034 3035 if (c == '\n') { 3036 return (upto != 0 ? (off_t) (as_bytes ? btes : col-col_acc) : p); 3037 } 2817 3038 2818 if (c == '\n') 2819 return (upto != 0 ? (off_t) col : p); 2820 if (c == '\t') 2821 col += TAB_SIZE - col % TAB_SIZE; 3039 #ifdef HAVE_CHARSET 3040 if (edit->utf8) 3041 { 3042 btes += prev_len <= 1 ? char_length : 0; 3043 prev_len = prev_len <= 1 ? char_length : prev_len - 1; 3044 } else 3045 btes += 1; 3046 #else 3047 btes += 1; 3048 #endif 3049 3050 /* Treat tab specially, as it needs to use 3051 * whole line, not only screen line */ 3052 if (c == '\t' || utf_ch == '\t') { 3053 off_t boln = edit_buffer_get_bol(&edit->buffer, p, FALSE); 3054 off_t qq = boln, ncols = 0, acc = 0; 3055 int len = -1, ch; 3056 for(; len && qq <= p; 3057 (ch=edit_buffer_get_utf(&edit->buffer,qq,&len)), 3058 qq+=len, ncols+=(g_unichar_iswide (ch)>0)+(ch=='\t'?(TAB_SIZE-(ncols%TAB_SIZE)):len>0)) 3059 { 3060 /* Still modulo the line length */ 3061 if ((ncols-acc) >= edit->end_col) 3062 acc += edit->end_col; 3063 } 3064 /* Apply precisely calculated cols */ 3065 col = ncols; 3066 if (boln != current) 3067 col -= acc; 3068 } 2822 3069 else if ((c < 32 || c == 127) && (orig_c == c 2823 3070 #ifdef HAVE_CHARSET 2824 3071 || (!mc_global.utf8_display && !edit->utf8) … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2829 3076 col += 2; 2830 3077 else 2831 3078 col++; 3079 3080 if (col_limit > 0) 3081 { 3082 btes = ((col - col_acc) >= col_limit) ? 0 : btes; 3083 col_acc += ((col - col_acc) >= col_limit) ? col_limit : 0; 3084 } 2832 3085 } 2833 return (off_t) col; 3086 3087 return (off_t) (as_bytes ? btes : col-col_acc); 2834 3088 } 2835 3089 2836 3090 /* --------------------------------------------------------------------------------------------- */ … … edit_get_cursor_offset (const WEdit * edit) 2843 3097 } 2844 3098 2845 3099 /* --------------------------------------------------------------------------------------------- */ 3100 2846 3101 /** returns the current column position of the cursor */ 2847 3102 2848 3103 long 2849 3104 edit_get_col (const WEdit * edit) 2850 3105 { 2851 return (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 2852 edit->buffer.curs1); 3106 gboolean screen = edit_options.soft_wrap?1:0; 3107 off_t bol = edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1, screen); 3108 3109 off_t col = (long) edit_move_forward3 (edit, bol, 0, edit->buffer.curs1, FALSE, 0); 3110 col -= -2*edit->start_col; 3111 return col; 2853 3112 } 2854 3113 2855 3114 /* --------------------------------------------------------------------------------------------- */ … … edit_get_col (const WEdit * edit) 2857 3116 /* --------------------------------------------------------------------------------------------- */ 2858 3117 2859 3118 void 2860 edit_update_curs_row (WEdit * e dit)3119 edit_update_curs_row (WEdit * e) 2861 3120 { 2862 edit->curs_row = edit->buffer.curs_line - edit->start_line; 3121 /* Helper variables */ 3122 edit_buffer_t *buf = &e->buffer; 3123 off_t curs1 = edit_get_cursor_offset(e); 3124 3125 /* The screen-line count ↔ the cursor row */ 3126 int lines = edit_buffer_count_lines(buf, e->start_display, curs1, TRUE); 3127 /* Screen-line count should be 0-based */ 3128 e->curs_row = lines > 0 ? lines-1 : 0; 3129 /* Non screen-lines line count */ 3130 e->array_row = edit_buffer_count_lines (buf, e->start_display, curs1, FALSE); 3131 /* Make the line count 0-based */ 3132 e->array_row>0 ? e->array_row-- : 0; 2863 3133 } 2864 3134 2865 3135 /* --------------------------------------------------------------------------------------------- */ … … edit_update_curs_row (WEdit * edit) 2867 3137 void 2868 3138 edit_update_curs_col (WEdit * edit) 2869 3139 { 2870 edit->curs_col = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 2871 0, edit->buffer.curs1); 3140 edit->curs_col = edit_get_col(edit); 2872 3141 } 2873 3142 2874 3143 /* --------------------------------------------------------------------------------------------- */ … … edit_scroll_upward (WEdit * edit, long i) 2893 3162 { 2894 3163 edit->start_line -= i; 2895 3164 edit->start_display = 2896 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i );3165 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i, FALSE); 2897 3166 edit->force |= REDRAW_PAGE; 2898 3167 edit->force &= (0xfff - REDRAW_CHAR_ONLY); 2899 3168 } … … edit_scroll_downward (WEdit * edit, long i) 2908 3177 { 2909 3178 long lines_below; 2910 3179 2911 lines_below = edit->buffer.lines - edit->start_line - ( WIDGET (edit)->rect.lines- 1);3180 lines_below = edit->buffer.lines - edit->start_line - (soft_last_row - 1); 2912 3181 if (lines_below > 0) 2913 3182 { 2914 3183 if (i > lines_below) 2915 3184 i = lines_below; 2916 3185 edit->start_line += i; 2917 3186 edit->start_display = 2918 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0 );3187 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0, FALSE); 2919 3188 edit->force |= REDRAW_PAGE; 2920 3189 edit->force &= (0xfff - REDRAW_CHAR_ONLY); 2921 3190 } … … edit_move_to_prev_col (WEdit * edit, off_t p) 2958 3227 long over = edit->over_col; 2959 3228 2960 3229 edit_cursor_move (edit, 2961 edit_move_forward3 (edit, p, prev + edit->over_col, 0 ) - edit->buffer.curs1);3230 edit_move_forward3 (edit, p, prev + edit->over_col, 0, FALSE, 0) - edit->buffer.curs1); 2962 3231 2963 3232 if (edit_options.cursor_beyond_eol) 2964 3233 { 2965 3234 long line_len; 2966 3235 2967 3236 line_len = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 2968 edit_buffer_get_current_eol (&edit->buffer) );3237 edit_buffer_get_current_eol (&edit->buffer), FALSE, FALSE); 2969 3238 if (line_len < prev + edit->over_col) 2970 3239 { 2971 3240 edit->over_col = prev + over - line_len; … … edit_move_to_prev_col (WEdit * edit, off_t p) 2998 3267 p = edit_buffer_get_current_bol (&edit->buffer); 2999 3268 edit_cursor_move (edit, 3000 3269 edit_move_forward3 (edit, p, edit->curs_col, 3001 0 ) - edit->buffer.curs1);3270 0, FALSE, FALSE) - edit->buffer.curs1); 3002 3271 if (!left_of_four_spaces (edit)) 3003 3272 edit_cursor_move (edit, 3004 edit_move_forward3 (edit, p, q, 0 ) - edit->buffer.curs1);3273 edit_move_forward3 (edit, p, q, 0, FALSE, FALSE) - edit->buffer.curs1); 3005 3274 } 3006 3275 } 3007 3276 } … … void 3029 3298 edit_move_to_line (WEdit * e, long line) 3030 3299 { 3031 3300 if (line < e->buffer.curs_line) 3032 edit_move_up (e, e->buffer.curs_line - line, FALSE );3301 edit_move_up (e, e->buffer.curs_line - line, FALSE, FALSE); 3033 3302 else 3034 edit_move_down (e, line - e->buffer.curs_line, FALSE );3303 edit_move_down (e, line - e->buffer.curs_line, FALSE, FALSE); 3035 3304 edit_scroll_screen_over_cursor (e); 3036 3305 } 3037 3306 … … edit_execute_key_command (WEdit * edit, long command, int char_for_insertion) 3260 3529 void 3261 3530 edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3262 3531 { 3263 WRect *w = &WIDGET (edit)->rect;3264 3265 3532 if (command == CK_WindowFullscreen) 3266 3533 { 3267 3534 edit_toggle_fullscreen (edit); … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3353 3620 /* An ordinary key press */ 3354 3621 if (char_for_insertion >= 0) 3355 3622 { 3623 off_t prev_curs_col, col; 3624 3625 if (edit->curs_col == 0) 3626 edit->force |= REDRAW_AFTER_CURSOR; 3627 prev_curs_col = edit->curs_col; 3628 3356 3629 /* if non persistent selection and text selected */ 3357 3630 if (!edit_options.persistent_selections && edit->mark1 != edit->mark2) 3358 3631 edit_block_delete_cmd (edit); … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3408 3681 edit->force |= REDRAW_PAGE; 3409 3682 } 3410 3683 else 3684 { 3411 3685 check_and_wrap_line (edit); 3686 edit->force |= REDRAW_AFTER_CURSOR; 3687 } 3688 col = edit_get_col(edit); 3689 if (prev_curs_col == edit->buffer.end_col - 1 && col == 0) 3690 edit->force |= REDRAW_AFTER_CURSOR; 3412 3691 edit->found_len = 0; 3413 3692 edit->prev_col = edit_get_col (edit); 3414 3693 edit->search_start = edit->buffer.curs1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3467 3746 case CK_Right: 3468 3747 case CK_MarkLeft: 3469 3748 case CK_MarkRight: 3470 edit->force |= REDRAW_ CHAR_ONLY;3749 edit->force |= REDRAW_LINE; 3471 3750 break; 3472 3751 default: 3473 3752 break; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3497 3776 } 3498 3777 else 3499 3778 edit_backspace (edit, FALSE); 3779 3780 edit->force |= REDRAW_AFTER_CURSOR; 3500 3781 break; 3501 3782 case CK_Delete: 3502 3783 /* if non persistent selection and text selected */ … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3563 3844 MC_FALLTHROUGH; 3564 3845 case CK_PageUp: 3565 3846 case CK_MarkPageUp: 3566 edit_move_up (edit, w->lines - 1, TRUE);3847 edit_move_up (edit, soft_last_row, TRUE, FALSE); 3567 3848 break; 3568 3849 case CK_MarkColumnPageDown: 3569 3850 edit->column_highlight = 1; 3570 3851 MC_FALLTHROUGH; 3571 3852 case CK_PageDown: 3572 3853 case CK_MarkPageDown: 3573 edit_move_down (edit, w->lines - 1, TRUE);3854 edit_move_down (edit, soft_last_row, TRUE, FALSE); 3574 3855 break; 3575 3856 case CK_MarkColumnLeft: 3576 3857 edit->column_highlight = 1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3626 3907 MC_FALLTHROUGH; 3627 3908 case CK_Up: 3628 3909 case CK_MarkUp: 3629 edit_move_up (edit, 1, FALSE );3910 edit_move_up (edit, 1, FALSE, TRUE); 3630 3911 break; 3631 3912 case CK_MarkColumnDown: 3632 3913 edit->column_highlight = 1; 3633 3914 MC_FALLTHROUGH; 3634 3915 case CK_Down: 3635 3916 case CK_MarkDown: 3636 edit_move_down (edit, 1, FALSE );3917 edit_move_down (edit, 1, FALSE, TRUE); 3637 3918 break; 3638 3919 case CK_MarkColumnParagraphUp: 3639 3920 edit->column_highlight = 1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3654 3935 MC_FALLTHROUGH; 3655 3936 case CK_ScrollUp: 3656 3937 case CK_MarkScrollUp: 3657 edit_move_up (edit, 1, TRUE );3938 edit_move_up (edit, 1, TRUE, TRUE); 3658 3939 break; 3659 3940 case CK_MarkColumnScrollDown: 3660 3941 edit->column_highlight = 1; 3661 3942 MC_FALLTHROUGH; 3662 3943 case CK_ScrollDown: 3663 3944 case CK_MarkScrollDown: 3664 edit_move_down (edit, 1, TRUE );3945 edit_move_down (edit, 1, TRUE, TRUE); 3665 3946 break; 3666 3947 case CK_Home: 3667 3948 case CK_MarkToHome: 3668 edit_cursor_to_bol (edit );3949 edit_cursor_to_bol (edit, TRUE); 3669 3950 break; 3670 3951 case CK_End: 3671 3952 case CK_MarkToEnd: 3672 edit_cursor_to_eol (edit );3953 edit_cursor_to_eol (edit, TRUE); 3673 3954 break; 3674 3955 case CK_Tab: 3675 3956 /* if text marked shift block */ … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3757 4038 if (p->next != NULL) 3758 4039 { 3759 4040 p = p->next; 3760 if (p->line >= edit->start_line + w->lines|| p->line < edit->start_line)3761 edit_move_display (edit, p->line - w->lines/ 2);4041 if (p->line >= edit->start_line + soft_last_row+1 || p->line < edit->start_line) 4042 edit_move_display (edit, p->line - (soft_last_row+1) / 2); 3762 4043 edit_move_to_line (edit, p->line); 3763 4044 } 3764 4045 } … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3774 4055 p = p->prev; 3775 4056 if (p->line >= 0) 3776 4057 { 3777 if (p->line >= edit->start_line + w->lines|| p->line < edit->start_line)3778 edit_move_display (edit, p->line - w->lines/ 2);4058 if (p->line >= edit->start_line + soft_last_row+1 || p->line < edit->start_line) 4059 edit_move_display (edit, p->line - (soft_last_row+1) / 2); 3779 4060 edit_move_to_line (edit, p->line); 3780 4061 } 3781 4062 } 3782 4063 break; 3783 4064 4065 case CK_SoftFolds: 4066 edit_options.soft_wrap = !edit_options.soft_wrap; 4067 edit->start_col *= !edit_options.soft_wrap; 4068 edit->force |= REDRAW_COMPLETELY; 4069 break; 4070 3784 4071 case CK_Top: 3785 4072 case CK_MarkToFileBegin: 3786 4073 edit_move_to_top (edit); … … edit_stack_free (void) 4050 4337 /** move i lines */ 4051 4338 4052 4339 void 4053 edit_move_up (WEdit * edit, long i, gboolean do_scroll )4340 edit_move_up (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines) 4054 4341 { 4055 edit_move_updown (edit, i, do_scroll, TRUE); 4342 screen_lines &= edit_options.soft_wrap; 4343 edit_move_updown (edit, i, do_scroll, TRUE, screen_lines); 4056 4344 } 4057 4345 4058 4346 /* --------------------------------------------------------------------------------------------- */ 4059 4347 /** move i lines */ 4060 4348 4061 4349 void 4062 edit_move_down (WEdit * edit, long i, gboolean do_scroll )4350 edit_move_down (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines) 4063 4351 { 4064 edit_move_updown (edit, i, do_scroll, FALSE); 4352 screen_lines &= edit_options.soft_wrap; 4353 edit_move_updown (edit, i, do_scroll, FALSE, screen_lines); 4065 4354 } 4066 4355 4067 4356 /* --------------------------------------------------------------------------------------------- */ -
src/editor/edit.h
diff --git a/src/editor/edit.h b/src/editor/edit.h index 358aa3f14..ffdc0af97 100644
a b typedef struct 60 60 gboolean show_right_margin; 61 61 gboolean simple_statusbar; /* statusbar draw style */ 62 62 gboolean check_nl_at_eof; 63 gboolean soft_wrap; 63 64 } edit_options_t; 64 65 65 66 /*** global variables defined in .c file *********************************************************/ 66 67 67 68 extern edit_options_t edit_options; 69 extern int soft_last_row; 68 70 69 71 /*** declarations of public functions ************************************************************/ 72 void edit_apply_curs_exceptions(WEdit *edit); 73 long edit_count_returns(WEdit *edit, off_t from, off_t to, gboolean screen_lines); 74 gboolean edit_set_end_column(WEdit *edit); 70 75 71 76 /* used in main() */ 72 77 void edit_stack_init (void); -
src/editor/editbuffer.c
diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 24bc7eeab..3da13b6e6 100644
a b 40 40 41 41 #include "lib/vfs/vfs.h" 42 42 43 #include "editwidget.h" 43 44 #include "edit-impl.h" 44 45 #include "editbuffer.h" 45 46 … … edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) 136 137 137 138 /* --------------------------------------------------------------------------------------------- */ 138 139 /*** public functions ****************************************************************************/ 140 /* Todo: query unicode chars (not bytes) */ 141 int edit_buffer_count_tabs(edit_buffer_t *buf, off_t first, off_t last, gboolean all_kinds) 142 { 143 int cnt = 0; 144 last = last > buf->size ? buf->size : last; 145 while (first <= last) 146 { 147 int byte = edit_buffer_get_byte(buf, first); 148 if (byte == '\t' || (all_kinds && byte == '\v')) 149 cnt ++; 150 ++ first; 151 } 152 return cnt; 153 } 154 139 155 /* --------------------------------------------------------------------------------------------- */ 140 156 /** 141 157 * Initialize editor buffers. … … edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) 144 160 */ 145 161 146 162 void 147 edit_buffer_init ( edit_buffer_t * buf, off_t size)163 edit_buffer_init (WEdit *e, edit_buffer_t * buf, off_t size) 148 164 { 149 165 buf->b1 = g_ptr_array_new_full (32, g_free); 150 166 buf->b2 = g_ptr_array_new_full (32, g_free); 167 buf->edit_widget = e; 168 buf->end_col = 73; 151 169 152 170 buf->curs1 = 0; 153 171 buf->curs2 = 0; … … void 167 185 edit_buffer_clean (edit_buffer_t * buf) 168 186 { 169 187 if (buf->b1 != NULL) 188 { 170 189 g_ptr_array_free (buf->b1, TRUE); 190 } 171 191 172 192 if (buf->b2 != NULL) 193 { 173 194 g_ptr_array_free (buf->b2, TRUE); 195 } 174 196 } 175 197 176 198 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_clean (edit_buffer_t * buf) 182 204 * 183 205 * @return '\n' if byte_index is negative or larger than file size; byte at byte_index otherwise. 184 206 */ 207 int 208 edit_buffer_get_byte_ex (const edit_buffer_t * buf, off_t byte_index) 209 { 210 char *p; 211 212 p = edit_buffer_get_byte_ptr (buf, byte_index); 213 214 return (p != NULL) ? *(unsigned char *) p : -1; 215 } 185 216 186 217 int 187 218 edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index) … … edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char 323 354 */ 324 355 325 356 long 326 edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last )357 edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last, gboolean screen_lines) 327 358 { 328 long lines = 0; 359 long lines = 0, prev_eol = 0, eol; 360 screen_lines &= edit_options.soft_wrap; 329 361 330 362 first = MAX (first, 0); 331 363 last = MIN (last, buf->size); 332 364 333 while (first < last) 334 if (edit_buffer_get_byte (buf, first++) == '\n') 335 lines++; 365 if (first == last) 366 return 0; 336 367 368 while (first <= last) 369 { 370 eol = edit_buffer_get_eol(buf, first, screen_lines); 371 /* Advance in buffer */ 372 if (edit_buffer_get_byte_ex(buf, eol) == '\n' || ~screen_lines || eol == prev_eol) 373 first = eol+1; 374 else 375 first = eol; 376 prev_eol = eol; 377 /* Count line */ 378 lines++; 379 } 337 380 return lines; 338 381 } 339 382 … … edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last) 348 391 */ 349 392 350 393 off_t 351 edit_buffer_get_bol (const edit_buffer_t * buf, off_t current )394 edit_buffer_get_bol (const edit_buffer_t * buf, off_t current_bol, gboolean screen_lines) 352 395 { 353 if (current <= 0) 396 off_t current_save = current_bol; 397 off_t current_eol = current_bol; 398 screen_lines &= edit_options.soft_wrap; 399 if (current_bol <= 0) 400 { 354 401 return 0; 355 356 for (; edit_buffer_get_byte (buf, current - 1) != '\n'; current--)402 } 403 for (; current_bol>0 && edit_buffer_get_byte (buf, current_bol-1)!='\n'; current_bol-=1) 357 404 ; 358 405 359 return current; 406 for (; (edit_buffer_get_byte (buf, current_eol)!='\n' || current_save == current_eol) && current_eol < buf->size 407 ; current_eol+=1); 408 409 410 if (screen_lines) 411 { 412 off_t pos = current_save - 413 edit_move_forward3(buf->edit_widget, current_bol, 0, current_save, TRUE, buf->end_col); 414 return pos; 415 } 416 return current_bol; 360 417 } 361 418 362 419 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_get_bol (const edit_buffer_t * buf, off_t current) 370 427 */ 371 428 372 429 off_t 373 edit_buffer_get_eol (const edit_buffer_t * buf, off_t current )430 edit_buffer_get_eol (const edit_buffer_t * buf, off_t current_eol, gboolean screen_lines) 374 431 { 375 if (current >= buf->size) 432 off_t current_save = current_eol; 433 off_t current_bol = current_eol; 434 off_t q; 435 screen_lines &= edit_options.soft_wrap; 436 if (current_eol >= buf->size) 376 437 return buf->size; 377 438 378 for (; edit_buffer_get_byte (buf, current) != '\n'; current++) 439 for (; current_bol > 0 && edit_buffer_get_byte (buf, current_bol - 1) != '\n'; 440 current_bol--) 379 441 ; 380 442 381 return current; 443 if (screen_lines) 444 { 445 off_t prev_eol=0; 446 for (; 447 (edit_buffer_get_byte_ex (buf, current_eol) != '\n') && 448 current_eol <= buf->size && 449 (current_eol==current_save || ((q=edit_move_forward3(buf->edit_widget, current_bol, 0, current_eol, FALSE, 0)%buf->end_col) != 0) 450 ) ; 451 current_eol=edit_move_forward3(buf->edit_widget,current_eol,1,0,FALSE,0), 452 current_eol+=prev_eol==current_eol?1:0,prev_eol=current_eol) 453 ; 454 if (current_eol > buf->size && edit_buffer_get_byte_ex(buf, current_eol) != '\n') 455 current_eol=buf->size; 456 } 457 else 458 for (; (edit_buffer_get_byte (buf, current_eol) != '\n') && current_eol < buf->size; current_eol++) 459 ; 460 461 462 return current_eol; 382 463 } 383 464 384 465 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_backspace (edit_buffer_t * buf) 638 719 */ 639 720 640 721 off_t 641 edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, off_t upto )722 edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, off_t upto, gboolean screen_lines) 642 723 { 724 screen_lines &= edit_options.soft_wrap; 643 725 if (upto != 0) 644 return (off_t) edit_buffer_count_lines (buf, current, upto );726 return (off_t) edit_buffer_count_lines (buf, current, upto, screen_lines); 645 727 646 728 lines = MAX (lines, 0); 647 729 730 if (lines > 0) 731 { 732 edit_update_curs_col(buf->edit_widget); 733 if (buf->edit_widget->curs_col == buf->end_col) 734 lines--; 735 } 736 648 737 while (lines-- != 0) 649 738 { 650 long next; 739 off_t next; 740 int byte; 651 741 652 next = edit_buffer_get_eol (buf, current) + 1; 653 if (next > buf->size) 742 next = edit_buffer_get_eol (buf, current, screen_lines); 743 byte = edit_buffer_get_byte_ex(buf, next); 744 745 if (byte == '\n' || !screen_lines) 746 next++; 747 if (next > buf->size+1) 654 748 break; 655 749 current = next; 656 750 } 657 658 751 return current; 659 752 } 660 753 … … edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long l 670 763 */ 671 764 672 765 off_t 673 edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines )766 edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines, gboolean screen_lines) 674 767 { 768 screen_lines &= edit_options.soft_wrap; 675 769 lines = MAX (lines, 0); 676 current = edit_buffer_get_bol (buf, current );770 current = edit_buffer_get_bol (buf, current, screen_lines); 677 771 678 772 while (lines-- != 0 && current != 0) 679 current = edit_buffer_get_bol (buf, current - 1); 773 { 774 current = edit_buffer_get_bol (buf, current - 1, screen_lines); 775 if (screen_lines && current > 0 && 776 edit_buffer_get_byte_ex(buf,current) == '\n' && 777 edit_buffer_get_byte_ex(buf,current-1) != '\n') 778 lines++; 779 } 680 780 781 if (current > 0 && screen_lines && edit_buffer_get_byte_ex(buf,current-1) != '\n') 782 current = edit_buffer_get_eol (buf, current - 1, screen_lines); 783 681 784 return current; 682 785 } 683 786 -
src/editor/editbuffer.h
diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index def17eec5..eb4486f42 100644
a b 13 13 14 14 typedef struct edit_buffer_struct 15 15 { 16 WEdit *edit_widget; 16 17 off_t curs1; /* position of the cursor from the beginning of the file. */ 17 18 off_t curs2; /* position from the end of the file */ 18 19 GPtrArray *b1; /* all data up to curs1 */ … … typedef struct edit_buffer_struct 20 21 off_t size; /* file size */ 21 22 long lines; /* total lines in the file */ 22 23 long curs_line; /* line number of the cursor. */ 24 long line_begin_offset; /* offset of first char after last \n */ 25 long end_col; /* Maximum column in current view */ 23 26 } edit_buffer_t; 24 27 25 28 typedef struct edit_buffer_read_file_status_msg_struct … … typedef struct edit_buffer_read_file_status_msg_struct 34 37 /*** global variables defined in .c file *********************************************************/ 35 38 36 39 /*** declarations of public functions ************************************************************/ 40 int edit_buffer_get_byte_ex (const edit_buffer_t * buf, off_t byte_index); 37 41 38 void edit_buffer_init (edit_buffer_t * buf, off_t size); 42 int edit_buffer_count_tabs(edit_buffer_t *buf, off_t first, off_t last, gboolean all_kinds); 43 void edit_buffer_init (WEdit *e, edit_buffer_t * buf, off_t size); 39 44 void edit_buffer_clean (edit_buffer_t * buf); 40 45 41 46 int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index); … … int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index); 43 48 int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_length); 44 49 int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_length); 45 50 #endif 46 long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last );47 off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current );48 off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current );51 long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last, gboolean screen_lines); 52 off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current, gboolean screen_lines); 53 off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current, gboolean screen_lines); 49 54 GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start, 50 55 gsize * cut); 51 56 gboolean edit_buffer_find_word_start (const edit_buffer_t * buf, off_t * word_start, … … int edit_buffer_delete (edit_buffer_t * buf); 57 62 int edit_buffer_backspace (edit_buffer_t * buf); 58 63 59 64 off_t edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, 60 off_t upto); 61 off_t edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines); 65 off_t upto, gboolean screen_lines); 66 off_t edit_buffer_get_backward_offset (const edit_buffer_t *buf, off_t current, long lines, 67 gboolean screen_lines); 62 68 63 69 off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size, 64 70 edit_buffer_read_file_status_msg_t * sm, gboolean * aborted); … … edit_buffer_get_previous_byte (const edit_buffer_t * buf) 94 100 static inline off_t 95 101 edit_buffer_get_current_bol (const edit_buffer_t * buf) 96 102 { 97 return edit_buffer_get_bol (buf, buf->curs1 );103 return edit_buffer_get_bol (buf, buf->curs1, FALSE); 98 104 } 99 105 100 106 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_get_current_bol (const edit_buffer_t * buf) 109 115 static inline off_t 110 116 edit_buffer_get_current_eol (const edit_buffer_t * buf) 111 117 { 112 return edit_buffer_get_eol (buf, buf->curs1 );118 return edit_buffer_get_eol (buf, buf->curs1, FALSE); 113 119 } 114 120 115 121 /* --------------------------------------------------------------------------------------------- */ -
src/editor/editcmd.c
diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index de624f249..a550b52da 100644
a b edit_delete_column_of_text (WEdit * edit) 467 467 long b, c, d; 468 468 469 469 eval_marks (edit, &m1, &m2); 470 n = edit_buffer_get_forward_offset (&edit->buffer, m1, 0, m2 ) + 1;471 c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1 ), 0, m1);472 d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2 ), 0, m2);470 n = edit_buffer_get_forward_offset (&edit->buffer, m1, 0, m2, FALSE) + 1; 471 c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1, TRUE), 0, m1, FALSE, 0); 472 d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2, TRUE), 0, m2, FALSE, 0); 473 473 b = MAX (MIN (c, d), MIN (edit->column1, edit->column2)); 474 474 c = MAX (c, MAX (edit->column1, edit->column2)); 475 475 … … edit_delete_column_of_text (WEdit * edit) 478 478 off_t r, p, q; 479 479 480 480 r = edit_buffer_get_current_bol (&edit->buffer); 481 p = edit_move_forward3 (edit, r, b, 0 );482 q = edit_move_forward3 (edit, r, c, 0 );481 p = edit_move_forward3 (edit, r, b, 0, FALSE, 0); 482 q = edit_move_forward3 (edit, r, c, 0, FALSE, 0); 483 483 p = MAX (p, m1); 484 484 q = MIN (q, m2); 485 485 edit_cursor_move (edit, p - edit->buffer.curs1); … … edit_delete_column_of_text (WEdit * edit) 492 492 if (n != 0) 493 493 edit_cursor_move (edit, 494 494 edit_buffer_get_forward_offset (&edit->buffer, edit->buffer.curs1, 1, 495 0 ) - edit->buffer.curs1);495 0, FALSE) - edit->buffer.curs1); 496 496 } 497 497 } 498 498 … … edit_block_delete (WEdit * edit) 547 547 edit_move_to_line (edit, curs_line); 548 548 /* calculate line width and cursor position before cut */ 549 549 line_width = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 550 edit_buffer_get_current_eol (&edit->buffer) );550 edit_buffer_get_current_eol (&edit->buffer), FALSE, FALSE); 551 551 if (edit_options.cursor_beyond_eol && curs_pos > line_width) 552 552 edit->over_col = curs_pos - line_width; 553 553 } … … edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l) 586 586 int c; 587 587 off_t x; 588 588 589 x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start ), 0, start);589 x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start, TRUE), 0, start, FALSE, 0); 590 590 c = edit_buffer_get_byte (&edit->buffer, start); 591 591 if ((x >= edit->column1 && x < edit->column2) 592 592 || (x >= edit->column2 && x < edit->column1) || c == '\n') … … edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long 699 699 break; 700 700 } 701 701 } 702 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0 ) - edit->buffer.curs1);702 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0, FALSE, FALSE) - edit->buffer.curs1); 703 703 704 704 for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) 705 705 edit_insert (edit, ' '); … … eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark) 1300 1300 long col1, col2; 1301 1301 off_t diff1, diff2; 1302 1302 1303 start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark );1304 start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1 ) + 1;1305 end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark );1306 end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark );1303 start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark, FALSE); 1304 start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1, FALSE) + 1; 1305 end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark, FALSE); 1306 end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark, FALSE); 1307 1307 col1 = MIN (edit->column1, edit->column2); 1308 1308 col2 = MAX (edit->column1, edit->column2); 1309 1309 1310 diff1 = edit_move_forward3 (edit, start_bol, col2, 0 ) -1311 edit_move_forward3 (edit, start_bol, col1, 0 );1312 diff2 = edit_move_forward3 (edit, end_bol, col2, 0 ) -1313 edit_move_forward3 (edit, end_bol, col1, 0 );1310 diff1 = edit_move_forward3 (edit, start_bol, col2, 0, FALSE, 0) - 1311 edit_move_forward3 (edit, start_bol, col1, 0, FALSE, 0); 1312 diff2 = edit_move_forward3 (edit, end_bol, col2, 0, FALSE, 0) - 1313 edit_move_forward3 (edit, end_bol, col1, 0, FALSE, 0); 1314 1314 1315 1315 *start_mark -= diff1; 1316 1316 *end_mark += diff2; … … edit_block_move_cmd (WEdit * edit) 1409 1409 x2 = x + edit->over_col; 1410 1410 1411 1411 /* do nothing when cursor inside first line of selected area */ 1412 if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1 ) ==1413 edit_buffer_get_eol (&edit->buffer, start_mark )) && x2 > c1 && x2 <= c2)1412 if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1, FALSE) == 1413 edit_buffer_get_eol (&edit->buffer, start_mark, FALSE)) && x2 > c1 && x2 <= c2) 1414 1414 return; 1415 1415 1416 1416 if (edit->buffer.curs1 > start_mark 1417 && edit->buffer.curs1 < edit_buffer_get_eol (&edit->buffer, end_mark ))1417 && edit->buffer.curs1 < edit_buffer_get_eol (&edit->buffer, end_mark, FALSE)) 1418 1418 { 1419 1419 if (x > c2) 1420 1420 x -= b_width; … … edit_block_move_cmd (WEdit * edit) 1429 1429 1430 1430 edit->over_col = MAX (0, edit->over_col - b_width); 1431 1431 /* calculate the cursor pos after delete block */ 1432 current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0 );1432 current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0, FALSE, 0); 1433 1433 edit_cursor_move (edit, current - edit->buffer.curs1); 1434 1434 edit_scroll_screen_over_cursor (edit); 1435 1435 -
src/editor/editdraw.c
diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index fbd1e095f..d61347c96 100644
a b 76 76 77 77 /*** file scope type declarations ****************************************************************/ 78 78 79 typedef struct 79 typedef struct line 80 80 { 81 81 unsigned int ch; 82 82 unsigned int style; 83 } line _s;83 } line; 84 84 85 85 /*** forward declarations (file scope functions) *************************************************/ 86 typedef struct 87 { 88 long soft_last_row; 89 long row; /* Normal (not soft-wrapped) line number to print to */ 90 int plines_count; /* Will occupy that much screen lines */ 91 int index; /* Line number in doc (normal, no wraps, whole) */ 92 int scr_index; /* Line number (logical) on screen, i.e.: from 0 */ 93 int size; /* Length of line ↔ # elements in ldata[] */ 94 long order_idx; /* Should be same as row above */ 95 96 /* In future versions it'll be possible to draw only part of 97 * the line – currently *_col fields are unused. */ 98 int q, start_col_real; 99 long ec; 100 char status[LINE_STATE_WIDTH + 1]; 101 int bookmarked; 102 gboolean visible; 103 104 line ldata[]; /* Flexible array for a single malloc */ 105 } MCELineData; 86 106 87 107 /*** file scope variables ************************************************************************/ 88 108 89 109 /*** file scope functions ************************************************************************/ 90 110 111 static MCELineData * 112 edit_prepare_this_line (WEdit * edit, off_t b, long order_idx, long row, long start_col, long end_col, long soft_last_row, gboolean draw, long base_line); 113 114 gboolean refresh_line_data(WEdit *edit, GPtrArray *page_line_data, long start_column, long end_column, long end_row); 115 116 gboolean refresh_line_data(WEdit *edit, GPtrArray *page_line_data, long start_column, long end_column, long end_row) 117 { 118 MCELineData *prev_ldata, *line_data; 119 gboolean ret = FALSE; 120 long base_line,row,start_row = 0; 121 int prev_plines = 0; 122 123 base_line=edit_buffer_count_lines(&edit->buffer,0,edit->start_display,FALSE); 124 off_t b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0, FALSE); 125 for (row = start_row; row < end_row; row++) 126 { 127 int pplines_add = 0; 128 if (!edit_options.soft_wrap) 129 pplines_add = -prev_plines; 130 line_data = edit_prepare_this_line (edit, b, row, row+prev_plines+pplines_add, 131 start_column, end_column, -1, FALSE,base_line); 132 line_data->plines_count += pplines_add; 133 prev_ldata = (MCELineData*)page_line_data->pdata[row]; 134 if (prev_ldata == NULL || prev_ldata->plines_count != line_data->plines_count) 135 /* Return true if any plines changed */ 136 ret = TRUE; 137 page_line_data->pdata[row] = line_data; 138 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count-1 : 0; 139 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 140 } 141 return ret; 142 } 143 144 int 145 sum_plines_to_row_full(GPtrArray *page_line_data, int row, gboolean count_only_second_etc_lines) 146 { 147 int prev_plines = 0; 148 149 if (!edit_options.soft_wrap) 150 return prev_plines; 151 152 for (int idx = 0; idx < row && idx < (long)page_line_data->len; idx ++) 153 { 154 MCELineData *line_data = page_line_data->pdata[idx]; 155 if(line_data != NULL) 156 prev_plines += (line_data->plines_count>0) ? line_data->plines_count-(count_only_second_etc_lines?1:0) : 0; 157 else 158 prev_plines += count_only_second_etc_lines?0:1; 159 } 160 return prev_plines; 161 } 162 91 163 static inline void 92 164 printwstr (const char *s, int len) 93 165 { … … status_string (WEdit * edit, char *s, int w) 136 208 } 137 209 138 210 /* The field lengths just prevent the status line from shortening too much */ 211 off_t bol = edit_buffer_get_current_bol(&edit->buffer); 212 off_t col = edit_move_forward3(edit,bol,0, 213 edit->buffer.curs1,FALSE,0); 139 214 if (edit_options.simple_statusbar) 140 215 g_snprintf (s, w, 141 216 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s", 142 217 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', 143 218 edit->modified ? 'M' : '-', 144 219 macro_index < 0 ? '-' : 'R', 145 edit->overwrite == 0 ? '-' :'O',146 edit->curs_col + edit->over_col,220 edit->overwrite == 0 ? '-':'O', 221 col, 147 222 edit->buffer.curs_line + 1, 148 223 edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, 149 224 byte_str, … … status_string (WEdit * edit, char *s, int w) 157 232 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', 158 233 edit->modified ? 'M' : '-', 159 234 macro_index < 0 ? '-' : 'R', 160 edit->overwrite == 0 ? '-' :'O',161 edit->curs_col + edit->over_col,235 edit->overwrite == 0 ? '-':'O', 236 col, 162 237 edit->start_line + 1, 163 238 edit->curs_row, 164 239 edit->buffer.curs_line + 1, … … edit_status_fullscreen (WEdit * edit, int color) 185 260 const int w = h->rect.cols; 186 261 const int gap = 3; /* between the filename and the status */ 187 262 const int right_gap = 5; /* at the right end of the screen */ 188 const int preferred_fname_len = 1 6;263 const int preferred_fname_len = 14; 189 264 char *status; 190 265 size_t status_size; 191 266 int status_len; … … edit_draw_window_icons (const WEdit * edit, int color) 377 452 /* --------------------------------------------------------------------------------------------- */ 378 453 379 454 static inline void 380 print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,381 long end_col, line_s line[], char *status, int bookmarked) 455 print_to_widget (WEdit * edit, MCELineData *line_data) 456 382 457 { 458 int linesize = line_data->size; 459 long row = edit_options.soft_wrap ? line_data->row : line_data->scr_index; 460 int q = line_data->q; 461 int start_col_real = line_data->start_col_real; 462 long ec = line_data->ec, idx; 463 line *line_ = line_data->ldata; 464 char *status = line_data->status; 465 int bookmarked = line_data->bookmarked; 466 383 467 Widget *w = WIDGET (edit); 384 line _s*p;468 line *p; 385 469 int x, x1, y, cols_to_skip; 386 int i ;387 int wrap_start;470 int i, yp; 471 int f_start; 388 472 int len; 389 473 474 if (row<line_data->row) 475 { 476 row = line_data->row; 477 } 390 478 x = start_col_real; 391 x1 = start_col+ EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;479 x1 = q + EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 392 480 y = row + EDIT_TEXT_VERTICAL_OFFSET; 393 cols_to_skip = abs 481 cols_to_skip = abs(x); 394 482 395 483 if (!edit->fullscreen) 396 484 { … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 398 486 y++; 399 487 } 400 488 401 tty_setcolor (EDITOR_NORMAL_COLOR); 402 if (bookmarked != 0) 403 tty_setcolor (bookmarked); 489 len = ec + 1 - q; 490 f_start = edit_options.word_wrap_line_length + edit->start_col; 404 491 405 len = end_col + 1 - start_col; 406 wrap_start = edit_options.word_wrap_line_length + edit->start_col; 407 408 if (len > 0 && w->rect.y + y >= 0) 492 for (idx=0; idx < line_data->plines_count || idx == 0; idx++) 409 493 { 410 if (!edit_options.show_right_margin || wrap_start > end_col) 411 tty_draw_hline (w->rect.y + y, w->rect.x + x1, ' ', len); 412 else if (wrap_start < 0) 494 if (len > 0 && w->rect.y + y >= 0) 413 495 { 414 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 415 tty_draw_hline (w->rect.y + y, w->rect.x + x1, ' ', len); 416 } 417 else 418 { 419 if (wrap_start > 0) 420 tty_draw_hline (w->rect.y + y, w->rect.x + x1, ' ', wrap_start); 496 if (!edit_options.show_right_margin || f_start > ec) 497 { 498 tty_setcolor (EDITOR_NORMAL_COLOR); 499 if (bookmarked != 0) 500 tty_setcolor (bookmarked); 421 501 422 len -= wrap_start; 423 if (len > 0) 502 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', len); 503 } 504 else if (f_start < 0) 424 505 { 425 506 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 426 tty_draw_hline (w->rect.y + y, w->rect.x + x1 + wrap_start, ' ', len); 507 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', len); 508 } 509 else 510 { 511 if (f_start > 0) 512 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', f_start); 513 514 len -= f_start; 515 if (len > 0) 516 { 517 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 518 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1 + f_start, ' ', len); 519 } 520 } 521 } 522 } 523 if (edit_options.line_state) 524 { 525 tty_setcolor (LINE_STATE_COLOR); 526 for (yp = 0; (edit_options.soft_wrap && yp <= linesize/ec + 527 (linesize%ec != 0 ? 0 : -1) + 528 (linesize == 0 ? 1 : 0)) || (!edit_options.soft_wrap && yp < 1); ++ yp) 529 { 530 for (i = 0; i < LINE_STATE_WIDTH; i++) 531 { 532 edit_move (x1 + i - edit_options.line_state_width, y+yp); 533 if (yp == 0) 534 { 535 if (status[i] == '\0') 536 status[i] = ' '; 537 tty_print_char (status[i]); 538 } else 539 tty_print_char (' '); 427 540 } 428 541 } 429 542 } 430 543 431 if (edit_options.line_state) 432 { 433 tty_setcolor (LINE_STATE_COLOR); 434 435 for (i = 0; i < LINE_STATE_WIDTH; i++) 436 { 437 edit_move (x1 + i - edit_options.line_state_width, y); 438 if (status[i] == '\0') 439 status[i] = ' '; 440 tty_print_char (status[i]); 441 } 442 } 544 edit->end_col = ec; 545 edit->buffer.end_col = ec; 443 546 444 547 edit_move (x1, y); 445 548 446 549 i = 1; 447 for (p = line; p->ch != 0; p++) 448 { 550 for (idx = 0, p = &line_[-edit->start_col]; (edit_options.soft_wrap && linesize -- > 0) || ( 551 !edit_options.soft_wrap && (linesize -- + edit->start_col > 0) && p->ch != 0 552 ); p++, idx++) 553 { 554 449 555 int style; 450 556 unsigned int textchar; 451 557 int color; 452 453 if (cols_to_skip != 0) 558 if (!edit_options.soft_wrap && cols_to_skip != 0) 454 559 { 455 560 cols_to_skip--; 456 561 continue; 457 562 } 458 563 564 /* Position each physical line */ 565 if (edit_options.soft_wrap && idx%ec == 0) 566 edit_move (x1, y++); 567 459 568 style = p->style & 0xFF00; 460 569 textchar = p->ch; 461 570 /* If non-printable - use black background */ … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 482 591 { 483 592 if (i > edit_options.word_wrap_line_length + edit->start_col) 484 593 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 485 i++;486 594 } 595 i++; 487 596 488 597 tty_print_anychar (textchar); 489 598 } … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 492 601 /* --------------------------------------------------------------------------------------------- */ 493 602 /** b is a pointer to the beginning of the line */ 494 603 495 static void496 edit_ draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col)604 static MCELineData * 605 edit_prepare_this_line (WEdit * edit, off_t b, long order_idx, long row, long start_col, long end_col, long soft_last_row_idx, gboolean draw, long base_line) 497 606 { 607 long line_count, cur_line, prev_line; 608 MCELineData *line_data; 498 609 Widget *w = WIDGET (edit); 499 line_s line[MAX_LINE_LEN]; 500 line_s *p = line; 610 line *p; 501 611 off_t q; 502 int col, start_col_real; 612 int wrap_line_len, line_size, start_col_real = 0; 613 int col; 614 int color; 503 615 int abn_style; 504 616 int book_mark = 0; 505 char line_stat[LINE_STATE_WIDTH + 1] = "\0";506 617 507 if (row > w->rect.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1)) 508 return; 618 q = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 619 line_size = edit_move_forward3 (edit, b, 0, q, FALSE, 0); 620 line_data = (MCELineData *) g_malloc0(sizeof(MCELineData) + sizeof(line) * 621 (line_size + /* sentinel —→ */ 1 + 622 edit_buffer_count_tabs(&edit->buffer,b,q, 623 FALSE)*8)); 624 p = line_data->ldata; 509 625 510 if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR)) 511 book_mark = BOOK_MARK_COLOR; 512 else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR)) 513 book_mark = BOOK_MARK_FOUND_COLOR; 514 515 if (book_mark != 0) 516 abn_style = book_mark << 16; 626 /* Helper var */ 627 if (edit_options.soft_wrap) 628 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 517 629 else 518 abn_style = MOD_ABNORMAL;630 wrap_line_len = abs(edit_options.word_wrap_line_length); 519 631 520 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;521 632 if (!edit->fullscreen) 522 633 { 523 634 end_col--; 524 635 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols) 525 636 end_col--; 526 637 } 638 wrap_line_len = end_col; 527 639 528 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0); 529 col = (int) edit_move_forward3 (edit, b, 0, q); 530 start_col_real = col + edit->start_col; 640 line_count = edit_buffer_count_lines(&edit->buffer, edit->start_display, q-1, FALSE); 641 line_count+=base_line+(line_count>0?-1:0); 642 643 line_data->soft_last_row = soft_last_row_idx; 644 line_data->row = row; 645 line_data->plines_count = line_size / wrap_line_len + ((line_size % wrap_line_len) ? 1 : 0); 646 if (!edit_options.soft_wrap) 647 line_data->plines_count = 0; 648 line_data->index = line_count+(line_count>0?-1:0); 649 line_data->scr_index = line_data->index - edit->start_line; 650 line_data->order_idx = order_idx; /* for investigation */ 651 line_data->size = line_size; 652 line_data->q = !edit_options.soft_wrap ? edit->start_col : 0; 653 line_data->ec = end_col; 654 line_data->visible = (order_idx <= line_data->soft_last_row); 655 656 if (!edit_options.soft_wrap) 657 line_data->plines_count = 0; 658 659 if (book_mark_query_color (edit, line_data->index, BOOK_MARK_COLOR)) 660 book_mark = BOOK_MARK_COLOR; 661 else if (book_mark_query_color (edit, line_data->index, BOOK_MARK_FOUND_COLOR)) 662 book_mark = BOOK_MARK_FOUND_COLOR; 663 664 line_data->bookmarked = book_mark; 665 666 if (book_mark != 0) 667 abn_style = book_mark << 16; 668 else 669 abn_style = MOD_ABNORMAL; 670 if (!edit_options.soft_wrap) 671 { 672 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 673 if (!edit->fullscreen) 674 { 675 end_col--; 676 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols) 677 end_col--; 678 } 679 } 680 681 color = edit_get_syntax_color (edit, b - 1); 682 if (edit_options.soft_wrap) 683 { 684 q = b; 685 col = (int) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 686 } 687 else 688 { 689 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0, FALSE, 0); 690 col = (int) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 691 line_data->start_col_real = start_col_real = col + edit->start_col; 692 } 531 693 532 694 if (edit_options.line_state) 533 695 { 534 long cur_line;535 536 cur_line = edit->start_line + row;537 if (cur_line <= edit->buffer.lines)538 g_snprintf (line_stat, sizeof (line_stat), "%7ld", cur_line + 1);696 int line_cnt=0; 697 cur_line = line_data->index; 698 if (line_data->order_idx == line_data->scr_index || cur_line+1 < line_cnt) 699 g_snprintf (line_data->status, sizeof (line_data->status), 700 "%7li ", cur_line + 1); 539 701 else 540 702 { 541 memset (line_ stat, ' ', LINE_STATE_WIDTH);542 line_ stat[LINE_STATE_WIDTH] = '\0';703 memset (line_data->status, ' ', LINE_STATE_WIDTH); 704 line_data->status[LINE_STATE_WIDTH] = '\0'; 543 705 } 544 706 prev_line = cur_line + 1; 545 707 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR)) 546 g_snprintf (line_ stat, 2, "*");708 g_snprintf (line_data->status, 2, "*"); 547 709 } 548 710 549 711 if (col <= -(edit->start_col + 16)) 550 712 start_col_real = start_col = 0; 551 713 else 552 714 { 553 715 off_t m1 = 0, m2 = 0; 554 716 555 717 eval_marks (edit, &m1, &m2); 556 557 if (row <= edit->buffer.lines - edit->start_line) 718 if (order_idx <= edit->buffer.lines - edit->start_line) 558 719 { 559 720 off_t tws = 0; 560 721 561 if ( edit_options.visible_tws && tty_use_colors ())562 for (tws = edit_buffer_get_eol (&edit->buffer, b ); tws > b; tws--)722 if (tty_use_colors () && edit_options.visible_tws) 723 for (tws = edit_buffer_get_eol (&edit->buffer, b, FALSE); tws > b; tws--) 563 724 { 564 725 unsigned int c; 565 726 … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 568 729 break; 569 730 } 570 731 571 while (col <= end_col - edit->start_col) 732 while ((edit_options.soft_wrap && col <= line_data->size) || 733 (!edit_options.soft_wrap && col <= line_data->size)) 572 734 { 573 735 int char_length = 1; 574 736 unsigned int c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 586 748 { 587 749 long x, cl; 588 750 589 x = (long) edit_move_forward3 (edit, b, 0, q );751 x = (long) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 590 752 cl = MIN (edit->column1, edit->column2); 591 753 if (x >= cl) 592 754 { … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 614 776 p->style |= book_mark << 16; 615 777 else 616 778 { 617 int color;618 619 779 color = edit_get_syntax_color (edit, q); 620 780 p->style |= color << 16; 621 781 } … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 623 783 switch (c) 624 784 { 625 785 case '\n': 626 col = end_col - edit->start_col + 1; /* quit */ 786 if (edit_options.soft_wrap) 787 col = line_data->size + 1; /* quit */ 788 else 789 col = line_data->size + 1; 627 790 break; 628 791 629 792 case '\t': 630 793 { 631 int tab_over ;794 int tab_over = 0; 632 795 int i; 633 796 634 797 i = TAB_SIZE - ((int) col % TAB_SIZE); 635 tab_over = (end_col - edit->start_col) - (col + i - 1); 636 if (tab_over < 0) 637 i += tab_over; 798 799 /* Supress off-screen part only if not in Soft Wraps mode */ 800 if(!edit_options.soft_wrap || edit_options.soft_wrap) 801 { 802 tab_over = end_col - (col + i - 1); 803 if (tab_over < 0) 804 i += tab_over; 805 } 638 806 col += i; 639 if ( (edit_options.visible_tabs || (edit_options.visible_tws && q >= tws))640 && enable_show_tabs_tws && tty_use_colors ())807 if (tty_use_colors () && (edit_options.visible_tabs || (edit_options.visible_tws && q >= tws)) 808 && enable_show_tabs_tws) 641 809 { 642 810 if ((p->style & MOD_MARKED) != 0) 643 811 c = p->style; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 669 837 p->style = c; 670 838 p++; 671 839 } 672 else 840 else if (i > 0) 673 841 { 674 842 p->ch = '>'; 675 843 p->style = c; 676 844 p++; 677 845 } 678 846 } 679 else if ( edit_options.visible_tws && q >= tws && enable_show_tabs_tws680 && tty_use_colors ())847 else if (tty_use_colors () && edit_options.visible_tws && q >= tws 848 && enable_show_tabs_tws) 681 849 { 682 850 p->ch = '.'; 683 851 p->style |= MOD_WHITESPACE; 684 852 c = p->style & ~MOD_CURSOR; 685 853 p++; 686 while (--i !=0)854 while (--i > 0) 687 855 { 688 856 p->ch = ' '; 689 857 p->style = c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 695 863 p->ch |= ' '; 696 864 c = p->style & ~MOD_CURSOR; 697 865 p++; 698 while (--i !=0)866 while (--i > 0) 699 867 { 700 868 p->ch = ' '; 701 869 p->style = c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 706 874 break; 707 875 708 876 case ' ': 709 if (edit_options.visible_tws && q >= tws && enable_show_tabs_tws 710 && tty_use_colors ()) 877 if (tty_use_colors () && edit_options.visible_tws && q >= tws && enable_show_tabs_tws) 711 878 { 712 879 p->ch = '.'; 713 880 p->style |= MOD_WHITESPACE; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 796 963 if (char_length > 1) 797 964 q += char_length - 1; 798 965 799 if (col > (end_col - edit->start_col + 1)) 800 { 966 if ((edit_options.soft_wrap && col > (line_data->size + 1)) 967 || (!edit_options.soft_wrap && (col > line_data->size + 1))) 968 { 801 969 if (wide_width_char) 802 970 { 803 971 p--; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 814 982 } 815 983 816 984 p->ch = 0; 817 818 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark); 985 if (draw) 986 print_to_widget (edit, line_data); 987 return line_data; 819 988 } 820 989 821 990 /* --------------------------------------------------------------------------------------------- */ 822 991 823 992 static inline void 824 edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column)993 edit_draw_this_char (WEdit * edit, off_t curs, long order_idx, long row, long start_column, long end_column) 825 994 { 995 MCELineData *line_data; 826 996 off_t b; 827 997 828 b = edit_buffer_get_bol (&edit->buffer, curs); 829 edit_draw_this_line (edit, b, row, start_column, end_column); 998 b = edit_buffer_get_bol (&edit->buffer, curs, FALSE); 999 line_data = edit_prepare_this_line (edit, b, order_idx, row, start_column, end_column, 0, TRUE,0); 1000 edit->page_line_data->pdata[order_idx] = line_data; 830 1001 } 831 1002 832 1003 /* --------------------------------------------------------------------------------------------- */ … … edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long 835 1006 static inline void 836 1007 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column) 837 1008 { 838 static long prev_curs_row = 0;839 static off_t prev_curs = 0;1009 long base_line,y = 0,y_pos; 1010 MCELineData *line_data = NULL; 840 1011 841 Widget *we = WIDGET (edit); 842 Widget *wh = WIDGET (we->owner); 843 WRect *w = &we->rect; 1012 Widget *w = WIDGET (edit); 1013 Widget *wh = WIDGET(w->owner); 844 1014 845 int force = edit->force; 846 int y1, x1, y2, x2; 847 int last_line, last_column; 1015 int force = edit->force,prev_plines = 0; 1016 int y1,x1,y2,x2; 1017 int last_line,last_column; 1018 base_line = edit_buffer_count_lines(&edit->buffer,0,edit->start_display,FALSE); 1019 base_line += edit->start_display == 0 ? 1 : 0; 1020 GPtrArray *page_line_data = edit->page_line_data; 848 1021 1022 if (edit->page_line_data == NULL) 1023 page_line_data = edit->page_line_data = g_ptr_array_new_full(LINES, g_free); 1024 g_ptr_array_set_size(edit->page_line_data, LINES); 1025 1026 y_pos = edit->array_row; 849 1027 /* draw only visible region */ 850 1028 851 1029 last_line = wh->rect.y + wh->rect.lines - 1; 852 1030 853 y1 = w-> y;1031 y1 = w->rect.y; 854 1032 if (y1 > last_line - 1 /* buttonbar */ ) 855 1033 return; 856 1034 857 1035 last_column = wh->rect.x + wh->rect.cols - 1; 858 1036 859 x1 = w-> x;1037 x1 = w->rect.x; 860 1038 if (x1 > last_column) 861 1039 return; 862 1040 863 y2 = w-> y + w->lines - 1;1041 y2 = w->rect.y + w->rect.lines - 1; 864 1042 if (y2 < wh->rect.y + 1 /* menubar */ ) 865 1043 return; 866 1044 867 x2 = w-> x + w->cols - 1;1045 x2 = w->rect.x + w->rect.cols - 1; 868 1046 if (x2 < wh->rect.x) 869 1047 return; 870 1048 … … render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, 874 1052 /* draw only visible region */ 875 1053 876 1054 if (y2 <= last_line - 1 /* buttonbar */ ) 877 end_row = w-> lines - 1;1055 end_row = w->rect.lines - 1; 878 1056 else if (y1 >= wh->rect.y + 1 /* menubar */ ) 879 1057 end_row = wh->rect.lines - 1 - y1 - 1; 880 1058 else 881 1059 end_row = start_row + wh->rect.lines - 1 - 1; 1060 soft_last_row = end_row; 882 1061 883 1062 if (x2 <= last_column) 884 end_column = w-> cols - 1;1063 end_column = w->rect.cols - 1; 885 1064 else if (x1 >= wh->rect.x) 886 1065 end_column = wh->rect.cols - 1 - x1; 887 1066 else 888 1067 end_column = start_column + wh->rect.cols - 1; 889 1068 } 1069 refresh_line_data(edit, page_line_data, start_column, end_column, end_row); 890 1070 1071 if (edit_options.soft_wrap) 1072 { 1073 int i, lines_occupied = 0; 1074 for (i=1 /*skip 0*/; i<=end_row; ++i) 1075 { 1076 /* for i=1, it is line 0 that's 1077 * summed up, and so on */ 1078 lines_occupied = i + sum_plines_to_row(page_line_data, i); 1079 if (lines_occupied >= wh->rect.lines-1-1) 1080 break; 1081 } 1082 soft_last_row = i-1; 1083 } 1084 else 1085 soft_last_row = end_row; 891 1086 /* 892 1087 * If the position of the page has not moved then we can draw the cursor 893 1088 * character only. This will prevent line flicker when using arrow keys. … … render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, 899 1094 900 1095 if ((force & REDRAW_PAGE) != 0) 901 1096 { 902 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0 );1097 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0, FALSE); 903 1098 for (row = start_row; row <= end_row; row++) 904 1099 { 905 if (key_pending (edit)) 906 return; 907 edit_draw_this_line (edit, b, row, start_column, end_column); 908 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0); 1100 line_data = edit_prepare_this_line (edit, b, row, row+prev_plines, 1101 start_column, end_column, soft_last_row, row <= soft_last_row, 1102 base_line); 1103 page_line_data->pdata[row] = line_data; 1104 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count-1 : 0; 1105 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 909 1106 } 910 1107 } 911 1108 else 912 1109 { 913 long curs_row = edit->curs_row;914 1110 915 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)1111 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < y_pos) 916 1112 { 917 1113 long upto; 918 1114 1115 row = start_row; 919 1116 b = edit->start_display; 920 upto = MIN ( curs_row- 1, end_row);921 for (row = start_row; row <= upto; row++)1117 upto = MIN (y_pos - 1, end_row); 1118 while (row <= upto) 922 1119 { 923 if (key_pending (edit)) 924 return; 925 edit_draw_this_line (edit, b, row, start_column, end_column); 926 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0); 1120 line_data = edit_prepare_this_line (edit, b, row, row+prev_plines, 1121 start_column, end_column, soft_last_row, row <= soft_last_row, 1122 base_line); 1123 page_line_data->pdata[row] = line_data; 1124 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count-1 : 0; 1125 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 1126 row++; 927 1127 } 928 1128 } 929 930 1129 /* if (force & REDRAW_LINE) ---> default */ 1130 y = (y_pos-1 < 0) ? 0 : y_pos-1; 931 1131 b = edit_buffer_get_current_bol (&edit->buffer); 932 if (curs_row >= start_row && curs_row <= end_row) 1132 if (y_pos-y == 1) 1133 b = edit_buffer_get_backward_offset (&edit->buffer, b, 1, FALSE); 1134 while (y <= y_pos && y >= start_row && y <= end_row) 933 1135 { 934 if (key_pending (edit)) 935 return; 936 edit_draw_this_line (edit, b, curs_row, start_column, end_column); 1136 prev_plines = sum_plines_to_row(edit->page_line_data, y); 1137 line_data = edit_prepare_this_line (edit, b, y, y+prev_plines, 1138 start_column, end_column, soft_last_row, y <= soft_last_row,base_line); 1139 page_line_data->pdata[y] = line_data; 1140 y++; 1141 if (y <= y_pos) 1142 b = edit_buffer_get_forward_offset(&edit->buffer, b, 1, 0, FALSE); 937 1143 } 938 1144 939 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)1145 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > y_pos) 940 1146 { 941 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0); 942 for (row = MAX (curs_row + 1, start_row); row <= end_row; row++) 1147 row = MAX (y_pos+1, start_row); 1148 prev_plines = sum_plines_to_row(page_line_data, row); 1149 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, row, 0, FALSE); 1150 for (; row <= end_row; row++) 943 1151 { 944 if (key_pending (edit))945 return;946 edit_draw_this_line (edit, b, row, start_column, end_column);947 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0 );1152 line_data = edit_prepare_this_line (edit, b, row, row+prev_plines, start_column, end_column, soft_last_row, row <= soft_last_row,base_line); 1153 page_line_data->pdata[row] = line_data; 1154 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count-1 : 0; 1155 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 948 1156 } 949 1157 } 950 1158 951 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row>= 1)1159 if ((force & REDRAW_LINE_ABOVE) != 0 && y_pos >= 1) 952 1160 { 953 row = curs_row- 1;1161 row = y_pos - 1; 954 1162 b = edit_buffer_get_backward_offset (&edit->buffer, 955 1163 edit_buffer_get_current_bol (&edit->buffer), 956 1 );1164 1, FALSE); 957 1165 if (row >= start_row && row <= end_row) 958 1166 { 959 if (key_pending (edit))960 return;961 edit_draw_this_line (edit, b, row, start_column, end_column);1167 prev_plines = sum_plines_to_row(edit->page_line_data, row); 1168 line_data = edit_prepare_this_line (edit, b, row, row+prev_plines, start_column, end_column, soft_last_row, row <= soft_last_row,base_line); 1169 page_line_data->pdata[row] = line_data; 962 1170 } 963 1171 } 964 965 if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) 1172 if ((force & REDRAW_LINE_BELOW) != 0 && y_pos < w->rect.lines - 1) 966 1173 { 967 row = curs_row+ 1;1174 row = y_pos + 1; 968 1175 b = edit_buffer_get_current_bol (&edit->buffer); 969 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0 );1176 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 970 1177 if (row >= start_row && row <= end_row) 971 1178 { 972 if (key_pending (edit))973 return;974 edit_draw_this_line (edit, b, row, start_column, end_column);1179 prev_plines = sum_plines_to_row(edit->page_line_data, row); 1180 line_data = edit_prepare_this_line (edit, b, row, row+prev_plines, start_column, end_column, soft_last_row, row <= soft_last_row,base_line); 1181 page_line_data->pdata[row] = line_data; 975 1182 } 976 1183 } 977 1184 } 978 1185 } 979 else if (prev_curs_row < edit->curs_row)980 {981 /* with the new text highlighting, we must draw from the top down */982 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);983 edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);984 }985 else986 {987 edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);988 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);989 }990 1186 991 1187 edit->force = 0; 992 993 prev_curs_row = edit->curs_row;994 prev_curs = edit->buffer.curs1;995 1188 } 996 1189 997 1190 /* --------------------------------------------------------------------------------------------- */ … … edit_status (WEdit * edit, gboolean active) 1044 1237 void 1045 1238 edit_scroll_screen_over_cursor (WEdit * edit) 1046 1239 { 1047 W Rect *w = &WIDGET (edit)->rect;1240 Widget *w = WIDGET (edit); 1048 1241 1049 1242 long p; 1050 1243 long outby; 1051 1244 int b_extreme, t_extreme, l_extreme, r_extreme; 1052 1245 1053 if (w-> lines <= 0 || w->cols <= 0)1246 if (w->rect.lines <= 0 || w->rect.cols <= 0) 1054 1247 return; 1055 1248 1056 rect_resize ( w, -EDIT_TEXT_VERTICAL_OFFSET,1249 rect_resize (&w->rect, -EDIT_TEXT_VERTICAL_OFFSET, 1057 1250 -(EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width)); 1058 1251 1059 1252 if (!edit->fullscreen) 1060 rect_grow ( w, -1, -1);1253 rect_grow (&w->rect, -1, -1); 1061 1254 1062 1255 r_extreme = EDIT_RIGHT_EXTREME; 1063 1256 l_extreme = EDIT_LEFT_EXTREME; … … edit_scroll_screen_over_cursor (WEdit * edit) 1065 1258 t_extreme = EDIT_TOP_EXTREME; 1066 1259 if (edit->found_len != 0) 1067 1260 { 1068 b_extreme = MAX (w-> lines / 4, b_extreme);1069 t_extreme = MAX (w-> lines / 4, t_extreme);1261 b_extreme = MAX (w->rect.lines / 4, b_extreme); 1262 t_extreme = MAX (w->rect.lines / 4, t_extreme); 1070 1263 } 1071 if (b_extreme + t_extreme + 1 > w-> lines)1264 if (b_extreme + t_extreme + 1 > w->rect.lines) 1072 1265 { 1073 1266 int n; 1074 1267 1075 1268 n = b_extreme + t_extreme; 1076 1269 if (n == 0) 1077 1270 n = 1; 1078 b_extreme = (b_extreme * (w-> lines - 1)) / n;1079 t_extreme = (t_extreme * (w-> lines - 1)) / n;1271 b_extreme = (b_extreme * (w->rect.lines - 1)) / n; 1272 t_extreme = (t_extreme * (w->rect.lines - 1)) / n; 1080 1273 } 1081 if (l_extreme + r_extreme + 1 > w-> cols)1274 if (l_extreme + r_extreme + 1 > w->rect.cols) 1082 1275 { 1083 1276 int n; 1084 1277 1085 1278 n = l_extreme + r_extreme; 1086 1279 if (n == 0) 1087 1280 n = 1; 1088 l_extreme = (l_extreme * (w-> cols - 1)) / n;1089 r_extreme = (r_extreme * (w-> cols - 1)) / n;1281 l_extreme = (l_extreme * (w->rect.cols - 1)) / n; 1282 r_extreme = (r_extreme * (w->rect.cols - 1)) / n; 1090 1283 } 1091 1284 p = edit_get_col (edit) + edit->over_col; 1092 1285 edit_update_curs_row (edit); 1093 outby = p + edit->start_col - w-> cols + 1 + (r_extreme + edit->found_len);1286 outby = p + edit->start_col - w->rect.cols + 1 + (r_extreme + edit->found_len); 1094 1287 if (outby > 0) 1095 1288 edit_scroll_right (edit, outby); 1096 1289 outby = l_extreme - p - edit->start_col; 1097 1290 if (outby > 0) 1098 1291 edit_scroll_left (edit, outby); 1099 1292 p = edit->curs_row; 1100 outby = p - w-> lines + 1 + b_extreme;1293 outby = p - w->rect.lines + 1 + b_extreme; 1101 1294 if (outby > 0) 1102 1295 edit_scroll_downward (edit, outby); 1103 1296 outby = t_extreme - p; … … edit_scroll_screen_over_cursor (WEdit * edit) 1105 1298 edit_scroll_upward (edit, outby); 1106 1299 edit_update_curs_row (edit); 1107 1300 1108 rect_resize ( w, EDIT_TEXT_VERTICAL_OFFSET,1301 rect_resize (&w->rect, EDIT_TEXT_VERTICAL_OFFSET, 1109 1302 EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width); 1110 1303 if (!edit->fullscreen) 1111 rect_grow ( w, 1, 1);1304 rect_grow (&w->rect, 1, 1); 1112 1305 } 1113 1306 1114 1307 /* --------------------------------------------------------------------------------------------- */ -
src/editor/editoptions.c
diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c index 9e059f330..0cb57a0ff 100644
a b static const char *wrap_str[] = { 54 54 N_("&None"), 55 55 N_("&Dynamic paragraphing"), 56 56 N_("Type &writer wrap"), 57 N_("Soft wr&aps"), 57 58 NULL 58 59 }; 59 60 … … edit_options_dialog (WDialog * h) 138 139 g_snprintf (wrap_length, sizeof (wrap_length), "%d", edit_options.word_wrap_line_length); 139 140 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d", TAB_SIZE); 140 141 141 if (edit_options.auto_para_formatting) 142 if (edit_options.soft_wrap) 143 wrap_mode = 3; 144 else if (edit_options.auto_para_formatting) 142 145 wrap_mode = 1; 143 146 else if (edit_options.typewriter_wrap) 144 147 wrap_mode = 2; … … edit_options_dialog (WDialog * h) 150 153 /* *INDENT-OFF* */ 151 154 QUICK_START_COLUMNS, 152 155 QUICK_START_GROUPBOX (N_("Wrap mode")), 153 QUICK_RADIO ( 3, wrap_str, &wrap_mode, NULL),156 QUICK_RADIO (4, wrap_str, &wrap_mode, NULL), 154 157 QUICK_STOP_GROUPBOX, 155 158 QUICK_SEPARATOR (FALSE), 156 159 QUICK_SEPARATOR (FALSE), … … edit_options_dialog (WDialog * h) 221 224 { 222 225 edit_options.auto_para_formatting = TRUE; 223 226 edit_options.typewriter_wrap = FALSE; 227 edit_options.soft_wrap = FALSE; 224 228 } 225 229 else if (wrap_mode == 2) 226 230 { 227 231 edit_options.auto_para_formatting = FALSE; 228 232 edit_options.typewriter_wrap = TRUE; 233 edit_options.soft_wrap = FALSE; 234 } 235 else if (wrap_mode == 3) 236 { 237 edit_options.auto_para_formatting = FALSE; 238 edit_options.typewriter_wrap = FALSE; 239 edit_options.soft_wrap = TRUE; 229 240 } 230 241 else 231 242 { 232 243 edit_options.auto_para_formatting = FALSE; 233 244 edit_options.typewriter_wrap = FALSE; 245 edit_options.soft_wrap = FALSE; 234 246 } 235 247 236 248 /* Load or unload syntax rules if the option has changed */ -
src/editor/editsearch.c
diff --git a/src/editor/editsearch.c b/src/editor/editsearch.c index 1bdf88350..1c2b33945 100644
a b edit_do_search (WEdit * edit) 615 615 edit->search_start = edit->search->normal_offset; 616 616 found = TRUE; 617 617 618 l += edit_buffer_count_lines (&edit->buffer, q, edit->search->normal_offset );618 l += edit_buffer_count_lines (&edit->buffer, q, edit->search->normal_offset, FALSE); 619 619 if (l != l_last) 620 620 book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR); 621 621 l_last = l; -
src/editor/editwidget.c
diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 05f03e83f..267739332 100644
a b static unsigned int edit_dlg_init_refcounter = 0; 89 89 90 90 /* --------------------------------------------------------------------------------------------- */ 91 91 /*** file scope functions ************************************************************************/ 92 static cb_ret_t edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, 93 void *data); 92 94 /* --------------------------------------------------------------------------------------------- */ 93 95 /** 94 96 * Init the 'edit' subsystem … … edit_update_cursor (WEdit * edit, const mouse_event_t * event) 721 723 long line_len; 722 724 723 725 line_len = 724 edit_move_forward3 (edit, edit_buffer_get_ current_bol (&edit->buffer), 0,725 edit_buffer_get_ current_eol (&edit->buffer));726 edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1, TRUE), 0, 727 edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1,TRUE), FALSE, 0); 726 728 727 729 if (x > line_len - 1) 728 730 { … … edit_update_cursor (WEdit * edit, const mouse_event_t * event) 737 739 } 738 740 739 741 if (y > edit->curs_row) 740 edit_move_down (edit, y - edit->curs_row, FALSE );742 edit_move_down (edit, y - edit->curs_row, FALSE, TRUE); 741 743 else if (y < edit->curs_row) 742 edit_move_up (edit, edit->curs_row - y, FALSE );744 edit_move_up (edit, edit->curs_row - y, FALSE, TRUE); 743 745 else 744 edit_move_to_prev_col (edit, edit_buffer_get_ current_bol (&edit->buffer));746 edit_move_to_prev_col (edit, edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1, TRUE)); 745 747 746 748 if (event->msg == MSG_MOUSE_CLICK) 747 749 { … … edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da 951 953 952 954 case MSG_DRAW: 953 955 e->force |= REDRAW_COMPLETELY; 956 WMSG(e,MSG_CURSOR,7); 954 957 edit_update_screen (e); 955 958 return MSG_HANDLED; 956 959 … … edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da 985 988 { 986 989 int y, x; 987 990 991 if (edit_options.soft_wrap) 992 edit_apply_curs_exceptions(e); 993 994 if (parm != 7) 995 { 996 e->prev_size = e->buffer.size; 997 e->prev_curs1 = e->buffer.curs1; 998 e->prev_curs_col = e->curs_col; 999 e->prev_curs_row = e->curs_row; 1000 } 1001 x = (e->fullscreen ? 0 : 1) + EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width + 1002 e->curs_col + e->start_col + e->over_col; 988 1003 y = (e->fullscreen ? 0 : 1) + EDIT_TEXT_VERTICAL_OFFSET + e->curs_row; 989 x = (e->fullscreen ? 0 : 1) + EDIT_TEXT_HORIZONTAL_OFFSET +990 edit_options.line_state_width + e->curs_col + e->start_col + e->over_col;991 1004 992 1005 widget_gotoyx (w, y, x); 993 1006 return MSG_HANDLED; … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1171 1184 break; 1172 1185 1173 1186 case MSG_MOUSE_SCROLL_UP: 1174 edit_move_up (edit, 2, TRUE );1187 edit_move_up (edit, 2, TRUE, FALSE); 1175 1188 edit_total_update (edit); 1176 1189 break; 1177 1190 1178 1191 case MSG_MOUSE_SCROLL_DOWN: 1179 edit_move_down (edit, 2, TRUE );1192 edit_move_down (edit, 2, TRUE, FALSE); 1180 1193 edit_total_update (edit); 1181 1194 break; 1182 1195 … … edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline) 1387 1400 1388 1401 group_add_widget_autopos (GROUP (h), w, WPOS_KEEP_ALL, NULL); 1389 1402 edit_set_buttonbar (edit, buttonbar_find (h)); 1403 edit_set_end_column(edit); 1390 1404 widget_draw (WIDGET (h)); 1391 1405 1392 1406 return TRUE; -
src/editor/editwidget.h
diff --git a/src/editor/editwidget.h b/src/editor/editwidget.h index 769b91a1e..6fc0193e9 100644
a b struct WEdit 98 98 off_t found_start; /* the found word from a search - start position */ 99 99 100 100 /* display information */ 101 long prev_size; /* size at previous key action */ 102 gboolean flag, flag2; /* flag – at eol, flag2 – at bol */ 103 long prev_curs1; 104 long prev_curs_col; 105 long prev_curs_row; 101 106 long start_display; /* First char displayed */ 102 107 long start_col; /* First displayed column, negative */ 103 108 long max_column; /* The maximum cursor position ever reached used to calc hori scroll bar */ … … struct WEdit 105 110 long curs_col; /* column position on screen */ 106 111 long over_col; /* pos after '\n' */ 107 112 int force; /* how much of the screen do we redraw? */ 113 long array_row; /* Position of cursor in the rows array */ 108 114 unsigned int overwrite:1; /* Overwrite on type mode (as opposed to insert) */ 109 115 unsigned int modified:1; /* File has been modified and needs saving */ 110 116 unsigned int loading_done:1; /* File has been loaded into the editor */ … … struct WEdit 113 119 unsigned int highlight:1; /* There is a selected block */ 114 120 unsigned int column_highlight:1; 115 121 unsigned int fullscreen:1; /* Is window fullscreen or not */ 116 long prev_col; /* recent column position of the cursor - used when moving 122 unsigned int soft_wrap:1; /* Are lines being soft-wrapped when too long? */ 123 long prev_col; /* Recent column position of the cursor - used when moving 117 124 up or down past lines that are shorter than the current line */ 118 125 long start_line; /* line number of the top of the page */ 126 GPtrArray *page_line_data; /* A temporary set of LINES-count MCELineData objects */ 127 long end_col; /* Last column in current window */ 119 128 120 129 /* file info */ 121 130 off_t mark1; /* position of highlight start */ -
src/editor/format.c
diff --git a/src/editor/format.c b/src/editor/format.c index 319306799..87a62546c 100644
a b line_start (const edit_buffer_t * buf, long line) 78 78 p = buf->curs1; 79 79 80 80 if (line < l) 81 p = edit_buffer_get_backward_offset (buf, p, l - line );81 p = edit_buffer_get_backward_offset (buf, p, l - line, FALSE); 82 82 else if (line > l) 83 p = edit_buffer_get_forward_offset (buf, p, line - l, 0 );83 p = edit_buffer_get_forward_offset (buf, p, line - l, 0, FALSE); 84 84 85 p = edit_buffer_get_bol (buf, p );85 p = edit_buffer_get_bol (buf, p, FALSE); 86 86 while (strchr ("\t ", edit_buffer_get_byte (buf, p)) != NULL) 87 87 p++; 88 88 return p; … … begin_paragraph (WEdit * edit, gboolean force, long *lines) 135 135 *lines = edit->buffer.curs_line - i; 136 136 137 137 return edit_buffer_get_backward_offset (&edit->buffer, 138 edit_buffer_get_current_bol (&edit->buffer), *lines );138 edit_buffer_get_current_bol (&edit->buffer), *lines, FALSE); 139 139 } 140 140 141 141 /* --------------------------------------------------------------------------------------------- */ … … end_paragraph (WEdit * edit, gboolean force) 161 161 edit_buffer_get_forward_offset (&edit->buffer, 162 162 edit_buffer_get_current_bol 163 163 (&edit->buffer), 164 i - edit->buffer.curs_line, 0 ));164 i - edit->buffer.curs_line, 0, FALSE), FALSE); 165 165 } 166 166 167 167 /* --------------------------------------------------------------------------------------------- */ … … edit_indent_width (const WEdit * edit, off_t p) 377 377 && q < edit->buffer.size - 1) 378 378 q++; 379 379 /* count the number of columns of indentation */ 380 return (long) edit_move_forward3 (edit, p, 0, q );380 return (long) edit_move_forward3 (edit, p, 0, q, FALSE, FALSE); 381 381 } 382 382 383 383 /* --------------------------------------------------------------------------------------------- */ -
src/setup.c
diff --git a/src/setup.c b/src/setup.c index 68e6f37c1..8e7e4cc3a 100644
a b static const struct 395 395 #ifdef USE_INTERNAL_EDIT 396 396 { "editor_word_wrap_line_length", &edit_options.word_wrap_line_length }, 397 397 { "editor_option_save_mode", &edit_options.save_mode }, 398 { "editor_soft_wraps", &edit_options.soft_wrap }, 398 399 #endif /* USE_INTERNAL_EDIT */ 399 400 { NULL, NULL } 400 401 };