Ticket #1447: 0001-Implementation-of-soft-wraps-screen-only-division-of.3.patch
File 0001-Implementation-of-soft-wraps-screen-only-division-of.3.patch, 114.8 KB (added by psprint, 15 months ago) |
---|
-
lib/keybind.c
From a7499a548ad1a05a9347a6868d918ba556853319 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.c | 1 + lib/keybind.h | 1 + lib/util.h | 7 + src/editor/edit-impl.h | 15 +- src/editor/edit.c | 516 +++++++++++++++++++++++++++------- src/editor/edit.h | 5 + src/editor/editbuffer.c | 159 +++++++++-- src/editor/editbuffer.h | 23 +- src/editor/editcmd.c | 49 ++-- src/editor/editdraw.c | 585 +++++++++++++++++++++++++++------------ src/editor/editoptions.c | 16 +- src/editor/editsearch.c | 2 +- src/editor/editwidget.c | 31 ++- src/editor/editwidget.h | 11 +- src/editor/format.c | 14 +- src/keymap.c | 1 + src/setup.c | 1 + 17 files changed, 1076 insertions(+), 361 deletions(-) diff --git a/lib/keybind.c b/lib/keybind.c index ebbc82eed..1e4c9681c 100644
a b static name_keymap_t command_names[] = { 273 273 ADD_KEYMAP_NAME (MarkAndDown), 274 274 275 275 #ifdef USE_INTERNAL_EDIT 276 ADD_KEYMAP_NAME (SoftFolds), 276 277 ADD_KEYMAP_NAME (Close), 277 278 ADD_KEYMAP_NAME (Tab), 278 279 ADD_KEYMAP_NAME (Undo), -
lib/keybind.h
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..ee2e6044d 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, 139 gboolean count_only_second_etc_lines); 138 140 139 141 gboolean edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline); 140 142 WEdit *edit_find_editor (const WDialog * h); … … void edit_menu_cmd (WDialog * h); 144 146 void user_menu (WEdit * edit, const char *menu_file, int selected_entry); 145 147 void edit_init_menu (WMenuBar * menubar); 146 148 void edit_save_mode_cmd (void); 147 off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto); 149 off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto, 150 gboolean as_btes, off_t len_limit); 148 151 void edit_scroll_screen_over_cursor (WEdit * edit); 149 152 void edit_render_keypress (WEdit * edit); 150 153 void edit_scroll_upward (WEdit * edit, long i); 151 154 void edit_scroll_downward (WEdit * edit, long i); 152 155 void edit_scroll_right (WEdit * edit, long i); 153 156 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 );157 void edit_move_up (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines); 158 void edit_move_down (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines); 156 159 void edit_move_to_prev_col (WEdit * edit, off_t p); 157 160 long edit_get_col (const WEdit * edit); 158 161 void edit_update_curs_row (WEdit * edit); … … void edit_delete_line (WEdit * edit); 168 171 169 172 int edit_delete (WEdit * edit, gboolean byte_delete); 170 173 int edit_backspace (WEdit * edit, gboolean byte_delete); 174 void edit_move_to_top (WEdit * edit); 175 void edit_move_to_bottom (WEdit * edit); 176 void edit_cursor_to_bol (WEdit * edit, gboolean screen_lines); 177 void edit_cursor_to_eol (WEdit * edit, gboolean screen_lines); 171 178 void edit_insert (WEdit * edit, int c); 172 179 void edit_insert_over (WEdit * edit); 173 180 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..697dddb77 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 262 edit_set_end_column (WEdit * edit) 263 { 264 gboolean ret = FALSE; 265 Widget *w = WIDGET (edit); 266 Widget *wh = WIDGET (WIDGET (edit)->owner); 267 int x1, x2, last_column, start_column = 0, end_column; 268 269 int wh_cols = wh ? wh->rect.cols : COLS; 270 int wh_x = 0; 271 272 x1 = w->rect.x; 273 x2 = w->rect.x + w->rect.cols - 1; 274 if (x2 < x1 || x2 < wh_x) 275 { 276 /* Still, set a good, not overcomplicated, value */ 277 edit->end_col = edit->buffer.end_col = w->rect.cols - 1; 278 return ret; /* false */ 279 } 280 281 last_column = wh_x + wh_cols - 1; 282 if (x2 <= last_column) 283 end_column = w->rect.cols - 1; 284 else if (x1 >= wh_x) 285 end_column = wh_cols - 1 - x1; 286 else 287 end_column = start_column + wh_cols - 1; 288 289 ret = (end_column <= COLS - 1) && (end_column > 0); 290 if (!ret) 291 end_column = 80; 292 293 edit->end_col = end_column; 294 edit->buffer.end_col = end_column; 295 296 return ret; 297 } 298 259 299 /* --------------------------------------------------------------------------------------------- */ 260 300 261 301 static char * … … edit_load_file (WEdit * edit) 437 477 438 478 if (fast_load) 439 479 { 440 edit_buffer_init ( &edit->buffer, edit->stat1.st_size);480 edit_buffer_init (edit, &edit->buffer, edit->stat1.st_size); 441 481 442 482 if (!edit_load_file_fast (&edit->buffer, edit->filename_vpath)) 443 483 { … … edit_load_file (WEdit * edit) 447 487 } 448 488 else 449 489 { 450 edit_buffer_init ( &edit->buffer, 0);490 edit_buffer_init (edit, &edit->buffer, 0); 451 491 452 492 if (edit->filename_vpath != NULL 453 493 && *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) != '\0') … … is_blank (const edit_buffer_t * buf, off_t offset) 678 718 { 679 719 off_t s, f; 680 720 681 s = edit_buffer_get_bol (buf, offset );682 f = edit_buffer_get_eol (buf, offset ) - 1;721 s = edit_buffer_get_bol (buf, offset, FALSE); 722 f = edit_buffer_get_eol (buf, offset, FALSE) - 1; 683 723 while (s <= f) 684 724 { 685 725 int c; … … edit_find_line (WEdit * edit, long line) 708 748 edit->line_numbers[1] = edit->buffer.curs_line; 709 749 edit->line_offsets[1] = edit_buffer_get_current_bol (&edit->buffer); 710 750 edit->line_numbers[2] = edit->buffer.lines; 711 edit->line_offsets[2] = edit_buffer_get_bol (&edit->buffer, edit->buffer.size );751 edit->line_offsets[2] = edit_buffer_get_bol (&edit->buffer, edit->buffer.size, FALSE); 712 752 edit->caches_valid = TRUE; 713 753 } 714 754 if (line >= edit->buffer.lines) … … edit_find_line (WEdit * edit, long line) 736 776 if (line > edit->line_numbers[j]) 737 777 edit->line_offsets[i] = 738 778 edit_buffer_get_forward_offset (&edit->buffer, edit->line_offsets[j], 739 line - edit->line_numbers[j], 0 );779 line - edit->line_numbers[j], 0, FALSE); 740 780 else 741 781 edit->line_offsets[i] = 742 782 edit_buffer_get_backward_offset (&edit->buffer, edit->line_offsets[j], 743 edit->line_numbers[j] - line );783 edit->line_numbers[j] - line, FALSE); 744 784 edit->line_numbers[i] = line; 745 785 return edit->line_offsets[i]; 746 786 } … … edit_move_up_paragraph (WEdit * edit, gboolean do_scroll) 779 819 } 780 820 } 781 821 782 edit_move_up (edit, edit->buffer.curs_line - i, do_scroll );822 edit_move_up (edit, edit->buffer.curs_line - i, do_scroll, FALSE); 783 823 } 784 824 785 825 /* --------------------------------------------------------------------------------------------- */ … … edit_move_down_paragraph (WEdit * edit, gboolean do_scroll) 814 854 if (edit_line_is_blank (edit, i) || i >= edit->buffer.lines) 815 855 break; 816 856 } 817 edit_move_down (edit, i - edit->buffer.curs_line, do_scroll );857 edit_move_down (edit, i - edit->buffer.curs_line, do_scroll, FALSE); 818 858 } 819 859 820 860 /* --------------------------------------------------------------------------------------------- */ … … static void 823 863 edit_begin_page (WEdit * edit) 824 864 { 825 865 edit_update_curs_row (edit); 826 edit_move_up (edit, edit->curs_row, FALSE );866 edit_move_up (edit, edit->curs_row, FALSE, FALSE); 827 867 } 828 868 829 869 /* --------------------------------------------------------------------------------------------- */ … … static void 832 872 edit_end_page (WEdit * edit) 833 873 { 834 874 edit_update_curs_row (edit); 835 edit_move_down (edit, WIDGET (edit)->rect.lines - edit->curs_row - 1, FALSE );875 edit_move_down (edit, WIDGET (edit)->rect.lines - edit->curs_row - 1, FALSE, FALSE); 836 876 } 837 877 838 878 839 879 /* --------------------------------------------------------------------------------------------- */ 840 880 /** goto beginning of text */ 841 881 842 staticvoid882 void 843 883 edit_move_to_top (WEdit * edit) 844 884 { 845 885 if (edit->buffer.curs_line != 0) … … edit_move_to_top (WEdit * edit) 855 895 /* --------------------------------------------------------------------------------------------- */ 856 896 /** goto end of text */ 857 897 858 staticvoid898 void 859 899 edit_move_to_bottom (WEdit * edit) 860 900 { 861 901 if (edit->buffer.curs_line < edit->buffer.lines) 862 902 { 863 edit_move_down (edit, edit->buffer.lines - edit->curs_row, FALSE );903 edit_move_down (edit, edit->buffer.lines - edit->curs_row, FALSE, FALSE); 864 904 edit->start_display = edit->buffer.size; 865 905 edit->start_line = edit->buffer.lines; 866 906 edit_scroll_upward (edit, WIDGET (edit)->rect.lines - 1); … … edit_move_to_bottom (WEdit * edit) 871 911 /* --------------------------------------------------------------------------------------------- */ 872 912 /** goto beginning of line */ 873 913 874 staticvoid875 edit_cursor_to_bol (WEdit * edit )914 void 915 edit_cursor_to_bol (WEdit * edit, gboolean screen_lines) 876 916 { 877 edit_cursor_move (edit, edit_buffer_get_current_bol (&edit->buffer) - edit->buffer.curs1); 917 off_t bol = edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1 - edit->flag, screen_lines); 918 screen_lines &= edit_options.soft_wrap; 919 edit->flag2 = TRUE; 920 edit->flag = FALSE; 921 edit_cursor_move (edit, bol - edit->buffer.curs1); 878 922 edit->search_start = edit->buffer.curs1; 879 923 edit->prev_col = edit_get_col (edit); 880 924 edit->over_col = 0; … … edit_cursor_to_bol (WEdit * edit) 883 927 /* --------------------------------------------------------------------------------------------- */ 884 928 /** goto end of line */ 885 929 886 staticvoid887 edit_cursor_to_eol (WEdit * edit )930 void 931 edit_cursor_to_eol (WEdit * edit, gboolean screen_lines) 888 932 { 889 edit_cursor_move (edit, edit_buffer_get_current_eol (&edit->buffer) - edit->buffer.curs1); 933 screen_lines &= edit_options.soft_wrap; 934 if (edit->flag) 935 return; 936 edit->flag2 = 0; 937 off_t eol = edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1, screen_lines); 938 939 edit_cursor_move (edit, eol - edit->buffer.curs1); 890 940 edit->search_start = edit->buffer.curs1; 891 941 edit->prev_col = edit_get_col (edit); 892 942 edit->over_col = 0; … … edit_left_char_move_cmd (WEdit * edit) 1068 1118 */ 1069 1119 1070 1120 static void 1071 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction) 1121 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction, 1122 gboolean screen_lines) 1072 1123 { 1073 1124 long p; 1074 long l = direction ? edit->buffer.curs_line : edit->buffer.lines - edit->buffer.curs_line; 1125 long l, cnt_; 1126 off_t curs1 = edit->buffer.curs1; 1127 off_t boln = edit_buffer_get_bol (&edit->buffer, curs1, FALSE); 1128 int col, real_col, end_col; 1075 1129 1130 screen_lines &= edit_options.soft_wrap; 1131 if (do_scroll) 1132 screen_lines = FALSE; 1133 if (direction) 1134 { 1135 l = edit_buffer_count_lines (&edit->buffer, 0, curs1, screen_lines); 1136 if (l == 0) 1137 l++; 1138 p = edit_move_forward3 (edit, boln, 0, curs1, FALSE, 0); 1139 /* Count possible only "touched"/started screen line */ 1140 cnt_ = (p % edit->end_col == 0) ? 1 : 0; 1141 l += cnt_ - 1; 1142 } 1143 else 1144 { 1145 l = edit->buffer.lines - edit->buffer.curs_line; 1146 if (screen_lines && l < lines) 1147 { 1148 GPtrArray *page_line_data = edit->page_line_data; 1149 if (edit->page_line_data == NULL) 1150 page_line_data = edit->page_line_data = g_ptr_array_new_full (LINES, g_free); 1151 g_ptr_array_set_size (edit->page_line_data, LINES); 1152 cnt_ = sum_plines_to_row_full (page_line_data, soft_last_row + 1, FALSE); 1153 l += cnt_; 1154 cnt_ = sum_plines_to_row_full (page_line_data, edit->array_row, FALSE); 1155 l -= 1 + cnt_; 1156 p = edit_move_forward3 (edit, boln, 0, curs1, FALSE, 0); 1157 cnt_ = p / edit->end_col - ((p % edit->end_col == 0) ? 1 : 0); 1158 l -= cnt_; 1159 } 1160 } 1076 1161 if (lines > l) 1077 1162 lines = l; 1078 1163 … … edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi 1088 1173 else 1089 1174 edit_scroll_downward (edit, lines); 1090 1175 } 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); 1176 p = edit_get_cursor_offset (edit); 1177 edit_update_curs_col (edit); 1178 col = edit->curs_col; 1179 end_col = edit->end_col; 1180 1181 if ( /*m.right */ curs1 == edit->prev_curs1 + 1 && col == 0 && curs1 != boln && 1182 /*not flagged */ !edit->flag) 1183 real_col = end_col; 1184 else if ( /*m.left */ curs1 == edit->prev_curs1 - 1 && 1185 col == end_col - 1 && !edit->flag) 1186 real_col = end_col; 1187 else if (ABS (curs1 - edit->prev_curs1) != 1 && col == 0 && curs1 != boln && !edit->flag2) 1188 real_col = end_col; 1189 else 1190 real_col = col; 1191 1192 if (direction) 1193 p = edit_buffer_get_backward_offset (&edit->buffer, p, lines, screen_lines); 1194 else 1195 p = edit_buffer_get_forward_offset (&edit->buffer, p, lines, 0, screen_lines); 1196 1197 int offset = edit_move_forward3 (edit, p, col, 0, FALSE, 0); 1198 int offset2 = edit_move_forward3 (edit, p, real_col % end_col, 0, FALSE, 0); 1199 if (real_col == end_col && offset - 1 > 0 1200 && edit_buffer_get_byte_ex (&edit->buffer, offset - 1) == '\n' 1201 && edit_buffer_get_byte_ex (&edit->buffer, offset) != '\n') 1202 offset2 = offset - 1; 1203 edit_cursor_move (edit, offset2 - curs1); 1096 1204 1097 1205 #ifdef HAVE_CHARSET 1098 1206 /* search start of current multibyte char (like CJK) */ 1099 if ( edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size1207 if (0 && edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size 1100 1208 && edit_buffer_get_current_byte (&edit->buffer) >= 256) 1101 1209 { 1102 1210 edit_right_char_move_cmd (edit); … … static void 1158 1266 edit_do_undo (WEdit * edit) 1159 1267 { 1160 1268 long ac; 1161 long count = 0;1162 1269 1163 1270 edit->undo_stack_disable = 1; /* don't record undo's onto undo stack! */ 1164 1271 edit->over_col = 0; … … edit_do_undo (WEdit * edit) 1200 1307 { 1201 1308 edit->mark1 = ac - MARK_1; 1202 1309 edit->column1 = 1203 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 1204 0, edit->mark1); 1310 (long) edit_move_forward3 (edit, 1311 edit_buffer_get_bol (&edit->buffer, edit->mark1, TRUE), 1312 0, edit->mark1, FALSE, 0); 1205 1313 } 1206 1314 if (ac >= MARK_2 - 2 && ac < MARK_CURS - 2) 1207 1315 { 1208 1316 edit->mark2 = ac - MARK_2; 1209 1317 edit->column2 = 1210 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), 1211 0, edit->mark2); 1318 (long) edit_move_forward3 (edit, 1319 edit_buffer_get_bol (&edit->buffer, edit->mark2, TRUE), 1320 0, edit->mark2, FALSE, 0); 1212 1321 } 1213 1322 else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS) 1214 1323 { 1215 1324 edit->end_mark_curs = ac - MARK_CURS; 1216 1325 } 1217 if (count++) 1218 edit->force |= REDRAW_PAGE; /* more than one pop usually means something big */ 1326 edit->force |= REDRAW_PAGE; 1219 1327 } 1220 1328 1221 1329 if (edit->start_display > ac - KEY_PRESS) 1222 1330 { 1223 1331 edit->start_line -= 1224 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display );1332 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display, FALSE) - 1; 1225 1333 edit->force |= REDRAW_PAGE; 1226 1334 } 1227 1335 else if (edit->start_display < ac - KEY_PRESS) 1228 1336 { 1229 1337 edit->start_line += 1230 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS );1338 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS, FALSE) - 1; 1231 1339 edit->force |= REDRAW_PAGE; 1232 1340 } 1233 1341 edit->start_display = ac - KEY_PRESS; /* see push and pop above */ … … static void 1243 1351 edit_do_redo (WEdit * edit) 1244 1352 { 1245 1353 long ac; 1246 long count = 0;1247 1354 1248 1355 if (edit->redo_stack_reset) 1249 1356 return; … … edit_do_redo (WEdit * edit) 1285 1392 { 1286 1393 edit->mark1 = ac - MARK_1; 1287 1394 edit->column1 = 1288 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 1289 0, edit->mark1); 1395 (long) edit_move_forward3 (edit, 1396 edit_buffer_get_bol (&edit->buffer, edit->mark1, TRUE), 1397 0, edit->mark1, FALSE, 0); 1290 1398 } 1291 1399 else if (ac >= MARK_2 - 2 && ac < KEY_PRESS) 1292 1400 { 1293 1401 edit->mark2 = ac - MARK_2; 1294 1402 edit->column2 = 1295 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), 1296 0, edit->mark2); 1403 (long) edit_move_forward3 (edit, 1404 edit_buffer_get_bol (&edit->buffer, edit->mark2, TRUE), 1405 0, edit->mark2, FALSE, 0); 1297 1406 } 1298 /* more than one pop usually means something big */ 1299 if (count++) 1300 edit->force |= REDRAW_PAGE; 1407 edit->force |= REDRAW_PAGE; 1301 1408 } 1302 1409 1303 1410 if (edit->start_display > ac - KEY_PRESS) 1304 1411 { 1305 1412 edit->start_line -= 1306 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display );1413 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display, FALSE) - 1; 1307 1414 edit->force |= REDRAW_PAGE; 1308 1415 } 1309 1416 else if (edit->start_display < ac - KEY_PRESS) 1310 1417 { 1311 1418 edit->start_line += 1312 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS );1419 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS, FALSE) - 1; 1313 1420 edit->force |= REDRAW_PAGE; 1314 1421 } 1315 1422 edit->start_display = ac - KEY_PRESS; /* see push and pop above */ … … edit_auto_indent (WEdit * edit) 1404 1511 1405 1512 p = edit->buffer.curs1; 1406 1513 /* use the previous line as a template */ 1407 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1 );1514 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1, FALSE); 1408 1515 /* copy the leading whitespace of the line */ 1409 1516 while (TRUE) 1410 1517 { /* no range check - the line _is_ \n-terminated */ … … edit_move_block_to_right (WEdit * edit) 1604 1711 if (!eval_marks (edit, &start_mark, &end_mark)) 1605 1712 return; 1606 1713 1607 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark );1608 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1 );1714 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark, FALSE); 1715 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1, FALSE); 1609 1716 1610 1717 do 1611 1718 { … … edit_move_block_to_right (WEdit * edit) 1617 1724 else 1618 1725 edit_insert (edit, '\t'); 1619 1726 edit_cursor_move (edit, 1620 edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1); 1727 edit_buffer_get_bol (&edit->buffer, cur_bol, 1728 FALSE) - edit->buffer.curs1); 1621 1729 } 1622 1730 1623 1731 if (cur_bol == 0) 1624 1732 break; 1625 1733 1626 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1 );1734 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1, FALSE); 1627 1735 } 1628 1736 while (cur_bol >= start_bol); 1629 1737 … … edit_move_block_to_left (WEdit * edit) 1641 1749 if (!eval_marks (edit, &start_mark, &end_mark)) 1642 1750 return; 1643 1751 1644 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark );1645 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1 );1752 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark, FALSE); 1753 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1, FALSE); 1646 1754 1647 1755 do 1648 1756 { … … edit_move_block_to_left (WEdit * edit) 1671 1779 if (cur_bol == 0) 1672 1780 break; 1673 1781 1674 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1 );1782 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1, FALSE); 1675 1783 } 1676 1784 while (cur_bol >= start_bol); 1677 1785 … … edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * 1748 1856 } 1749 1857 } 1750 1858 1751 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1); 1859 edit_cursor_move (edit, 1860 edit_move_forward3 (edit, p, col, 0, FALSE, 1861 0) - edit->buffer.curs1); 1752 1862 1753 1863 for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) 1754 1864 edit_insert (edit, ' '); … … edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * 1769 1879 /*** public functions ****************************************************************************/ 1770 1880 /* --------------------------------------------------------------------------------------------- */ 1771 1881 1882 1883 void 1884 edit_apply_curs_exceptions (WEdit * e) 1885 { 1886 off_t bol_m2 = 1887 edit_buffer_get_bol (&e->buffer, e->buffer.curs1 + (e->buffer.curs1 - 2 >= 0 ? -2 : 0), 1888 TRUE); 1889 off_t bol = edit_buffer_get_bol (&e->buffer, e->buffer.curs1, TRUE); 1890 off_t boln = edit_buffer_get_bol (&e->buffer, e->buffer.curs1, FALSE); 1891 off_t eol = edit_buffer_get_eol (&e->buffer, e->buffer.curs1, TRUE); 1892 off_t curs1 = e->buffer.curs1, prev_curs1 = e->prev_curs1; 1893 long size = e->buffer.size, psize = e->prev_size; 1894 long cnt_m2 = edit_move_forward3 (e, bol_m2, 0, eol, FALSE, 0); 1895 long col = edit_move_forward3 (e, bol, 0, curs1, FALSE, 0); 1896 long end_col = e->end_col; 1897 edit_update_curs_row (e); 1898 1899 /* First one exception is turned on – the one 1900 * that increases cursor y position when at 1901 * first column and not at bol */ 1902 if (curs1 != boln && curs1 == bol && col == 0) 1903 { 1904 e->curs_row++; 1905 if (cnt_m2 <= end_col - 2) 1906 e->flag2 = 1; 1907 } 1908 1909 if (curs1 == bol && /*m.left */ curs1 < prev_curs1) 1910 e->flag2 = TRUE; 1911 1912 /* Remaining apply only for screen-long lines */ 1913 if (cnt_m2 <= end_col - 2) 1914 return; 1915 1916 /* The second exception – when moving at 1917 * col == 0 from a lower curs1 position (right), 1918 * meaning that it should be an end_col position 1919 */ 1920 if ( /*m.right */ curs1 == prev_curs1 + 1 && col == 0 && curs1 != boln 1921 && /*not flagged */ !e->flag) 1922 { 1923 if (psize + 1 != size) 1924 { 1925 e->flag = TRUE; 1926 e->curs_col = e->end_col; 1927 e->curs_row--; 1928 } 1929 e->flag2 = 0; 1930 } 1931 else if ( /*m.right */ curs1 == prev_curs1 + 1 && col == 1 && curs1 >= boln + 1 && 1932 /* flagged */ e->flag) 1933 { 1934 if (psize + 1 != size) 1935 { 1936 edit_cursor_move (e, -1); 1937 e->flag = FALSE; 1938 e->curs_col = 0; 1939 } 1940 e->flag2 = 1; 1941 } 1942 else if ( /*m.left */ curs1 == prev_curs1 - 1 && 1943 col == end_col - 1 && !e->flag) 1944 { 1945 if (psize != size + 1) 1946 { 1947 edit_cursor_move (e, 1); 1948 e->flag = TRUE; 1949 e->curs_col = end_col; 1950 } 1951 e->flag2 = 0; 1952 } 1953 else if (ABS (curs1 - prev_curs1) != 1 && col == 0 && curs1 != boln && !e->flag2) 1954 { 1955 e->curs_col = end_col; 1956 e->curs_row--; 1957 e->flag = TRUE; 1958 } 1959 else 1960 { 1961 e->flag = 0; 1962 } 1963 } 1964 1772 1965 /** User edit menu, like user menu (F2) but only in editor. */ 1773 1966 1774 1967 void … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2124 2317 edit_save_size (edit); 2125 2318 } 2126 2319 2320 if (edit->page_line_data == NULL) 2321 edit->page_line_data = g_ptr_array_new_full (LINES, g_free); 2322 g_ptr_array_set_size (edit->page_line_data, LINES); 2323 2127 2324 edit->drag_state = MCEDIT_DRAG_NONE; 2128 2325 2129 2326 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 2350 edit_set_codeset (edit); 2154 2351 #endif 2155 2352 2353 edit_set_end_column (edit); 2156 2354 if (!edit_load_file (edit)) 2157 2355 { 2158 2356 /* edit_load_file already gives an error message */ … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2179 2377 edit_move_to_line (edit, line - 1); 2180 2378 } 2181 2379 2380 2182 2381 edit_load_macro_cmd (edit); 2183 2382 2184 2383 return edit; … … edit_push_redo_action (WEdit * edit, long c) 2508 2707 edit->redo_stack_bottom = edit->redo_stack_pointer = 0; 2509 2708 } 2510 2709 2710 2711 /* --------------------------------------------------------------------------------------------- */ 2712 2511 2713 /* --------------------------------------------------------------------------------------------- */ 2512 2714 /** 2513 2715 Basic low level single character buffer alterations and movements at the cursor. … … edit_insert (WEdit * edit, int c) 2531 2733 /* now we must update some info on the file and check if a redraw is required */ 2532 2734 if (c == '\n') 2533 2735 { 2736 edit->buffer.line_begin_offset = edit->buffer.curs1; 2534 2737 book_mark_inc (edit, edit->buffer.curs_line); 2535 2738 edit->buffer.curs_line++; 2536 2739 edit->buffer.lines++; … … edit_backspace (WEdit * edit, gboolean byte_delete) 2724 2927 void 2725 2928 edit_cursor_move (WEdit * edit, off_t increment) 2726 2929 { 2930 gboolean scroll = FALSE; 2931 off_t idx; 2727 2932 if (increment < 0) 2728 2933 { 2729 for ( ; increment < 0 && edit->buffer.curs1 != 0; increment++)2934 for (idx = 0; idx > increment && edit->buffer.curs1 != 0; idx--) 2730 2935 { 2731 2936 int c; 2732 2937 … … edit_cursor_move (WEdit * edit, off_t increment) 2737 2942 c = edit_buffer_backspace (&edit->buffer); 2738 2943 if (c == '\n') 2739 2944 { 2945 edit->buffer.line_begin_offset = 0; 2946 for (int i = edit->buffer.curs1 - 1; i > 0; i--) 2947 { 2948 unsigned char ch = edit_buffer_get_byte (&edit->buffer, i); 2949 if (ch == '\n') 2950 { 2951 edit->buffer.line_begin_offset = i + 1; 2952 break; 2953 } 2954 } 2740 2955 edit->buffer.curs_line--; 2741 2956 edit->force |= REDRAW_LINE_BELOW; 2957 if (edit->buffer.curs_line < edit->start_line) 2958 scroll = TRUE; 2742 2959 } 2743 2960 } 2961 if (scroll) 2962 { 2963 edit_scroll_upward (edit, edit->start_line - edit->buffer.curs_line); 2964 } 2744 2965 } 2745 2966 else 2746 2967 { 2747 for ( ; increment > 0 && edit->buffer.curs2 != 0; increment--)2968 for (idx = 0; idx < increment && edit->buffer.curs2 != 0; idx++) 2748 2969 { 2749 2970 int c; 2750 2971 … … edit_cursor_move (WEdit * edit, off_t increment) 2755 2976 c = edit_buffer_delete (&edit->buffer); 2756 2977 if (c == '\n') 2757 2978 { 2979 edit->buffer.line_begin_offset = edit->buffer.curs1; 2758 2980 edit->buffer.curs_line++; 2981 if (edit->buffer.curs_line - edit->start_line >= soft_last_row) 2982 scroll = TRUE; 2759 2983 edit->force |= REDRAW_LINE_ABOVE; 2760 2984 } 2761 2985 } 2986 if (scroll) 2987 { 2988 edit_scroll_downward (edit, 2989 (edit->buffer.curs_line - edit->start_line) - soft_last_row); 2990 edit->force |= REDRAW_PAGE; 2991 } 2762 2992 } 2763 2993 } 2764 2994 … … edit_cursor_move (WEdit * edit, off_t increment) 2767 2997 /* If upto is zero returns index of cols across from current. */ 2768 2998 2769 2999 off_t 2770 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 3000 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto, gboolean as_bytes, 3001 off_t col_limit) 2771 3002 { 2772 3003 off_t p, q; 2773 long col; 3004 long col, col_acc = 0, btes = 0, prev_len = 0; 3005 int char_length = 1; 3006 int utf_ch; 2774 3007 2775 3008 if (upto != 0) 2776 3009 { … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2778 3011 cols = -10; 2779 3012 } 2780 3013 else 2781 q = edit->buffer.size + 2;3014 q = edit->buffer.size + 1; 2782 3015 2783 3016 for (col = 0, p = current; p < q; p++) 2784 3017 { … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2797 3030 #ifdef HAVE_CHARSET 2798 3031 if (edit->utf8) 2799 3032 { 2800 int utf_ch; 2801 int char_length = 1; 2802 3033 char_length = 1; 2803 3034 utf_ch = edit_buffer_get_utf (&edit->buffer, p, &char_length); 3035 2804 3036 if (mc_global.utf8_display) 2805 3037 { 2806 3038 if (char_length > 1) … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2816 3048 #endif 2817 3049 2818 3050 if (c == '\n') 2819 return (upto != 0 ? (off_t) col : p); 2820 if (c == '\t') 2821 col += TAB_SIZE - col % TAB_SIZE; 3051 { 3052 return (upto != 0 ? (off_t) (as_bytes ? btes : col - col_acc) : p); 3053 } 3054 3055 #ifdef HAVE_CHARSET 3056 if (edit->utf8) 3057 { 3058 btes += prev_len <= 1 ? char_length : 0; 3059 prev_len = prev_len <= 1 ? char_length : prev_len - 1; 3060 } 3061 else 3062 btes += 1; 3063 #else 3064 btes += 1; 3065 #endif 3066 3067 /* Treat tab specially, as it needs to use 3068 * whole line, not only screen line */ 3069 if (c == '\t' || utf_ch == '\t') 3070 { 3071 off_t boln = edit_buffer_get_bol (&edit->buffer, p, FALSE); 3072 off_t qq = boln, ncols = 0, acc = 0; 3073 int len = -1, ch; 3074 for (; len && qq <= p; 3075 (ch = edit_buffer_get_utf (&edit->buffer, qq, &len)), 3076 qq += len, ncols += 3077 (g_unichar_iswide (ch) > 0) + (ch == '\t' ? (TAB_SIZE - (ncols % TAB_SIZE)) : len > 3078 0)) 3079 { 3080 /* Still modulo the line length */ 3081 if ((ncols - acc) >= edit->end_col) 3082 acc += edit->end_col; 3083 } 3084 /* Apply precisely calculated cols */ 3085 col = ncols; 3086 if (boln != current) 3087 col -= acc; 3088 } 2822 3089 else if ((c < 32 || c == 127) && (orig_c == c 2823 3090 #ifdef HAVE_CHARSET 2824 3091 || (!mc_global.utf8_display && !edit->utf8) … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2829 3096 col += 2; 2830 3097 else 2831 3098 col++; 3099 3100 if (col_limit > 0) 3101 { 3102 btes = ((col - col_acc) >= col_limit) ? 0 : btes; 3103 col_acc += ((col - col_acc) >= col_limit) ? col_limit : 0; 3104 } 2832 3105 } 2833 return (off_t) col; 3106 3107 return (off_t) (as_bytes ? btes : col - col_acc); 2834 3108 } 2835 3109 2836 3110 /* --------------------------------------------------------------------------------------------- */ … … edit_get_cursor_offset (const WEdit * edit) 2843 3117 } 2844 3118 2845 3119 /* --------------------------------------------------------------------------------------------- */ 3120 2846 3121 /** returns the current column position of the cursor */ 2847 3122 2848 3123 long 2849 3124 edit_get_col (const WEdit * edit) 2850 3125 { 2851 return (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 2852 edit->buffer.curs1); 3126 gboolean screen = edit_options.soft_wrap ? 1 : 0; 3127 off_t bol = edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1, screen); 3128 3129 off_t col = (long) edit_move_forward3 (edit, bol, 0, edit->buffer.curs1, FALSE, 0); 3130 col -= -2 * edit->start_col; 3131 return col; 2853 3132 } 2854 3133 2855 3134 /* --------------------------------------------------------------------------------------------- */ … … edit_get_col (const WEdit * edit) 2857 3136 /* --------------------------------------------------------------------------------------------- */ 2858 3137 2859 3138 void 2860 edit_update_curs_row (WEdit * e dit)3139 edit_update_curs_row (WEdit * e) 2861 3140 { 2862 edit->curs_row = edit->buffer.curs_line - edit->start_line; 3141 /* Helper variables */ 3142 edit_buffer_t *buf = &e->buffer; 3143 off_t curs1 = edit_get_cursor_offset (e); 3144 3145 /* The screen-line count ↔ the cursor row */ 3146 int lines = edit_buffer_count_lines (buf, e->start_display, curs1, TRUE); 3147 /* Screen-line count should be 0-based */ 3148 e->curs_row = lines > 0 ? lines - 1 : 0; 3149 /* Non screen-lines line count */ 3150 e->array_row = edit_buffer_count_lines (buf, e->start_display, curs1, FALSE); 3151 /* Make the line count 0-based */ 3152 e->array_row > 0 ? e->array_row-- : 0; 2863 3153 } 2864 3154 2865 3155 /* --------------------------------------------------------------------------------------------- */ … … edit_update_curs_row (WEdit * edit) 2867 3157 void 2868 3158 edit_update_curs_col (WEdit * edit) 2869 3159 { 2870 edit->curs_col = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 2871 0, edit->buffer.curs1); 3160 edit->curs_col = edit_get_col (edit); 2872 3161 } 2873 3162 2874 3163 /* --------------------------------------------------------------------------------------------- */ … … edit_scroll_upward (WEdit * edit, long i) 2893 3182 { 2894 3183 edit->start_line -= i; 2895 3184 edit->start_display = 2896 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i );3185 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i, FALSE); 2897 3186 edit->force |= REDRAW_PAGE; 2898 3187 edit->force &= (0xfff - REDRAW_CHAR_ONLY); 2899 3188 } … … edit_scroll_downward (WEdit * edit, long i) 2908 3197 { 2909 3198 long lines_below; 2910 3199 2911 lines_below = edit->buffer.lines - edit->start_line - ( WIDGET (edit)->rect.lines- 1);3200 lines_below = edit->buffer.lines - edit->start_line - (soft_last_row - 1); 2912 3201 if (lines_below > 0) 2913 3202 { 2914 3203 if (i > lines_below) 2915 3204 i = lines_below; 2916 3205 edit->start_line += i; 2917 3206 edit->start_display = 2918 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0 );3207 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0, FALSE); 2919 3208 edit->force |= REDRAW_PAGE; 2920 3209 edit->force &= (0xfff - REDRAW_CHAR_ONLY); 2921 3210 } … … edit_move_to_prev_col (WEdit * edit, off_t p) 2958 3247 long over = edit->over_col; 2959 3248 2960 3249 edit_cursor_move (edit, 2961 edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1); 3250 edit_move_forward3 (edit, p, prev + edit->over_col, 0, FALSE, 3251 0) - edit->buffer.curs1); 2962 3252 2963 3253 if (edit_options.cursor_beyond_eol) 2964 3254 { 2965 3255 long line_len; 2966 3256 2967 3257 line_len = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 2968 edit_buffer_get_current_eol (&edit->buffer)); 3258 edit_buffer_get_current_eol (&edit->buffer), FALSE, 3259 FALSE); 2969 3260 if (line_len < prev + edit->over_col) 2970 3261 { 2971 3262 edit->over_col = prev + over - line_len; … … edit_move_to_prev_col (WEdit * edit, off_t p) 2998 3289 p = edit_buffer_get_current_bol (&edit->buffer); 2999 3290 edit_cursor_move (edit, 3000 3291 edit_move_forward3 (edit, p, edit->curs_col, 3001 0 ) - edit->buffer.curs1);3292 0, FALSE, FALSE) - edit->buffer.curs1); 3002 3293 if (!left_of_four_spaces (edit)) 3003 3294 edit_cursor_move (edit, 3004 edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1); 3295 edit_move_forward3 (edit, p, q, 0, FALSE, 3296 FALSE) - edit->buffer.curs1); 3005 3297 } 3006 3298 } 3007 3299 } … … void 3029 3321 edit_move_to_line (WEdit * e, long line) 3030 3322 { 3031 3323 if (line < e->buffer.curs_line) 3032 edit_move_up (e, e->buffer.curs_line - line, FALSE );3324 edit_move_up (e, e->buffer.curs_line - line, FALSE, FALSE); 3033 3325 else 3034 edit_move_down (e, line - e->buffer.curs_line, FALSE );3326 edit_move_down (e, line - e->buffer.curs_line, FALSE, FALSE); 3035 3327 edit_scroll_screen_over_cursor (e); 3036 3328 } 3037 3329 … … edit_execute_key_command (WEdit * edit, long command, int char_for_insertion) 3260 3552 void 3261 3553 edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3262 3554 { 3263 WRect *w = &WIDGET (edit)->rect;3264 3265 3555 if (command == CK_WindowFullscreen) 3266 3556 { 3267 3557 edit_toggle_fullscreen (edit); … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3353 3643 /* An ordinary key press */ 3354 3644 if (char_for_insertion >= 0) 3355 3645 { 3646 off_t prev_curs_col, col; 3647 3648 if (edit->curs_col == 0) 3649 edit->force |= REDRAW_AFTER_CURSOR; 3650 prev_curs_col = edit->curs_col; 3651 3356 3652 /* if non persistent selection and text selected */ 3357 3653 if (!edit_options.persistent_selections && edit->mark1 != edit->mark2) 3358 3654 edit_block_delete_cmd (edit); … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3408 3704 edit->force |= REDRAW_PAGE; 3409 3705 } 3410 3706 else 3707 { 3411 3708 check_and_wrap_line (edit); 3709 edit->force |= REDRAW_AFTER_CURSOR; 3710 } 3711 col = edit_get_col (edit); 3712 if (prev_curs_col == edit->buffer.end_col - 1 && col == 0) 3713 edit->force |= REDRAW_AFTER_CURSOR; 3412 3714 edit->found_len = 0; 3413 3715 edit->prev_col = edit_get_col (edit); 3414 3716 edit->search_start = edit->buffer.curs1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3467 3769 case CK_Right: 3468 3770 case CK_MarkLeft: 3469 3771 case CK_MarkRight: 3470 edit->force |= REDRAW_ CHAR_ONLY;3772 edit->force |= REDRAW_LINE; 3471 3773 break; 3472 3774 default: 3473 3775 break; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3497 3799 } 3498 3800 else 3499 3801 edit_backspace (edit, FALSE); 3802 3803 edit->force |= REDRAW_AFTER_CURSOR; 3500 3804 break; 3501 3805 case CK_Delete: 3502 3806 /* if non persistent selection and text selected */ … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3563 3867 MC_FALLTHROUGH; 3564 3868 case CK_PageUp: 3565 3869 case CK_MarkPageUp: 3566 edit_move_up (edit, w->lines - 1, TRUE);3870 edit_move_up (edit, soft_last_row, TRUE, FALSE); 3567 3871 break; 3568 3872 case CK_MarkColumnPageDown: 3569 3873 edit->column_highlight = 1; 3570 3874 MC_FALLTHROUGH; 3571 3875 case CK_PageDown: 3572 3876 case CK_MarkPageDown: 3573 edit_move_down (edit, w->lines - 1, TRUE);3877 edit_move_down (edit, soft_last_row, TRUE, FALSE); 3574 3878 break; 3575 3879 case CK_MarkColumnLeft: 3576 3880 edit->column_highlight = 1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3626 3930 MC_FALLTHROUGH; 3627 3931 case CK_Up: 3628 3932 case CK_MarkUp: 3629 edit_move_up (edit, 1, FALSE );3933 edit_move_up (edit, 1, FALSE, TRUE); 3630 3934 break; 3631 3935 case CK_MarkColumnDown: 3632 3936 edit->column_highlight = 1; 3633 3937 MC_FALLTHROUGH; 3634 3938 case CK_Down: 3635 3939 case CK_MarkDown: 3636 edit_move_down (edit, 1, FALSE );3940 edit_move_down (edit, 1, FALSE, TRUE); 3637 3941 break; 3638 3942 case CK_MarkColumnParagraphUp: 3639 3943 edit->column_highlight = 1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3654 3958 MC_FALLTHROUGH; 3655 3959 case CK_ScrollUp: 3656 3960 case CK_MarkScrollUp: 3657 edit_move_up (edit, 1, TRUE );3961 edit_move_up (edit, 1, TRUE, TRUE); 3658 3962 break; 3659 3963 case CK_MarkColumnScrollDown: 3660 3964 edit->column_highlight = 1; 3661 3965 MC_FALLTHROUGH; 3662 3966 case CK_ScrollDown: 3663 3967 case CK_MarkScrollDown: 3664 edit_move_down (edit, 1, TRUE );3968 edit_move_down (edit, 1, TRUE, TRUE); 3665 3969 break; 3666 3970 case CK_Home: 3667 3971 case CK_MarkToHome: 3668 edit_cursor_to_bol (edit );3972 edit_cursor_to_bol (edit, TRUE); 3669 3973 break; 3670 3974 case CK_End: 3671 3975 case CK_MarkToEnd: 3672 edit_cursor_to_eol (edit );3976 edit_cursor_to_eol (edit, TRUE); 3673 3977 break; 3674 3978 case CK_Tab: 3675 3979 /* if text marked shift block */ … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3757 4061 if (p->next != NULL) 3758 4062 { 3759 4063 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);4064 if (p->line >= edit->start_line + soft_last_row + 1 || p->line < edit->start_line) 4065 edit_move_display (edit, p->line - (soft_last_row + 1) / 2); 3762 4066 edit_move_to_line (edit, p->line); 3763 4067 } 3764 4068 } … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3774 4078 p = p->prev; 3775 4079 if (p->line >= 0) 3776 4080 { 3777 if (p->line >= edit->start_line + w->lines|| p->line < edit->start_line)3778 edit_move_display (edit, p->line - w->lines/ 2);4081 if (p->line >= edit->start_line + soft_last_row + 1 || p->line < edit->start_line) 4082 edit_move_display (edit, p->line - (soft_last_row + 1) / 2); 3779 4083 edit_move_to_line (edit, p->line); 3780 4084 } 3781 4085 } 3782 4086 break; 3783 4087 4088 case CK_SoftFolds: 4089 edit_options.soft_wrap = !edit_options.soft_wrap; 4090 edit->start_col *= !edit_options.soft_wrap; 4091 edit->force |= REDRAW_COMPLETELY; 4092 break; 4093 3784 4094 case CK_Top: 3785 4095 case CK_MarkToFileBegin: 3786 4096 edit_move_to_top (edit); … … edit_stack_free (void) 4050 4360 /** move i lines */ 4051 4361 4052 4362 void 4053 edit_move_up (WEdit * edit, long i, gboolean do_scroll )4363 edit_move_up (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines) 4054 4364 { 4055 edit_move_updown (edit, i, do_scroll, TRUE); 4365 screen_lines &= edit_options.soft_wrap; 4366 edit_move_updown (edit, i, do_scroll, TRUE, screen_lines); 4056 4367 } 4057 4368 4058 4369 /* --------------------------------------------------------------------------------------------- */ 4059 4370 /** move i lines */ 4060 4371 4061 4372 void 4062 edit_move_down (WEdit * edit, long i, gboolean do_scroll )4373 edit_move_down (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines) 4063 4374 { 4064 edit_move_updown (edit, i, do_scroll, FALSE); 4375 screen_lines &= edit_options.soft_wrap; 4376 edit_move_updown (edit, i, do_scroll, FALSE, screen_lines); 4065 4377 } 4066 4378 4067 4379 /* --------------------------------------------------------------------------------------------- */ -
src/editor/edit.h
diff --git a/src/editor/edit.h b/src/editor/edit.h index 358aa3f14..521591829 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..f1f718b82 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 142 edit_buffer_count_tabs (edit_buffer_t * buf, off_t first, off_t last, gboolean all_kinds) 143 { 144 int cnt = 0; 145 last = last > buf->size ? buf->size : last; 146 while (first <= last) 147 { 148 int byte = edit_buffer_get_byte (buf, first); 149 if (byte == '\t' || (all_kinds && byte == '\v')) 150 cnt++; 151 ++first; 152 } 153 return cnt; 154 } 155 139 156 /* --------------------------------------------------------------------------------------------- */ 140 157 /** 141 158 * Initialize editor buffers. … … edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) 144 161 */ 145 162 146 163 void 147 edit_buffer_init ( edit_buffer_t * buf, off_t size)164 edit_buffer_init (WEdit * e, edit_buffer_t * buf, off_t size) 148 165 { 149 166 buf->b1 = g_ptr_array_new_full (32, g_free); 150 167 buf->b2 = g_ptr_array_new_full (32, g_free); 168 buf->edit_widget = e; 169 buf->end_col = 73; 151 170 152 171 buf->curs1 = 0; 153 172 buf->curs2 = 0; … … void 167 186 edit_buffer_clean (edit_buffer_t * buf) 168 187 { 169 188 if (buf->b1 != NULL) 189 { 170 190 g_ptr_array_free (buf->b1, TRUE); 191 } 171 192 172 193 if (buf->b2 != NULL) 194 { 173 195 g_ptr_array_free (buf->b2, TRUE); 196 } 174 197 } 175 198 176 199 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_clean (edit_buffer_t * buf) 182 205 * 183 206 * @return '\n' if byte_index is negative or larger than file size; byte at byte_index otherwise. 184 207 */ 208 int 209 edit_buffer_get_byte_ex (const edit_buffer_t * buf, off_t byte_index) 210 { 211 char *p; 212 213 p = edit_buffer_get_byte_ptr (buf, byte_index); 214 215 return (p != NULL) ? *(unsigned char *) p : -1; 216 } 185 217 186 218 int 187 219 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 355 */ 324 356 325 357 long 326 edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last )358 edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last, gboolean screen_lines) 327 359 { 328 long lines = 0; 360 long lines = 0, prev_eol = 0, eol; 361 screen_lines &= edit_options.soft_wrap; 329 362 330 363 first = MAX (first, 0); 331 364 last = MIN (last, buf->size); 332 365 333 while (first < last) 334 if (edit_buffer_get_byte (buf, first++) == '\n') 335 lines++; 366 if (first == last) 367 return 0; 336 368 369 while (first <= last) 370 { 371 eol = edit_buffer_get_eol (buf, first, screen_lines); 372 /* Advance in buffer */ 373 if (edit_buffer_get_byte_ex (buf, eol) == '\n' || ~screen_lines || eol == prev_eol) 374 first = eol + 1; 375 else 376 first = eol; 377 prev_eol = eol; 378 /* Count line */ 379 lines++; 380 } 337 381 return lines; 338 382 } 339 383 … … edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last) 348 392 */ 349 393 350 394 off_t 351 edit_buffer_get_bol (const edit_buffer_t * buf, off_t current )395 edit_buffer_get_bol (const edit_buffer_t * buf, off_t current_bol, gboolean screen_lines) 352 396 { 353 if (current <= 0) 397 off_t current_save = current_bol; 398 off_t current_eol = current_bol; 399 screen_lines &= edit_options.soft_wrap; 400 if (current_bol <= 0) 401 { 354 402 return 0; 355 356 for (; edit_buffer_get_byte (buf, current - 1) != '\n'; current--)403 } 404 for (; current_bol > 0 && edit_buffer_get_byte (buf, current_bol - 1) != '\n'; current_bol -= 1) 357 405 ; 358 406 359 return current; 407 for (; 408 (edit_buffer_get_byte (buf, current_eol) != '\n' || current_save == current_eol) 409 && current_eol < buf->size; current_eol += 1); 410 411 412 if (screen_lines) 413 { 414 off_t pos = current_save - 415 edit_move_forward3 (buf->edit_widget, current_bol, 0, current_save, TRUE, buf->end_col); 416 return pos; 417 } 418 return current_bol; 360 419 } 361 420 362 421 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_get_bol (const edit_buffer_t * buf, off_t current) 370 429 */ 371 430 372 431 off_t 373 edit_buffer_get_eol (const edit_buffer_t * buf, off_t current )432 edit_buffer_get_eol (const edit_buffer_t * buf, off_t current_eol, gboolean screen_lines) 374 433 { 375 if (current >= buf->size) 434 off_t current_save = current_eol; 435 off_t current_bol = current_eol; 436 off_t q; 437 screen_lines &= edit_options.soft_wrap; 438 if (current_eol >= buf->size) 376 439 return buf->size; 377 440 378 for (; edit_buffer_get_byte (buf, current) != '\n'; current++)441 for (; current_bol > 0 && edit_buffer_get_byte (buf, current_bol - 1) != '\n'; current_bol--) 379 442 ; 380 443 381 return current; 444 if (screen_lines) 445 { 446 off_t prev_eol = 0; 447 for (; 448 (edit_buffer_get_byte_ex (buf, current_eol) != '\n') && 449 current_eol <= buf->size && 450 (current_eol == current_save 451 || 452 ((q = 453 edit_move_forward3 (buf->edit_widget, current_bol, 0, current_eol, FALSE, 454 0) % buf->end_col) != 0)); 455 current_eol = 456 edit_move_forward3 (buf->edit_widget, current_eol, 1, 0, FALSE, 0), current_eol += 457 prev_eol == current_eol ? 1 : 0, prev_eol = current_eol) 458 ; 459 if (current_eol > buf->size && edit_buffer_get_byte_ex (buf, current_eol) != '\n') 460 current_eol = buf->size; 461 } 462 else 463 for (; (edit_buffer_get_byte (buf, current_eol) != '\n') && current_eol < buf->size; 464 current_eol++) 465 ; 466 467 468 return current_eol; 382 469 } 383 470 384 471 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_backspace (edit_buffer_t * buf) 638 725 */ 639 726 640 727 off_t 641 edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, off_t upto) 728 edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, off_t upto, 729 gboolean screen_lines) 642 730 { 731 screen_lines &= edit_options.soft_wrap; 643 732 if (upto != 0) 644 return (off_t) edit_buffer_count_lines (buf, current, upto );733 return (off_t) edit_buffer_count_lines (buf, current, upto, screen_lines); 645 734 646 735 lines = MAX (lines, 0); 647 736 737 if (lines > 0) 738 { 739 edit_update_curs_col (buf->edit_widget); 740 if (buf->edit_widget->curs_col == buf->end_col) 741 lines--; 742 } 743 648 744 while (lines-- != 0) 649 745 { 650 long next; 746 off_t next; 747 int byte; 651 748 652 next = edit_buffer_get_eol (buf, current) + 1; 653 if (next > buf->size) 749 next = edit_buffer_get_eol (buf, current, screen_lines); 750 byte = edit_buffer_get_byte_ex (buf, next); 751 752 if (byte == '\n' || !screen_lines) 753 next++; 754 if (next > buf->size + 1) 654 755 break; 655 756 current = next; 656 757 } 657 658 758 return current; 659 759 } 660 760 … … edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long l 670 770 */ 671 771 672 772 off_t 673 edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines) 773 edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines, 774 gboolean screen_lines) 674 775 { 776 screen_lines &= edit_options.soft_wrap; 675 777 lines = MAX (lines, 0); 676 current = edit_buffer_get_bol (buf, current );778 current = edit_buffer_get_bol (buf, current, screen_lines); 677 779 678 780 while (lines-- != 0 && current != 0) 679 current = edit_buffer_get_bol (buf, current - 1); 781 { 782 current = edit_buffer_get_bol (buf, current - 1, screen_lines); 783 if (screen_lines && current > 0 && 784 edit_buffer_get_byte_ex (buf, current) == '\n' && 785 edit_buffer_get_byte_ex (buf, current - 1) != '\n') 786 lines++; 787 } 788 789 if (current > 0 && screen_lines && edit_buffer_get_byte_ex (buf, current - 1) != '\n') 790 current = edit_buffer_get_eol (buf, current - 1, screen_lines); 680 791 681 792 return current; 682 793 } -
src/editor/editbuffer.h
diff --git a/src/editor/editbuffer.h b/src/editor/editbuffer.h index def17eec5..00f094e81 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, 52 gboolean screen_lines); 53 off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current, gboolean screen_lines); 54 off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current, gboolean screen_lines); 49 55 GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start, 50 56 gsize * cut); 51 57 gboolean edit_buffer_find_word_start (const edit_buffer_t * buf, off_t * word_start, … … int edit_buffer_delete (edit_buffer_t * buf); 57 63 int edit_buffer_backspace (edit_buffer_t * buf); 58 64 59 65 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); 66 off_t upto, gboolean screen_lines); 67 off_t edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines, 68 gboolean screen_lines); 62 69 63 70 off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size, 64 71 edit_buffer_read_file_status_msg_t * sm, gboolean * aborted); … … edit_buffer_get_previous_byte (const edit_buffer_t * buf) 94 101 static inline off_t 95 102 edit_buffer_get_current_bol (const edit_buffer_t * buf) 96 103 { 97 return edit_buffer_get_bol (buf, buf->curs1 );104 return edit_buffer_get_bol (buf, buf->curs1, FALSE); 98 105 } 99 106 100 107 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_get_current_bol (const edit_buffer_t * buf) 109 116 static inline off_t 110 117 edit_buffer_get_current_eol (const edit_buffer_t * buf) 111 118 { 112 return edit_buffer_get_eol (buf, buf->curs1 );119 return edit_buffer_get_eol (buf, buf->curs1, FALSE); 113 120 } 114 121 115 122 /* --------------------------------------------------------------------------------------------- */ -
src/editor/editcmd.c
diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index de624f249..e29c20671 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, 472 FALSE, 0); 473 d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2, TRUE), 0, m2, 474 FALSE, 0); 473 475 b = MAX (MIN (c, d), MIN (edit->column1, edit->column2)); 474 476 c = MAX (c, MAX (edit->column1, edit->column2)); 475 477 … … edit_delete_column_of_text (WEdit * edit) 478 480 off_t r, p, q; 479 481 480 482 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 );483 p = edit_move_forward3 (edit, r, b, 0, FALSE, 0); 484 q = edit_move_forward3 (edit, r, c, 0, FALSE, 0); 483 485 p = MAX (p, m1); 484 486 q = MIN (q, m2); 485 487 edit_cursor_move (edit, p - edit->buffer.curs1); … … edit_delete_column_of_text (WEdit * edit) 492 494 if (n != 0) 493 495 edit_cursor_move (edit, 494 496 edit_buffer_get_forward_offset (&edit->buffer, edit->buffer.curs1, 1, 495 0 ) - edit->buffer.curs1);497 0, FALSE) - edit->buffer.curs1); 496 498 } 497 499 } 498 500 … … edit_block_delete (WEdit * edit) 547 549 edit_move_to_line (edit, curs_line); 548 550 /* calculate line width and cursor position before cut */ 549 551 line_width = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 550 edit_buffer_get_current_eol (&edit->buffer)); 552 edit_buffer_get_current_eol (&edit->buffer), FALSE, 553 FALSE); 551 554 if (edit_options.cursor_beyond_eol && curs_pos > line_width) 552 555 edit->over_col = curs_pos - line_width; 553 556 } … … edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l) 586 589 int c; 587 590 off_t x; 588 591 589 x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start), 0, start); 592 x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start, TRUE), 0, 593 start, FALSE, 0); 590 594 c = edit_buffer_get_byte (&edit->buffer, start); 591 595 if ((x >= edit->column1 && x < edit->column2) 592 596 || (x >= edit->column2 && x < edit->column1) || c == '\n') … … edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long 699 703 break; 700 704 } 701 705 } 702 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1); 706 edit_cursor_move (edit, 707 edit_move_forward3 (edit, p, col, 0, FALSE, 708 FALSE) - edit->buffer.curs1); 703 709 704 710 for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) 705 711 edit_insert (edit, ' '); … … eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark) 1300 1306 long col1, col2; 1301 1307 off_t diff1, diff2; 1302 1308 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 );1309 start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark, FALSE); 1310 start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1, FALSE) + 1; 1311 end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark, FALSE); 1312 end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark, FALSE); 1307 1313 col1 = MIN (edit->column1, edit->column2); 1308 1314 col2 = MAX (edit->column1, edit->column2); 1309 1315 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 );1316 diff1 = edit_move_forward3 (edit, start_bol, col2, 0, FALSE, 0) - 1317 edit_move_forward3 (edit, start_bol, col1, 0, FALSE, 0); 1318 diff2 = edit_move_forward3 (edit, end_bol, col2, 0, FALSE, 0) - 1319 edit_move_forward3 (edit, end_bol, col1, 0, FALSE, 0); 1314 1320 1315 1321 *start_mark -= diff1; 1316 1322 *end_mark += diff2; … … edit_block_move_cmd (WEdit * edit) 1409 1415 x2 = x + edit->over_col; 1410 1416 1411 1417 /* 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)1418 if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1, FALSE) == 1419 edit_buffer_get_eol (&edit->buffer, start_mark, FALSE)) && x2 > c1 && x2 <= c2) 1414 1420 return; 1415 1421 1416 1422 if (edit->buffer.curs1 > start_mark 1417 && edit->buffer.curs1 < edit_buffer_get_eol (&edit->buffer, end_mark ))1423 && edit->buffer.curs1 < edit_buffer_get_eol (&edit->buffer, end_mark, FALSE)) 1418 1424 { 1419 1425 if (x > c2) 1420 1426 x -= b_width; … … edit_block_move_cmd (WEdit * edit) 1429 1435 1430 1436 edit->over_col = MAX (0, edit->over_col - b_width); 1431 1437 /* calculate the cursor pos after delete block */ 1432 current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0); 1438 current = 1439 edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0, FALSE, 0); 1433 1440 edit_cursor_move (edit, current - edit->buffer.curs1); 1434 1441 edit_scroll_screen_over_cursor (edit); 1435 1442 -
src/editor/editdraw.c
diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index fbd1e095f..3067eee3f 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 *edit_prepare_this_line (WEdit * edit, off_t b, long order_idx, long row, 112 long start_col, long end_col, long soft_last_row, 113 gboolean draw, long base_line); 114 115 gboolean refresh_line_data (WEdit * edit, GPtrArray * page_line_data, long start_column, 116 long end_column, long end_row); 117 118 gboolean 119 refresh_line_data (WEdit * edit, GPtrArray * page_line_data, long start_column, long end_column, 120 long end_row) 121 { 122 MCELineData *prev_ldata, *line_data; 123 gboolean ret = FALSE; 124 long base_line, row, start_row = 0; 125 int prev_plines = 0; 126 127 base_line = edit_buffer_count_lines (&edit->buffer, 0, edit->start_display, FALSE); 128 off_t b = 129 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0, FALSE); 130 for (row = start_row; row < end_row; row++) 131 { 132 int pplines_add = 0; 133 if (!edit_options.soft_wrap) 134 pplines_add = -prev_plines; 135 line_data = edit_prepare_this_line (edit, b, row, row + prev_plines + pplines_add, 136 start_column, end_column, -1, FALSE, base_line); 137 line_data->plines_count += pplines_add; 138 prev_ldata = (MCELineData *) page_line_data->pdata[row]; 139 if (prev_ldata == NULL || prev_ldata->plines_count != line_data->plines_count) 140 /* Return true if any plines changed */ 141 ret = TRUE; 142 page_line_data->pdata[row] = line_data; 143 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 144 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 145 } 146 return ret; 147 } 148 149 int 150 sum_plines_to_row_full (GPtrArray * page_line_data, int row, gboolean count_only_second_etc_lines) 151 { 152 int prev_plines = 0; 153 154 if (!edit_options.soft_wrap) 155 return prev_plines; 156 157 for (int idx = 0; idx < row && idx < (long) page_line_data->len; idx++) 158 { 159 MCELineData *line_data = page_line_data->pdata[idx]; 160 if (line_data != NULL) 161 prev_plines += 162 (line_data->plines_count > 163 0) ? line_data->plines_count - (count_only_second_etc_lines ? 1 : 0) : 0; 164 else 165 prev_plines += count_only_second_etc_lines ? 0 : 1; 166 } 167 return prev_plines; 168 } 169 91 170 static inline void 92 171 printwstr (const char *s, int len) 93 172 { … … status_string (WEdit * edit, char *s, int w) 136 215 } 137 216 138 217 /* The field lengths just prevent the status line from shortening too much */ 218 off_t bol = edit_buffer_get_current_bol (&edit->buffer); 219 off_t col = edit_move_forward3 (edit, bol, 0, 220 edit->buffer.curs1, FALSE, 0); 139 221 if (edit_options.simple_statusbar) 140 222 g_snprintf (s, w, 141 223 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s", … … status_string (WEdit * edit, char *s, int w) 143 225 edit->modified ? 'M' : '-', 144 226 macro_index < 0 ? '-' : 'R', 145 227 edit->overwrite == 0 ? '-' : 'O', 146 edit->curs_col + edit->over_col,228 col, 147 229 edit->buffer.curs_line + 1, 148 230 edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, 149 231 byte_str, … … status_string (WEdit * edit, char *s, int w) 158 240 edit->modified ? 'M' : '-', 159 241 macro_index < 0 ? '-' : 'R', 160 242 edit->overwrite == 0 ? '-' : 'O', 161 edit->curs_col + edit->over_col,243 col, 162 244 edit->start_line + 1, 163 245 edit->curs_row, 164 246 edit->buffer.curs_line + 1, … … edit_status_fullscreen (WEdit * edit, int color) 185 267 const int w = h->rect.cols; 186 268 const int gap = 3; /* between the filename and the status */ 187 269 const int right_gap = 5; /* at the right end of the screen */ 188 const int preferred_fname_len = 1 6;270 const int preferred_fname_len = 14; 189 271 char *status; 190 272 size_t status_size; 191 273 int status_len; … … edit_draw_window_icons (const WEdit * edit, int color) 377 459 /* --------------------------------------------------------------------------------------------- */ 378 460 379 461 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) 462 print_to_widget (WEdit * edit, MCELineData * line_data) 382 463 { 464 int linesize = line_data->size; 465 long row = edit_options.soft_wrap ? line_data->row : line_data->scr_index; 466 int q = line_data->q; 467 int start_col_real = line_data->start_col_real; 468 long ec = line_data->ec, idx; 469 line *line_ = line_data->ldata; 470 char *status = line_data->status; 471 int bookmarked = line_data->bookmarked; 472 383 473 Widget *w = WIDGET (edit); 384 line _s*p;474 line *p; 385 475 int x, x1, y, cols_to_skip; 386 int i ;387 int wrap_start;476 int i, yp; 477 int f_start; 388 478 int len; 389 479 480 if (row < line_data->row) 481 { 482 row = line_data->row; 483 } 390 484 x = start_col_real; 391 x1 = start_col+ EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;485 x1 = q + EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 392 486 y = row + EDIT_TEXT_VERTICAL_OFFSET; 393 487 cols_to_skip = abs (x); 394 488 … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 398 492 y++; 399 493 } 400 494 401 tty_setcolor (EDITOR_NORMAL_COLOR); 402 if (bookmarked != 0) 403 tty_setcolor (bookmarked); 495 len = ec + 1 - q; 496 f_start = edit_options.word_wrap_line_length + edit->start_col; 404 497 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) 498 for (idx = 0; idx < line_data->plines_count || idx == 0; idx++) 409 499 { 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) 500 if (len > 0 && w->rect.y + y >= 0) 413 501 { 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); 502 if (!edit_options.show_right_margin || f_start > ec) 503 { 504 tty_setcolor (EDITOR_NORMAL_COLOR); 505 if (bookmarked != 0) 506 tty_setcolor (bookmarked); 421 507 422 len -= wrap_start; 423 if (len > 0) 508 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', len); 509 } 510 else if (f_start < 0) 424 511 { 425 512 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 426 tty_draw_hline (w->rect.y + y, w->rect.x + x1 + wrap_start, ' ', len); 513 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', len); 514 } 515 else 516 { 517 if (f_start > 0) 518 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', f_start); 519 520 len -= f_start; 521 if (len > 0) 522 { 523 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 524 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1 + f_start, ' ', len); 525 } 526 } 527 } 528 } 529 if (edit_options.line_state) 530 { 531 tty_setcolor (LINE_STATE_COLOR); 532 for (yp = 0; (edit_options.soft_wrap && yp <= linesize / ec + 533 (linesize % ec != 0 ? 0 : -1) + 534 (linesize == 0 ? 1 : 0)) || (!edit_options.soft_wrap && yp < 1); ++yp) 535 { 536 for (i = 0; i < LINE_STATE_WIDTH; i++) 537 { 538 edit_move (x1 + i - edit_options.line_state_width, y + yp); 539 if (yp == 0) 540 { 541 if (status[i] == '\0') 542 status[i] = ' '; 543 tty_print_char (status[i]); 544 } 545 else 546 tty_print_char (' '); 427 547 } 428 548 } 429 549 } 430 550 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 } 551 edit->end_col = ec; 552 edit->buffer.end_col = ec; 443 553 444 554 edit_move (x1, y); 445 555 446 556 i = 1; 447 for (p = line; p->ch != 0; p++) 557 for (idx = 0, p = &line_[-edit->start_col]; 558 (edit_options.soft_wrap && linesize-- > 0) || (!edit_options.soft_wrap 559 && (linesize-- + edit->start_col > 0) 560 && p->ch != 0); p++, idx++) 448 561 { 562 449 563 int style; 450 564 unsigned int textchar; 451 565 int color; 452 453 if (cols_to_skip != 0) 566 if (!edit_options.soft_wrap && cols_to_skip != 0) 454 567 { 455 568 cols_to_skip--; 456 569 continue; 457 570 } 458 571 572 /* Position each physical line */ 573 if (edit_options.soft_wrap && idx % ec == 0) 574 edit_move (x1, y++); 575 459 576 style = p->style & 0xFF00; 460 577 textchar = p->ch; 461 578 /* If non-printable - use black background */ … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 482 599 { 483 600 if (i > edit_options.word_wrap_line_length + edit->start_col) 484 601 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 485 i++;486 602 } 603 i++; 487 604 488 605 tty_print_anychar (textchar); 489 606 } … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 492 609 /* --------------------------------------------------------------------------------------------- */ 493 610 /** b is a pointer to the beginning of the line */ 494 611 495 static void 496 edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col) 612 static MCELineData * 613 edit_prepare_this_line (WEdit * edit, off_t b, long order_idx, long row, long start_col, 614 long end_col, long soft_last_row_idx, gboolean draw, long base_line) 497 615 { 616 long line_count, cur_line, prev_line; 617 MCELineData *line_data; 498 618 Widget *w = WIDGET (edit); 499 line_s line[MAX_LINE_LEN]; 500 line_s *p = line; 619 line *p; 501 620 off_t q; 502 int col, start_col_real; 621 int wrap_line_len, line_size, start_col_real = 0; 622 int col; 623 int color; 503 624 int abn_style; 504 625 int book_mark = 0; 505 char line_stat[LINE_STATE_WIDTH + 1] = "\0";506 626 507 if (row > w->rect.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1)) 508 return; 627 q = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 628 line_size = edit_move_forward3 (edit, b, 0, q, FALSE, 0); 629 line_data = (MCELineData *) g_malloc0 (sizeof (MCELineData) + sizeof (line) * 630 (line_size + /* sentinel —→ */ 1 + 631 edit_buffer_count_tabs (&edit->buffer, b, q, 632 FALSE) * 8)); 633 p = line_data->ldata; 509 634 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; 635 /* Helper var */ 636 if (edit_options.soft_wrap) 637 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 517 638 else 518 abn_style = MOD_ABNORMAL;639 wrap_line_len = abs (edit_options.word_wrap_line_length); 519 640 520 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;521 641 if (!edit->fullscreen) 522 642 { 523 643 end_col--; 524 644 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols) 525 645 end_col--; 526 646 } 647 wrap_line_len = end_col; 527 648 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; 649 line_count = edit_buffer_count_lines (&edit->buffer, edit->start_display, q - 1, FALSE); 650 line_count += base_line + (line_count > 0 ? -1 : 0); 651 652 line_data->soft_last_row = soft_last_row_idx; 653 line_data->row = row; 654 line_data->plines_count = line_size / wrap_line_len + ((line_size % wrap_line_len) ? 1 : 0); 655 if (!edit_options.soft_wrap) 656 line_data->plines_count = 0; 657 line_data->index = line_count + (line_count > 0 ? -1 : 0); 658 line_data->scr_index = line_data->index - edit->start_line; 659 line_data->order_idx = order_idx; /* for investigation */ 660 line_data->size = line_size; 661 line_data->q = !edit_options.soft_wrap ? edit->start_col : 0; 662 line_data->ec = end_col; 663 line_data->visible = (order_idx <= line_data->soft_last_row); 664 665 if (!edit_options.soft_wrap) 666 line_data->plines_count = 0; 667 668 if (book_mark_query_color (edit, line_data->index, BOOK_MARK_COLOR)) 669 book_mark = BOOK_MARK_COLOR; 670 else if (book_mark_query_color (edit, line_data->index, BOOK_MARK_FOUND_COLOR)) 671 book_mark = BOOK_MARK_FOUND_COLOR; 672 673 line_data->bookmarked = book_mark; 674 675 if (book_mark != 0) 676 abn_style = book_mark << 16; 677 else 678 abn_style = MOD_ABNORMAL; 679 if (!edit_options.soft_wrap) 680 { 681 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 682 if (!edit->fullscreen) 683 { 684 end_col--; 685 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols) 686 end_col--; 687 } 688 } 689 690 color = edit_get_syntax_color (edit, b - 1); 691 if (edit_options.soft_wrap) 692 { 693 q = b; 694 col = (int) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 695 } 696 else 697 { 698 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0, FALSE, 0); 699 col = (int) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 700 line_data->start_col_real = start_col_real = col + edit->start_col; 701 } 531 702 532 703 if (edit_options.line_state) 533 704 { 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); 705 int line_cnt = 0; 706 cur_line = line_data->index; 707 if (line_data->order_idx == line_data->scr_index || cur_line + 1 < line_cnt) 708 g_snprintf (line_data->status, sizeof (line_data->status), "%7li ", cur_line + 1); 539 709 else 540 710 { 541 memset (line_ stat, ' ', LINE_STATE_WIDTH);542 line_ stat[LINE_STATE_WIDTH] = '\0';711 memset (line_data->status, ' ', LINE_STATE_WIDTH); 712 line_data->status[LINE_STATE_WIDTH] = '\0'; 543 713 } 544 714 prev_line = cur_line + 1; 545 715 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR)) 546 g_snprintf (line_ stat, 2, "*");716 g_snprintf (line_data->status, 2, "*"); 547 717 } 548 718 549 719 if (col <= -(edit->start_col + 16)) … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 553 723 off_t m1 = 0, m2 = 0; 554 724 555 725 eval_marks (edit, &m1, &m2); 556 557 if (row <= edit->buffer.lines - edit->start_line) 726 if (order_idx <= edit->buffer.lines - edit->start_line) 558 727 { 559 728 off_t tws = 0; 560 729 561 if ( edit_options.visible_tws && tty_use_colors ())562 for (tws = edit_buffer_get_eol (&edit->buffer, b ); tws > b; tws--)730 if (tty_use_colors () && edit_options.visible_tws) 731 for (tws = edit_buffer_get_eol (&edit->buffer, b, FALSE); tws > b; tws--) 563 732 { 564 733 unsigned int c; 565 734 … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 568 737 break; 569 738 } 570 739 571 while (col <= end_col - edit->start_col) 740 while ((edit_options.soft_wrap && col <= line_data->size) || 741 (!edit_options.soft_wrap && col <= line_data->size)) 572 742 { 573 743 int char_length = 1; 574 744 unsigned int c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 586 756 { 587 757 long x, cl; 588 758 589 x = (long) edit_move_forward3 (edit, b, 0, q );759 x = (long) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 590 760 cl = MIN (edit->column1, edit->column2); 591 761 if (x >= cl) 592 762 { … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 614 784 p->style |= book_mark << 16; 615 785 else 616 786 { 617 int color;618 619 787 color = edit_get_syntax_color (edit, q); 620 788 p->style |= color << 16; 621 789 } … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 623 791 switch (c) 624 792 { 625 793 case '\n': 626 col = end_col - edit->start_col + 1; /* quit */ 794 if (edit_options.soft_wrap) 795 col = line_data->size + 1; /* quit */ 796 else 797 col = line_data->size + 1; 627 798 break; 628 799 629 800 case '\t': 630 801 { 631 int tab_over ;802 int tab_over = 0; 632 803 int i; 633 804 634 805 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; 806 807 /* Supress off-screen part only if not in Soft Wraps mode */ 808 if (!edit_options.soft_wrap || edit_options.soft_wrap) 809 { 810 tab_over = end_col - (col + i - 1); 811 if (tab_over < 0) 812 i += tab_over; 813 } 638 814 col += i; 639 if ((edit_options.visible_tabs || (edit_options.visible_tws && q >= tws)) 640 && enable_show_tabs_tws && tty_use_colors ()) 815 if (tty_use_colors () 816 && (edit_options.visible_tabs || (edit_options.visible_tws && q >= tws)) 817 && enable_show_tabs_tws) 641 818 { 642 819 if ((p->style & MOD_MARKED) != 0) 643 820 c = p->style; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 669 846 p->style = c; 670 847 p++; 671 848 } 672 else 849 else if (i > 0) 673 850 { 674 851 p->ch = '>'; 675 852 p->style = c; 676 853 p++; 677 854 } 678 855 } 679 else if ( edit_options.visible_tws && q >= tws && enable_show_tabs_tws680 && tty_use_colors ())856 else if (tty_use_colors () && edit_options.visible_tws && q >= tws 857 && enable_show_tabs_tws) 681 858 { 682 859 p->ch = '.'; 683 860 p->style |= MOD_WHITESPACE; 684 861 c = p->style & ~MOD_CURSOR; 685 862 p++; 686 while (--i !=0)863 while (--i > 0) 687 864 { 688 865 p->ch = ' '; 689 866 p->style = c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 695 872 p->ch |= ' '; 696 873 c = p->style & ~MOD_CURSOR; 697 874 p++; 698 while (--i !=0)875 while (--i > 0) 699 876 { 700 877 p->ch = ' '; 701 878 p->style = c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 706 883 break; 707 884 708 885 case ' ': 709 if ( edit_options.visible_tws && q >= tws && enable_show_tabs_tws710 && tty_use_colors ())886 if (tty_use_colors () && edit_options.visible_tws && q >= tws 887 && enable_show_tabs_tws) 711 888 { 712 889 p->ch = '.'; 713 890 p->style |= MOD_WHITESPACE; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 796 973 if (char_length > 1) 797 974 q += char_length - 1; 798 975 799 if (col > (end_col - edit->start_col + 1)) 976 if ((edit_options.soft_wrap && col > (line_data->size + 1)) 977 || (!edit_options.soft_wrap && (col > line_data->size + 1))) 800 978 { 801 979 if (wide_width_char) 802 980 { … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 814 992 } 815 993 816 994 p->ch = 0; 817 818 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark); 995 if (draw) 996 print_to_widget (edit, line_data); 997 return line_data; 819 998 } 820 999 821 1000 /* --------------------------------------------------------------------------------------------- */ 822 1001 823 1002 static inline void 824 edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column) 1003 edit_draw_this_char (WEdit * edit, off_t curs, long order_idx, long row, long start_column, 1004 long end_column) 825 1005 { 1006 MCELineData *line_data; 826 1007 off_t b; 827 1008 828 b = edit_buffer_get_bol (&edit->buffer, curs); 829 edit_draw_this_line (edit, b, row, start_column, end_column); 1009 b = edit_buffer_get_bol (&edit->buffer, curs, FALSE); 1010 line_data = 1011 edit_prepare_this_line (edit, b, order_idx, row, start_column, end_column, 0, TRUE, 0); 1012 edit->page_line_data->pdata[order_idx] = line_data; 830 1013 } 831 1014 832 1015 /* --------------------------------------------------------------------------------------------- */ … … edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long 835 1018 static inline void 836 1019 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column) 837 1020 { 838 static long prev_curs_row = 0;839 static off_t prev_curs = 0;1021 long base_line, y = 0, y_pos; 1022 MCELineData *line_data = NULL; 840 1023 841 Widget *we = WIDGET (edit); 842 Widget *wh = WIDGET (we->owner); 843 WRect *w = &we->rect; 1024 Widget *w = WIDGET (edit); 1025 Widget *wh = WIDGET (w->owner); 844 1026 845 int force = edit->force ;1027 int force = edit->force, prev_plines = 0; 846 1028 int y1, x1, y2, x2; 847 1029 int last_line, last_column; 1030 base_line = edit_buffer_count_lines (&edit->buffer, 0, edit->start_display, FALSE); 1031 base_line += edit->start_display == 0 ? 1 : 0; 1032 GPtrArray *page_line_data = edit->page_line_data; 848 1033 1034 if (edit->page_line_data == NULL) 1035 page_line_data = edit->page_line_data = g_ptr_array_new_full (LINES, g_free); 1036 g_ptr_array_set_size (edit->page_line_data, LINES); 1037 1038 y_pos = edit->array_row; 849 1039 /* draw only visible region */ 850 1040 851 1041 last_line = wh->rect.y + wh->rect.lines - 1; 852 1042 853 y1 = w-> y;1043 y1 = w->rect.y; 854 1044 if (y1 > last_line - 1 /* buttonbar */ ) 855 1045 return; 856 1046 857 1047 last_column = wh->rect.x + wh->rect.cols - 1; 858 1048 859 x1 = w-> x;1049 x1 = w->rect.x; 860 1050 if (x1 > last_column) 861 1051 return; 862 1052 863 y2 = w-> y + w->lines - 1;1053 y2 = w->rect.y + w->rect.lines - 1; 864 1054 if (y2 < wh->rect.y + 1 /* menubar */ ) 865 1055 return; 866 1056 867 x2 = w-> x + w->cols - 1;1057 x2 = w->rect.x + w->rect.cols - 1; 868 1058 if (x2 < wh->rect.x) 869 1059 return; 870 1060 … … render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, 874 1064 /* draw only visible region */ 875 1065 876 1066 if (y2 <= last_line - 1 /* buttonbar */ ) 877 end_row = w-> lines - 1;1067 end_row = w->rect.lines - 1; 878 1068 else if (y1 >= wh->rect.y + 1 /* menubar */ ) 879 1069 end_row = wh->rect.lines - 1 - y1 - 1; 880 1070 else 881 1071 end_row = start_row + wh->rect.lines - 1 - 1; 1072 soft_last_row = end_row; 882 1073 883 1074 if (x2 <= last_column) 884 end_column = w-> cols - 1;1075 end_column = w->rect.cols - 1; 885 1076 else if (x1 >= wh->rect.x) 886 1077 end_column = wh->rect.cols - 1 - x1; 887 1078 else 888 1079 end_column = start_column + wh->rect.cols - 1; 889 1080 } 1081 refresh_line_data (edit, page_line_data, start_column, end_column, end_row); 890 1082 1083 if (edit_options.soft_wrap) 1084 { 1085 int i, lines_occupied = 0; 1086 for (i = 1 /*skip 0 */ ; i <= end_row; ++i) 1087 { 1088 /* for i=1, it is line 0 that's 1089 * summed up, and so on */ 1090 lines_occupied = i + sum_plines_to_row (page_line_data, i); 1091 if (lines_occupied >= wh->rect.lines - 1 - 1) 1092 break; 1093 } 1094 soft_last_row = i - 1; 1095 } 1096 else 1097 soft_last_row = end_row; 891 1098 /* 892 1099 * If the position of the page has not moved then we can draw the cursor 893 1100 * 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 1106 900 1107 if ((force & REDRAW_PAGE) != 0) 901 1108 { 902 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0); 1109 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0, 1110 FALSE); 903 1111 for (row = start_row; row <= end_row; row++) 904 1112 { 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); 1113 line_data = edit_prepare_this_line (edit, b, row, row + prev_plines, 1114 start_column, end_column, soft_last_row, 1115 row <= soft_last_row, base_line); 1116 page_line_data->pdata[row] = line_data; 1117 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 1118 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 909 1119 } 910 1120 } 911 1121 else 912 1122 { 913 long curs_row = edit->curs_row;914 1123 915 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)1124 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < y_pos) 916 1125 { 917 1126 long upto; 918 1127 1128 row = start_row; 919 1129 b = edit->start_display; 920 upto = MIN ( curs_row- 1, end_row);921 for (row = start_row; row <= upto; row++)1130 upto = MIN (y_pos - 1, end_row); 1131 while (row <= upto) 922 1132 { 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); 1133 line_data = edit_prepare_this_line (edit, b, row, row + prev_plines, 1134 start_column, end_column, soft_last_row, 1135 row <= soft_last_row, base_line); 1136 page_line_data->pdata[row] = line_data; 1137 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 1138 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 1139 row++; 927 1140 } 928 1141 } 929 930 1142 /* if (force & REDRAW_LINE) ---> default */ 1143 y = (y_pos - 1 < 0) ? 0 : y_pos - 1; 931 1144 b = edit_buffer_get_current_bol (&edit->buffer); 932 if (curs_row >= start_row && curs_row <= end_row) 1145 if (y_pos - y == 1) 1146 b = edit_buffer_get_backward_offset (&edit->buffer, b, 1, FALSE); 1147 while (y <= y_pos && y >= start_row && y <= end_row) 933 1148 { 934 if (key_pending (edit)) 935 return; 936 edit_draw_this_line (edit, b, curs_row, start_column, end_column); 1149 prev_plines = sum_plines_to_row (edit->page_line_data, y); 1150 line_data = edit_prepare_this_line (edit, b, y, y + prev_plines, 1151 start_column, end_column, soft_last_row, 1152 y <= soft_last_row, base_line); 1153 page_line_data->pdata[y] = line_data; 1154 y++; 1155 if (y <= y_pos) 1156 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 937 1157 } 938 1158 939 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)1159 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > y_pos) 940 1160 { 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++) 1161 row = MAX (y_pos + 1, start_row); 1162 prev_plines = sum_plines_to_row (page_line_data, row); 1163 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, row, 0, 1164 FALSE); 1165 for (; row <= end_row; row++) 943 1166 { 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); 1167 line_data = 1168 edit_prepare_this_line (edit, b, row, row + prev_plines, start_column, 1169 end_column, soft_last_row, row <= soft_last_row, 1170 base_line); 1171 page_line_data->pdata[row] = line_data; 1172 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 1173 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 948 1174 } 949 1175 } 950 1176 951 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row>= 1)1177 if ((force & REDRAW_LINE_ABOVE) != 0 && y_pos >= 1) 952 1178 { 953 row = curs_row- 1;1179 row = y_pos - 1; 954 1180 b = edit_buffer_get_backward_offset (&edit->buffer, 955 1181 edit_buffer_get_current_bol (&edit->buffer), 956 1 );1182 1, FALSE); 957 1183 if (row >= start_row && row <= end_row) 958 1184 { 959 if (key_pending (edit)) 960 return; 961 edit_draw_this_line (edit, b, row, start_column, end_column); 1185 prev_plines = sum_plines_to_row (edit->page_line_data, row); 1186 line_data = 1187 edit_prepare_this_line (edit, b, row, row + prev_plines, start_column, 1188 end_column, soft_last_row, row <= soft_last_row, 1189 base_line); 1190 page_line_data->pdata[row] = line_data; 962 1191 } 963 1192 } 964 965 if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) 1193 if ((force & REDRAW_LINE_BELOW) != 0 && y_pos < w->rect.lines - 1) 966 1194 { 967 row = curs_row+ 1;1195 row = y_pos + 1; 968 1196 b = edit_buffer_get_current_bol (&edit->buffer); 969 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0 );1197 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 970 1198 if (row >= start_row && row <= end_row) 971 1199 { 972 if (key_pending (edit)) 973 return; 974 edit_draw_this_line (edit, b, row, start_column, end_column); 1200 prev_plines = sum_plines_to_row (edit->page_line_data, row); 1201 line_data = 1202 edit_prepare_this_line (edit, b, row, row + prev_plines, start_column, 1203 end_column, soft_last_row, row <= soft_last_row, 1204 base_line); 1205 page_line_data->pdata[row] = line_data; 975 1206 } 976 1207 } 977 1208 } 978 1209 } 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 1210 991 1211 edit->force = 0; 992 993 prev_curs_row = edit->curs_row;994 prev_curs = edit->buffer.curs1;995 1212 } 996 1213 997 1214 /* --------------------------------------------------------------------------------------------- */ … … edit_status (WEdit * edit, gboolean active) 1044 1261 void 1045 1262 edit_scroll_screen_over_cursor (WEdit * edit) 1046 1263 { 1047 W Rect *w = &WIDGET (edit)->rect;1264 Widget *w = WIDGET (edit); 1048 1265 1049 1266 long p; 1050 1267 long outby; 1051 1268 int b_extreme, t_extreme, l_extreme, r_extreme; 1052 1269 1053 if (w-> lines <= 0 || w->cols <= 0)1270 if (w->rect.lines <= 0 || w->rect.cols <= 0) 1054 1271 return; 1055 1272 1056 rect_resize ( w, -EDIT_TEXT_VERTICAL_OFFSET,1273 rect_resize (&w->rect, -EDIT_TEXT_VERTICAL_OFFSET, 1057 1274 -(EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width)); 1058 1275 1059 1276 if (!edit->fullscreen) 1060 rect_grow ( w, -1, -1);1277 rect_grow (&w->rect, -1, -1); 1061 1278 1062 1279 r_extreme = EDIT_RIGHT_EXTREME; 1063 1280 l_extreme = EDIT_LEFT_EXTREME; … … edit_scroll_screen_over_cursor (WEdit * edit) 1065 1282 t_extreme = EDIT_TOP_EXTREME; 1066 1283 if (edit->found_len != 0) 1067 1284 { 1068 b_extreme = MAX (w-> lines / 4, b_extreme);1069 t_extreme = MAX (w-> lines / 4, t_extreme);1285 b_extreme = MAX (w->rect.lines / 4, b_extreme); 1286 t_extreme = MAX (w->rect.lines / 4, t_extreme); 1070 1287 } 1071 if (b_extreme + t_extreme + 1 > w-> lines)1288 if (b_extreme + t_extreme + 1 > w->rect.lines) 1072 1289 { 1073 1290 int n; 1074 1291 1075 1292 n = b_extreme + t_extreme; 1076 1293 if (n == 0) 1077 1294 n = 1; 1078 b_extreme = (b_extreme * (w-> lines - 1)) / n;1079 t_extreme = (t_extreme * (w-> lines - 1)) / n;1295 b_extreme = (b_extreme * (w->rect.lines - 1)) / n; 1296 t_extreme = (t_extreme * (w->rect.lines - 1)) / n; 1080 1297 } 1081 if (l_extreme + r_extreme + 1 > w-> cols)1298 if (l_extreme + r_extreme + 1 > w->rect.cols) 1082 1299 { 1083 1300 int n; 1084 1301 1085 1302 n = l_extreme + r_extreme; 1086 1303 if (n == 0) 1087 1304 n = 1; 1088 l_extreme = (l_extreme * (w-> cols - 1)) / n;1089 r_extreme = (r_extreme * (w-> cols - 1)) / n;1305 l_extreme = (l_extreme * (w->rect.cols - 1)) / n; 1306 r_extreme = (r_extreme * (w->rect.cols - 1)) / n; 1090 1307 } 1091 1308 p = edit_get_col (edit) + edit->over_col; 1092 1309 edit_update_curs_row (edit); 1093 outby = p + edit->start_col - w-> cols + 1 + (r_extreme + edit->found_len);1310 outby = p + edit->start_col - w->rect.cols + 1 + (r_extreme + edit->found_len); 1094 1311 if (outby > 0) 1095 1312 edit_scroll_right (edit, outby); 1096 1313 outby = l_extreme - p - edit->start_col; 1097 1314 if (outby > 0) 1098 1315 edit_scroll_left (edit, outby); 1099 1316 p = edit->curs_row; 1100 outby = p - w-> lines + 1 + b_extreme;1317 outby = p - w->rect.lines + 1 + b_extreme; 1101 1318 if (outby > 0) 1102 1319 edit_scroll_downward (edit, outby); 1103 1320 outby = t_extreme - p; … … edit_scroll_screen_over_cursor (WEdit * edit) 1105 1322 edit_scroll_upward (edit, outby); 1106 1323 edit_update_curs_row (edit); 1107 1324 1108 rect_resize ( w, EDIT_TEXT_VERTICAL_OFFSET,1325 rect_resize (&w->rect, EDIT_TEXT_VERTICAL_OFFSET, 1109 1326 EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width); 1110 1327 if (!edit->fullscreen) 1111 rect_grow ( w, 1, 1);1328 rect_grow (&w->rect, 1, 1); 1112 1329 } 1113 1330 1114 1331 /* --------------------------------------------------------------------------------------------- */ -
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..8db62e62c 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), 727 0, edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1, TRUE), 728 FALSE, 0); 726 729 727 730 if (x > line_len - 1) 728 731 { … … edit_update_cursor (WEdit * edit, const mouse_event_t * event) 737 740 } 738 741 739 742 if (y > edit->curs_row) 740 edit_move_down (edit, y - edit->curs_row, FALSE );743 edit_move_down (edit, y - edit->curs_row, FALSE, TRUE); 741 744 else if (y < edit->curs_row) 742 edit_move_up (edit, edit->curs_row - y, FALSE );745 edit_move_up (edit, edit->curs_row - y, FALSE, TRUE); 743 746 else 744 edit_move_to_prev_col (edit, edit_buffer_get_ current_bol (&edit->buffer));747 edit_move_to_prev_col (edit, edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1, TRUE)); 745 748 746 749 if (event->msg == MSG_MOUSE_CLICK) 747 750 { … … edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da 951 954 952 955 case MSG_DRAW: 953 956 e->force |= REDRAW_COMPLETELY; 957 WMSG (e, MSG_CURSOR, 7); 954 958 edit_update_screen (e); 955 959 return MSG_HANDLED; 956 960 … … edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da 985 989 { 986 990 int y, x; 987 991 988 y = (e->fullscreen ? 0 : 1) + EDIT_TEXT_VERTICAL_OFFSET + e->curs_row; 992 if (edit_options.soft_wrap) 993 edit_apply_curs_exceptions (e); 994 995 if (parm != 7) 996 { 997 e->prev_size = e->buffer.size; 998 e->prev_curs1 = e->buffer.curs1; 999 e->prev_curs_col = e->curs_col; 1000 e->prev_curs_row = e->curs_row; 1001 } 989 1002 x = (e->fullscreen ? 0 : 1) + EDIT_TEXT_HORIZONTAL_OFFSET + 990 1003 edit_options.line_state_width + e->curs_col + e->start_col + e->over_col; 1004 y = (e->fullscreen ? 0 : 1) + EDIT_TEXT_VERTICAL_OFFSET + e->curs_row; 991 1005 992 1006 widget_gotoyx (w, y, x); 993 1007 return MSG_HANDLED; … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1171 1185 break; 1172 1186 1173 1187 case MSG_MOUSE_SCROLL_UP: 1174 edit_move_up (edit, 2, TRUE );1188 edit_move_up (edit, 2, TRUE, FALSE); 1175 1189 edit_total_update (edit); 1176 1190 break; 1177 1191 1178 1192 case MSG_MOUSE_SCROLL_DOWN: 1179 edit_move_down (edit, 2, TRUE );1193 edit_move_down (edit, 2, TRUE, FALSE); 1180 1194 edit_total_update (edit); 1181 1195 break; 1182 1196 … … edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline) 1387 1401 1388 1402 group_add_widget_autopos (GROUP (h), w, WPOS_KEEP_ALL, NULL); 1389 1403 edit_set_buttonbar (edit, buttonbar_find (h)); 1404 edit_set_end_column (edit); 1390 1405 widget_draw (WIDGET (h)); 1391 1406 1392 1407 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..0d6ded653 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, 139 FALSE); 139 140 } 140 141 141 142 /* --------------------------------------------------------------------------------------------- */ … … end_paragraph (WEdit * edit, gboolean force) 161 162 edit_buffer_get_forward_offset (&edit->buffer, 162 163 edit_buffer_get_current_bol 163 164 (&edit->buffer), 164 i - edit->buffer.curs_line, 0)); 165 i - edit->buffer.curs_line, 0, 166 FALSE), FALSE); 165 167 } 166 168 167 169 /* --------------------------------------------------------------------------------------------- */ … … edit_indent_width (const WEdit * edit, off_t p) 377 379 && q < edit->buffer.size - 1) 378 380 q++; 379 381 /* count the number of columns of indentation */ 380 return (long) edit_move_forward3 (edit, p, 0, q );382 return (long) edit_move_forward3 (edit, p, 0, q, FALSE, FALSE); 381 383 } 382 384 383 385 /* --------------------------------------------------------------------------------------------- */ -
src/keymap.c
diff --git a/src/keymap.c b/src/keymap.c index 3f6cce420..2d95cc2d7 100644
a b static const global_keymap_ini_t default_editor_keymap[] = { 472 472 {"MacroStartStopRecord", "ctrl-r"}, 473 473 {"MacroExecute", "ctrl-a"}, 474 474 {"ShowNumbers", "alt-n"}, 475 {"SoftFolds", "alt-w"}, 475 476 {"ShowTabTws", "alt-underline"}, 476 477 {"SyntaxOnOff", "ctrl-s"}, 477 478 {"Find", "alt-enter"}, -
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 };