Ticket #1447: 0001-Implementation-of-soft-wraps-screen-only-division-of.4.patch
File 0001-Implementation-of-soft-wraps-screen-only-division-of.4.patch, 115.2 KB (added by psprint, 15 months ago) |
---|
-
lib/keybind.c
From 9400f7bf583d0c67e46ce448dcb9f0e197ee88ec 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 | 530 ++++++++++++++++++++++++++++------- src/editor/edit.h | 5 + src/editor/editbuffer.c | 160 +++++++++-- src/editor/editbuffer.h | 23 +- src/editor/editcmd.c | 49 ++-- src/editor/editdraw.c | 589 +++++++++++++++++++++++++++------------ 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, 1095 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..b6217f76e 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; 918 bol = edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1 - edit->flag, screen_lines); 919 screen_lines &= edit_options.soft_wrap; 920 edit->flag2 = TRUE; 921 edit->flag = FALSE; 922 edit_cursor_move (edit, bol - edit->buffer.curs1); 878 923 edit->search_start = edit->buffer.curs1; 879 924 edit->prev_col = edit_get_col (edit); 880 925 edit->over_col = 0; … … edit_cursor_to_bol (WEdit * edit) 883 928 /* --------------------------------------------------------------------------------------------- */ 884 929 /** goto end of line */ 885 930 886 staticvoid887 edit_cursor_to_eol (WEdit * edit )931 void 932 edit_cursor_to_eol (WEdit * edit, gboolean screen_lines) 888 933 { 889 edit_cursor_move (edit, edit_buffer_get_current_eol (&edit->buffer) - edit->buffer.curs1); 934 off_t eol; 935 screen_lines &= edit_options.soft_wrap; 936 if (edit->flag) 937 return; 938 edit->flag2 = 0; 939 940 eol = edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1, screen_lines); 941 942 edit_cursor_move (edit, eol - edit->buffer.curs1); 890 943 edit->search_start = edit->buffer.curs1; 891 944 edit->prev_col = edit_get_col (edit); 892 945 edit->over_col = 0; … … edit_left_char_move_cmd (WEdit * edit) 1068 1121 */ 1069 1122 1070 1123 static void 1071 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction) 1124 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction, 1125 gboolean screen_lines) 1072 1126 { 1073 1127 long p; 1074 long l = direction ? edit->buffer.curs_line : edit->buffer.lines - edit->buffer.curs_line; 1128 long l, cnt_; 1129 off_t curs1 = edit->buffer.curs1; 1130 off_t boln; 1131 int col, real_col, end_col; 1132 int offset, offset2; 1075 1133 1134 boln = edit_buffer_get_bol (&edit->buffer, curs1, FALSE); 1135 screen_lines &= edit_options.soft_wrap; 1136 if (do_scroll) 1137 screen_lines = FALSE; 1138 if (direction) 1139 { 1140 l = edit_buffer_count_lines (&edit->buffer, 0, curs1, screen_lines); 1141 if (l == 0) 1142 l++; 1143 p = edit_move_forward3 (edit, boln, 0, curs1, FALSE, 0); 1144 /* Count possible only "touched"/started screen line */ 1145 cnt_ = (p % edit->end_col == 0) ? 1 : 0; 1146 l += cnt_ - 1; 1147 } 1148 else 1149 { 1150 l = edit->buffer.lines - edit->buffer.curs_line; 1151 if (screen_lines && l < lines) 1152 { 1153 GPtrArray *page_line_data = edit->page_line_data; 1154 if (edit->page_line_data == NULL) 1155 page_line_data = edit->page_line_data = g_ptr_array_new_full (LINES, g_free); 1156 g_ptr_array_set_size (edit->page_line_data, LINES); 1157 cnt_ = sum_plines_to_row_full (page_line_data, soft_last_row + 1, FALSE); 1158 l += cnt_; 1159 cnt_ = sum_plines_to_row_full (page_line_data, edit->array_row, FALSE); 1160 l -= 1 + cnt_; 1161 p = edit_move_forward3 (edit, boln, 0, curs1, FALSE, 0); 1162 cnt_ = p / edit->end_col - ((p % edit->end_col == 0) ? 1 : 0); 1163 l -= cnt_; 1164 } 1165 } 1076 1166 if (lines > l) 1077 1167 lines = l; 1078 1168 … … edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi 1088 1178 else 1089 1179 edit_scroll_downward (edit, lines); 1090 1180 } 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); 1181 p = edit_get_cursor_offset (edit); 1182 edit_update_curs_col (edit); 1183 col = edit->curs_col; 1184 end_col = edit->end_col; 1185 1186 if ( /*m.right */ curs1 == edit->prev_curs1 + 1 && col == 0 && curs1 != boln && 1187 /*not flagged */ !edit->flag) 1188 real_col = end_col; 1189 else if ( /*m.left */ curs1 == edit->prev_curs1 - 1 && 1190 col == end_col - 1 && !edit->flag) 1191 real_col = end_col; 1192 else if (ABS (curs1 - edit->prev_curs1) != 1 && col == 0 && curs1 != boln && !edit->flag2) 1193 real_col = end_col; 1194 else 1195 real_col = col; 1196 1197 if (direction) 1198 p = edit_buffer_get_backward_offset (&edit->buffer, p, lines, screen_lines); 1199 else 1200 p = edit_buffer_get_forward_offset (&edit->buffer, p, lines, 0, screen_lines); 1201 1202 offset = edit_move_forward3 (edit, p, col, 0, FALSE, 0); 1203 offset2 = edit_move_forward3 (edit, p, real_col % end_col, 0, FALSE, 0); 1204 if (real_col == end_col && offset - 1 > 0 1205 && edit_buffer_get_byte_ex (&edit->buffer, offset - 1) == '\n' 1206 && edit_buffer_get_byte_ex (&edit->buffer, offset) != '\n') 1207 offset2 = offset - 1; 1208 edit_cursor_move (edit, offset2 - curs1); 1096 1209 1097 1210 #ifdef HAVE_CHARSET 1098 1211 /* search start of current multibyte char (like CJK) */ 1099 if ( edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size1212 if (0 && edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size 1100 1213 && edit_buffer_get_current_byte (&edit->buffer) >= 256) 1101 1214 { 1102 1215 edit_right_char_move_cmd (edit); … … static void 1158 1271 edit_do_undo (WEdit * edit) 1159 1272 { 1160 1273 long ac; 1161 long count = 0;1162 1274 1163 1275 edit->undo_stack_disable = 1; /* don't record undo's onto undo stack! */ 1164 1276 edit->over_col = 0; … … edit_do_undo (WEdit * edit) 1200 1312 { 1201 1313 edit->mark1 = ac - MARK_1; 1202 1314 edit->column1 = 1203 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 1204 0, edit->mark1); 1315 (long) edit_move_forward3 (edit, 1316 edit_buffer_get_bol (&edit->buffer, edit->mark1, TRUE), 1317 0, edit->mark1, FALSE, 0); 1205 1318 } 1206 1319 if (ac >= MARK_2 - 2 && ac < MARK_CURS - 2) 1207 1320 { 1208 1321 edit->mark2 = ac - MARK_2; 1209 1322 edit->column2 = 1210 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), 1211 0, edit->mark2); 1323 (long) edit_move_forward3 (edit, 1324 edit_buffer_get_bol (&edit->buffer, edit->mark2, TRUE), 1325 0, edit->mark2, FALSE, 0); 1212 1326 } 1213 1327 else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS) 1214 1328 { 1215 1329 edit->end_mark_curs = ac - MARK_CURS; 1216 1330 } 1217 if (count++) 1218 edit->force |= REDRAW_PAGE; /* more than one pop usually means something big */ 1331 edit->force |= REDRAW_PAGE; 1219 1332 } 1220 1333 1221 1334 if (edit->start_display > ac - KEY_PRESS) 1222 1335 { 1223 1336 edit->start_line -= 1224 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display );1337 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display, FALSE) - 1; 1225 1338 edit->force |= REDRAW_PAGE; 1226 1339 } 1227 1340 else if (edit->start_display < ac - KEY_PRESS) 1228 1341 { 1229 1342 edit->start_line += 1230 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS );1343 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS, FALSE) - 1; 1231 1344 edit->force |= REDRAW_PAGE; 1232 1345 } 1233 1346 edit->start_display = ac - KEY_PRESS; /* see push and pop above */ … … static void 1243 1356 edit_do_redo (WEdit * edit) 1244 1357 { 1245 1358 long ac; 1246 long count = 0;1247 1359 1248 1360 if (edit->redo_stack_reset) 1249 1361 return; … … edit_do_redo (WEdit * edit) 1285 1397 { 1286 1398 edit->mark1 = ac - MARK_1; 1287 1399 edit->column1 = 1288 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1), 1289 0, edit->mark1); 1400 (long) edit_move_forward3 (edit, 1401 edit_buffer_get_bol (&edit->buffer, edit->mark1, TRUE), 1402 0, edit->mark1, FALSE, 0); 1290 1403 } 1291 1404 else if (ac >= MARK_2 - 2 && ac < KEY_PRESS) 1292 1405 { 1293 1406 edit->mark2 = ac - MARK_2; 1294 1407 edit->column2 = 1295 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2), 1296 0, edit->mark2); 1408 (long) edit_move_forward3 (edit, 1409 edit_buffer_get_bol (&edit->buffer, edit->mark2, TRUE), 1410 0, edit->mark2, FALSE, 0); 1297 1411 } 1298 /* more than one pop usually means something big */ 1299 if (count++) 1300 edit->force |= REDRAW_PAGE; 1412 edit->force |= REDRAW_PAGE; 1301 1413 } 1302 1414 1303 1415 if (edit->start_display > ac - KEY_PRESS) 1304 1416 { 1305 1417 edit->start_line -= 1306 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display );1418 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display, FALSE) - 1; 1307 1419 edit->force |= REDRAW_PAGE; 1308 1420 } 1309 1421 else if (edit->start_display < ac - KEY_PRESS) 1310 1422 { 1311 1423 edit->start_line += 1312 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS );1424 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS, FALSE) - 1; 1313 1425 edit->force |= REDRAW_PAGE; 1314 1426 } 1315 1427 edit->start_display = ac - KEY_PRESS; /* see push and pop above */ … … edit_auto_indent (WEdit * edit) 1404 1516 1405 1517 p = edit->buffer.curs1; 1406 1518 /* use the previous line as a template */ 1407 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1 );1519 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1, FALSE); 1408 1520 /* copy the leading whitespace of the line */ 1409 1521 while (TRUE) 1410 1522 { /* no range check - the line _is_ \n-terminated */ … … edit_move_block_to_right (WEdit * edit) 1604 1716 if (!eval_marks (edit, &start_mark, &end_mark)) 1605 1717 return; 1606 1718 1607 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark );1608 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1 );1719 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark, FALSE); 1720 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1, FALSE); 1609 1721 1610 1722 do 1611 1723 { … … edit_move_block_to_right (WEdit * edit) 1617 1729 else 1618 1730 edit_insert (edit, '\t'); 1619 1731 edit_cursor_move (edit, 1620 edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1); 1732 edit_buffer_get_bol (&edit->buffer, cur_bol, 1733 FALSE) - edit->buffer.curs1); 1621 1734 } 1622 1735 1623 1736 if (cur_bol == 0) 1624 1737 break; 1625 1738 1626 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1 );1739 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1, FALSE); 1627 1740 } 1628 1741 while (cur_bol >= start_bol); 1629 1742 … … edit_move_block_to_left (WEdit * edit) 1641 1754 if (!eval_marks (edit, &start_mark, &end_mark)) 1642 1755 return; 1643 1756 1644 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark );1645 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1 );1757 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark, FALSE); 1758 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1, FALSE); 1646 1759 1647 1760 do 1648 1761 { … … edit_move_block_to_left (WEdit * edit) 1671 1784 if (cur_bol == 0) 1672 1785 break; 1673 1786 1674 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1 );1787 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1, FALSE); 1675 1788 } 1676 1789 while (cur_bol >= start_bol); 1677 1790 … … edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * 1748 1861 } 1749 1862 } 1750 1863 1751 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1); 1864 edit_cursor_move (edit, 1865 edit_move_forward3 (edit, p, col, 0, FALSE, 1866 0) - edit->buffer.curs1); 1752 1867 1753 1868 for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) 1754 1869 edit_insert (edit, ' '); … … edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * 1769 1884 /*** public functions ****************************************************************************/ 1770 1885 /* --------------------------------------------------------------------------------------------- */ 1771 1886 1887 1888 void 1889 edit_apply_curs_exceptions (WEdit * e) 1890 { 1891 off_t bol_m2, bol, boln, eol, curs1, prev_curs1; 1892 long size, cnt_m2, col, end_col, psize; 1893 1894 bol_m2 = edit_buffer_get_bol (&e->buffer, e->buffer.curs1 + (e->buffer.curs1 - 2 >= 0 ? -2 : 0), TRUE); 1895 bol = edit_buffer_get_bol (&e->buffer, e->buffer.curs1, TRUE); 1896 boln = edit_buffer_get_bol (&e->buffer, e->buffer.curs1, FALSE); 1897 eol = edit_buffer_get_eol (&e->buffer, e->buffer.curs1, TRUE); 1898 curs1 = e->buffer.curs1; 1899 prev_curs1 = e->prev_curs1; 1900 size = e->buffer.size; 1901 psize = e->prev_size; 1902 cnt_m2 = edit_move_forward3 (e, bol_m2, 0, eol, FALSE, 0); 1903 col = edit_move_forward3 (e, bol, 0, curs1, FALSE, 0); 1904 end_col = e->end_col; 1905 1906 edit_update_curs_row (e); 1907 1908 /* First one exception is turned on – the one 1909 * that increases cursor y position when at 1910 * first column and not at bol */ 1911 if (curs1 != boln && curs1 == bol && col == 0) 1912 { 1913 e->curs_row++; 1914 if (cnt_m2 <= end_col - 2) 1915 e->flag2 = 1; 1916 } 1917 1918 if (curs1 == bol && /*m.left */ curs1 < prev_curs1) 1919 e->flag2 = TRUE; 1920 1921 /* Remaining apply only for screen-long lines */ 1922 if (cnt_m2 <= end_col - 2) 1923 return; 1924 1925 /* The second exception – when moving at 1926 * col == 0 from a lower curs1 position (right), 1927 * meaning that it should be an end_col position 1928 */ 1929 if ( /*m.right */ curs1 == prev_curs1 + 1 && col == 0 && curs1 != boln 1930 && /*not flagged */ !e->flag) 1931 { 1932 if (psize + 1 != size) 1933 { 1934 e->flag = TRUE; 1935 e->curs_col = e->end_col; 1936 e->curs_row--; 1937 } 1938 e->flag2 = 0; 1939 } 1940 else if ( /*m.right */ curs1 == prev_curs1 + 1 && col == 1 && curs1 >= boln + 1 && 1941 /* flagged */ e->flag) 1942 { 1943 if (psize + 1 != size) 1944 { 1945 edit_cursor_move (e, -1); 1946 e->flag = FALSE; 1947 e->curs_col = 0; 1948 } 1949 e->flag2 = 1; 1950 } 1951 else if ( /*m.left */ curs1 == prev_curs1 - 1 && 1952 col == end_col - 1 && !e->flag) 1953 { 1954 if (psize != size + 1) 1955 { 1956 edit_cursor_move (e, 1); 1957 e->flag = TRUE; 1958 e->curs_col = end_col; 1959 } 1960 e->flag2 = 0; 1961 } 1962 else if (ABS (curs1 - prev_curs1) != 1 && col == 0 && curs1 != boln && !e->flag2) 1963 { 1964 e->curs_col = end_col; 1965 e->curs_row--; 1966 e->flag = TRUE; 1967 } 1968 else 1969 { 1970 e->flag = 0; 1971 } 1972 } 1973 1772 1974 /** User edit menu, like user menu (F2) but only in editor. */ 1773 1975 1774 1976 void … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2124 2326 edit_save_size (edit); 2125 2327 } 2126 2328 2329 if (edit->page_line_data == NULL) 2330 edit->page_line_data = g_ptr_array_new_full (LINES, g_free); 2331 g_ptr_array_set_size (edit->page_line_data, LINES); 2332 2127 2333 edit->drag_state = MCEDIT_DRAG_NONE; 2128 2334 2129 2335 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 2359 edit_set_codeset (edit); 2154 2360 #endif 2155 2361 2362 edit_set_end_column (edit); 2156 2363 if (!edit_load_file (edit)) 2157 2364 { 2158 2365 /* edit_load_file already gives an error message */ … … edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon 2179 2386 edit_move_to_line (edit, line - 1); 2180 2387 } 2181 2388 2389 2182 2390 edit_load_macro_cmd (edit); 2183 2391 2184 2392 return edit; … … edit_push_redo_action (WEdit * edit, long c) 2508 2716 edit->redo_stack_bottom = edit->redo_stack_pointer = 0; 2509 2717 } 2510 2718 2719 2720 /* --------------------------------------------------------------------------------------------- */ 2721 2511 2722 /* --------------------------------------------------------------------------------------------- */ 2512 2723 /** 2513 2724 Basic low level single character buffer alterations and movements at the cursor. … … edit_insert (WEdit * edit, int c) 2531 2742 /* now we must update some info on the file and check if a redraw is required */ 2532 2743 if (c == '\n') 2533 2744 { 2745 edit->buffer.line_begin_offset = edit->buffer.curs1; 2534 2746 book_mark_inc (edit, edit->buffer.curs_line); 2535 2747 edit->buffer.curs_line++; 2536 2748 edit->buffer.lines++; … … edit_backspace (WEdit * edit, gboolean byte_delete) 2724 2936 void 2725 2937 edit_cursor_move (WEdit * edit, off_t increment) 2726 2938 { 2939 gboolean scroll = FALSE; 2940 off_t idx; 2727 2941 if (increment < 0) 2728 2942 { 2729 for ( ; increment < 0 && edit->buffer.curs1 != 0; increment++)2943 for (idx = 0; idx > increment && edit->buffer.curs1 != 0; idx--) 2730 2944 { 2731 2945 int c; 2732 2946 … … edit_cursor_move (WEdit * edit, off_t increment) 2737 2951 c = edit_buffer_backspace (&edit->buffer); 2738 2952 if (c == '\n') 2739 2953 { 2954 edit->buffer.line_begin_offset = 0; 2955 for (int i = edit->buffer.curs1 - 1; i > 0; i--) 2956 { 2957 unsigned char ch = edit_buffer_get_byte (&edit->buffer, i); 2958 if (ch == '\n') 2959 { 2960 edit->buffer.line_begin_offset = i + 1; 2961 break; 2962 } 2963 } 2740 2964 edit->buffer.curs_line--; 2741 2965 edit->force |= REDRAW_LINE_BELOW; 2966 if (edit->buffer.curs_line < edit->start_line) 2967 scroll = TRUE; 2742 2968 } 2743 2969 } 2970 if (scroll) 2971 { 2972 edit_scroll_upward (edit, edit->start_line - edit->buffer.curs_line); 2973 } 2744 2974 } 2745 2975 else 2746 2976 { 2747 for ( ; increment > 0 && edit->buffer.curs2 != 0; increment--)2977 for (idx = 0; idx < increment && edit->buffer.curs2 != 0; idx++) 2748 2978 { 2749 2979 int c; 2750 2980 … … edit_cursor_move (WEdit * edit, off_t increment) 2755 2985 c = edit_buffer_delete (&edit->buffer); 2756 2986 if (c == '\n') 2757 2987 { 2988 edit->buffer.line_begin_offset = edit->buffer.curs1; 2758 2989 edit->buffer.curs_line++; 2990 if (edit->buffer.curs_line - edit->start_line >= soft_last_row) 2991 scroll = TRUE; 2759 2992 edit->force |= REDRAW_LINE_ABOVE; 2760 2993 } 2761 2994 } 2995 if (scroll) 2996 { 2997 edit_scroll_downward (edit, 2998 (edit->buffer.curs_line - edit->start_line) - soft_last_row); 2999 edit->force |= REDRAW_PAGE; 3000 } 2762 3001 } 2763 3002 } 2764 3003 … … edit_cursor_move (WEdit * edit, off_t increment) 2767 3006 /* If upto is zero returns index of cols across from current. */ 2768 3007 2769 3008 off_t 2770 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 3009 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto, gboolean as_bytes, 3010 off_t col_limit) 2771 3011 { 2772 3012 off_t p, q; 2773 long col; 3013 long col, col_acc = 0, btes = 0, prev_len = 0; 3014 int char_length = 1; 3015 int utf_ch; 2774 3016 2775 3017 if (upto != 0) 2776 3018 { … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2778 3020 cols = -10; 2779 3021 } 2780 3022 else 2781 q = edit->buffer.size + 2;3023 q = edit->buffer.size + 1; 2782 3024 2783 3025 for (col = 0, p = current; p < q; p++) 2784 3026 { … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2797 3039 #ifdef HAVE_CHARSET 2798 3040 if (edit->utf8) 2799 3041 { 2800 int utf_ch; 2801 int char_length = 1; 2802 3042 char_length = 1; 2803 3043 utf_ch = edit_buffer_get_utf (&edit->buffer, p, &char_length); 3044 2804 3045 if (mc_global.utf8_display) 2805 3046 { 2806 3047 if (char_length > 1) … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2816 3057 #endif 2817 3058 2818 3059 if (c == '\n') 2819 return (upto != 0 ? (off_t) col : p); 2820 if (c == '\t') 2821 col += TAB_SIZE - col % TAB_SIZE; 3060 { 3061 return (upto != 0 ? (off_t) (as_bytes ? btes : col - col_acc) : p); 3062 } 3063 3064 #ifdef HAVE_CHARSET 3065 if (edit->utf8) 3066 { 3067 btes += prev_len <= 1 ? char_length : 0; 3068 prev_len = prev_len <= 1 ? char_length : prev_len - 1; 3069 } 3070 else 3071 btes += 1; 3072 #else 3073 btes += 1; 3074 #endif 3075 3076 /* Treat tab specially, as it needs to use 3077 * whole line, not only screen line */ 3078 if (c == '\t' || utf_ch == '\t') 3079 { 3080 off_t boln; 3081 off_t qq, ncols = 0, acc = 0; 3082 int len, ch; 3083 boln = edit_buffer_get_bol (&edit->buffer, p, FALSE); 3084 qq = boln; 3085 len = -1; 3086 for (; len && qq <= p; 3087 (ch = edit_buffer_get_utf (&edit->buffer, qq, &len)), 3088 qq += len, ncols += 3089 (g_unichar_iswide (ch) > 0) + (ch == '\t' ? (TAB_SIZE - (ncols % TAB_SIZE)) : len > 3090 0)) 3091 { 3092 /* Still modulo the line length */ 3093 if ((ncols - acc) >= edit->end_col) 3094 acc += edit->end_col; 3095 } 3096 /* Apply precisely calculated cols */ 3097 col = ncols; 3098 if (boln != current) 3099 col -= acc; 3100 } 2822 3101 else if ((c < 32 || c == 127) && (orig_c == c 2823 3102 #ifdef HAVE_CHARSET 2824 3103 || (!mc_global.utf8_display && !edit->utf8) … … edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto) 2829 3108 col += 2; 2830 3109 else 2831 3110 col++; 3111 3112 if (col_limit > 0) 3113 { 3114 btes = ((col - col_acc) >= col_limit) ? 0 : btes; 3115 col_acc += ((col - col_acc) >= col_limit) ? col_limit : 0; 3116 } 2832 3117 } 2833 return (off_t) col; 3118 3119 return (off_t) (as_bytes ? btes : col - col_acc); 2834 3120 } 2835 3121 2836 3122 /* --------------------------------------------------------------------------------------------- */ … … edit_get_cursor_offset (const WEdit * edit) 2843 3129 } 2844 3130 2845 3131 /* --------------------------------------------------------------------------------------------- */ 3132 2846 3133 /** returns the current column position of the cursor */ 2847 3134 2848 3135 long 2849 3136 edit_get_col (const WEdit * edit) 2850 3137 { 2851 return (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 2852 edit->buffer.curs1); 3138 gboolean screen = edit_options.soft_wrap ? 1 : 0; 3139 off_t bol, col; 3140 bol = edit_buffer_get_bol (&edit->buffer, edit->buffer.curs1, screen); 3141 col = (long) edit_move_forward3 (edit, bol, 0, edit->buffer.curs1, FALSE, 0); 3142 col -= -2 * edit->start_col; 3143 return col; 2853 3144 } 2854 3145 2855 3146 /* --------------------------------------------------------------------------------------------- */ … … edit_get_col (const WEdit * edit) 2857 3148 /* --------------------------------------------------------------------------------------------- */ 2858 3149 2859 3150 void 2860 edit_update_curs_row (WEdit * e dit)3151 edit_update_curs_row (WEdit * e) 2861 3152 { 2862 edit->curs_row = edit->buffer.curs_line - edit->start_line; 3153 /* Helper variables */ 3154 edit_buffer_t *buf = &e->buffer; 3155 off_t curs1; 3156 3157 /* The screen-line count ↔ the cursor row */ 3158 int lines; 3159 curs1 = edit_get_cursor_offset (e); 3160 lines = edit_buffer_count_lines (buf, e->start_display, curs1, TRUE); 3161 /* Screen-line count should be 0-based */ 3162 e->curs_row = lines > 0 ? lines - 1 : 0; 3163 /* Non screen-lines line count */ 3164 e->array_row = edit_buffer_count_lines (buf, e->start_display, curs1, FALSE); 3165 /* Make the line count 0-based */ 3166 e->array_row > 0 ? e->array_row-- : 0; 2863 3167 } 2864 3168 2865 3169 /* --------------------------------------------------------------------------------------------- */ … … edit_update_curs_row (WEdit * edit) 2867 3171 void 2868 3172 edit_update_curs_col (WEdit * edit) 2869 3173 { 2870 edit->curs_col = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 2871 0, edit->buffer.curs1); 3174 edit->curs_col = edit_get_col (edit); 2872 3175 } 2873 3176 2874 3177 /* --------------------------------------------------------------------------------------------- */ … … edit_scroll_upward (WEdit * edit, long i) 2893 3196 { 2894 3197 edit->start_line -= i; 2895 3198 edit->start_display = 2896 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i );3199 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i, FALSE); 2897 3200 edit->force |= REDRAW_PAGE; 2898 3201 edit->force &= (0xfff - REDRAW_CHAR_ONLY); 2899 3202 } … … edit_scroll_downward (WEdit * edit, long i) 2908 3211 { 2909 3212 long lines_below; 2910 3213 2911 lines_below = edit->buffer.lines - edit->start_line - ( WIDGET (edit)->rect.lines- 1);3214 lines_below = edit->buffer.lines - edit->start_line - (soft_last_row - 1); 2912 3215 if (lines_below > 0) 2913 3216 { 2914 3217 if (i > lines_below) 2915 3218 i = lines_below; 2916 3219 edit->start_line += i; 2917 3220 edit->start_display = 2918 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0 );3221 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0, FALSE); 2919 3222 edit->force |= REDRAW_PAGE; 2920 3223 edit->force &= (0xfff - REDRAW_CHAR_ONLY); 2921 3224 } … … edit_move_to_prev_col (WEdit * edit, off_t p) 2958 3261 long over = edit->over_col; 2959 3262 2960 3263 edit_cursor_move (edit, 2961 edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1); 3264 edit_move_forward3 (edit, p, prev + edit->over_col, 0, FALSE, 3265 0) - edit->buffer.curs1); 2962 3266 2963 3267 if (edit_options.cursor_beyond_eol) 2964 3268 { 2965 3269 long line_len; 2966 3270 2967 3271 line_len = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, 2968 edit_buffer_get_current_eol (&edit->buffer)); 3272 edit_buffer_get_current_eol (&edit->buffer), FALSE, 3273 FALSE); 2969 3274 if (line_len < prev + edit->over_col) 2970 3275 { 2971 3276 edit->over_col = prev + over - line_len; … … edit_move_to_prev_col (WEdit * edit, off_t p) 2998 3303 p = edit_buffer_get_current_bol (&edit->buffer); 2999 3304 edit_cursor_move (edit, 3000 3305 edit_move_forward3 (edit, p, edit->curs_col, 3001 0 ) - edit->buffer.curs1);3306 0, FALSE, FALSE) - edit->buffer.curs1); 3002 3307 if (!left_of_four_spaces (edit)) 3003 3308 edit_cursor_move (edit, 3004 edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1); 3309 edit_move_forward3 (edit, p, q, 0, FALSE, 3310 FALSE) - edit->buffer.curs1); 3005 3311 } 3006 3312 } 3007 3313 } … … void 3029 3335 edit_move_to_line (WEdit * e, long line) 3030 3336 { 3031 3337 if (line < e->buffer.curs_line) 3032 edit_move_up (e, e->buffer.curs_line - line, FALSE );3338 edit_move_up (e, e->buffer.curs_line - line, FALSE, FALSE); 3033 3339 else 3034 edit_move_down (e, line - e->buffer.curs_line, FALSE );3340 edit_move_down (e, line - e->buffer.curs_line, FALSE, FALSE); 3035 3341 edit_scroll_screen_over_cursor (e); 3036 3342 } 3037 3343 … … edit_execute_key_command (WEdit * edit, long command, int char_for_insertion) 3260 3566 void 3261 3567 edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3262 3568 { 3263 WRect *w = &WIDGET (edit)->rect;3264 3265 3569 if (command == CK_WindowFullscreen) 3266 3570 { 3267 3571 edit_toggle_fullscreen (edit); … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3353 3657 /* An ordinary key press */ 3354 3658 if (char_for_insertion >= 0) 3355 3659 { 3660 off_t prev_curs_col, col; 3661 3662 if (edit->curs_col == 0) 3663 edit->force |= REDRAW_AFTER_CURSOR; 3664 prev_curs_col = edit->curs_col; 3665 3356 3666 /* if non persistent selection and text selected */ 3357 3667 if (!edit_options.persistent_selections && edit->mark1 != edit->mark2) 3358 3668 edit_block_delete_cmd (edit); … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3408 3718 edit->force |= REDRAW_PAGE; 3409 3719 } 3410 3720 else 3721 { 3411 3722 check_and_wrap_line (edit); 3723 edit->force |= REDRAW_AFTER_CURSOR; 3724 } 3725 col = edit_get_col (edit); 3726 if (prev_curs_col == edit->buffer.end_col - 1 && col == 0) 3727 edit->force |= REDRAW_AFTER_CURSOR; 3412 3728 edit->found_len = 0; 3413 3729 edit->prev_col = edit_get_col (edit); 3414 3730 edit->search_start = edit->buffer.curs1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3467 3783 case CK_Right: 3468 3784 case CK_MarkLeft: 3469 3785 case CK_MarkRight: 3470 edit->force |= REDRAW_ CHAR_ONLY;3786 edit->force |= REDRAW_LINE; 3471 3787 break; 3472 3788 default: 3473 3789 break; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3497 3813 } 3498 3814 else 3499 3815 edit_backspace (edit, FALSE); 3816 3817 edit->force |= REDRAW_AFTER_CURSOR; 3500 3818 break; 3501 3819 case CK_Delete: 3502 3820 /* if non persistent selection and text selected */ … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3563 3881 MC_FALLTHROUGH; 3564 3882 case CK_PageUp: 3565 3883 case CK_MarkPageUp: 3566 edit_move_up (edit, w->lines - 1, TRUE);3884 edit_move_up (edit, soft_last_row, TRUE, FALSE); 3567 3885 break; 3568 3886 case CK_MarkColumnPageDown: 3569 3887 edit->column_highlight = 1; 3570 3888 MC_FALLTHROUGH; 3571 3889 case CK_PageDown: 3572 3890 case CK_MarkPageDown: 3573 edit_move_down (edit, w->lines - 1, TRUE);3891 edit_move_down (edit, soft_last_row, TRUE, FALSE); 3574 3892 break; 3575 3893 case CK_MarkColumnLeft: 3576 3894 edit->column_highlight = 1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3626 3944 MC_FALLTHROUGH; 3627 3945 case CK_Up: 3628 3946 case CK_MarkUp: 3629 edit_move_up (edit, 1, FALSE );3947 edit_move_up (edit, 1, FALSE, TRUE); 3630 3948 break; 3631 3949 case CK_MarkColumnDown: 3632 3950 edit->column_highlight = 1; 3633 3951 MC_FALLTHROUGH; 3634 3952 case CK_Down: 3635 3953 case CK_MarkDown: 3636 edit_move_down (edit, 1, FALSE );3954 edit_move_down (edit, 1, FALSE, TRUE); 3637 3955 break; 3638 3956 case CK_MarkColumnParagraphUp: 3639 3957 edit->column_highlight = 1; … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3654 3972 MC_FALLTHROUGH; 3655 3973 case CK_ScrollUp: 3656 3974 case CK_MarkScrollUp: 3657 edit_move_up (edit, 1, TRUE );3975 edit_move_up (edit, 1, TRUE, TRUE); 3658 3976 break; 3659 3977 case CK_MarkColumnScrollDown: 3660 3978 edit->column_highlight = 1; 3661 3979 MC_FALLTHROUGH; 3662 3980 case CK_ScrollDown: 3663 3981 case CK_MarkScrollDown: 3664 edit_move_down (edit, 1, TRUE );3982 edit_move_down (edit, 1, TRUE, TRUE); 3665 3983 break; 3666 3984 case CK_Home: 3667 3985 case CK_MarkToHome: 3668 edit_cursor_to_bol (edit );3986 edit_cursor_to_bol (edit, TRUE); 3669 3987 break; 3670 3988 case CK_End: 3671 3989 case CK_MarkToEnd: 3672 edit_cursor_to_eol (edit );3990 edit_cursor_to_eol (edit, TRUE); 3673 3991 break; 3674 3992 case CK_Tab: 3675 3993 /* if text marked shift block */ … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3757 4075 if (p->next != NULL) 3758 4076 { 3759 4077 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);4078 if (p->line >= edit->start_line + soft_last_row + 1 || p->line < edit->start_line) 4079 edit_move_display (edit, p->line - (soft_last_row + 1) / 2); 3762 4080 edit_move_to_line (edit, p->line); 3763 4081 } 3764 4082 } … … edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 3774 4092 p = p->prev; 3775 4093 if (p->line >= 0) 3776 4094 { 3777 if (p->line >= edit->start_line + w->lines|| p->line < edit->start_line)3778 edit_move_display (edit, p->line - w->lines/ 2);4095 if (p->line >= edit->start_line + soft_last_row + 1 || p->line < edit->start_line) 4096 edit_move_display (edit, p->line - (soft_last_row + 1) / 2); 3779 4097 edit_move_to_line (edit, p->line); 3780 4098 } 3781 4099 } 3782 4100 break; 3783 4101 4102 case CK_SoftFolds: 4103 edit_options.soft_wrap = !edit_options.soft_wrap; 4104 edit->start_col *= !edit_options.soft_wrap; 4105 edit->force |= REDRAW_COMPLETELY; 4106 break; 4107 3784 4108 case CK_Top: 3785 4109 case CK_MarkToFileBegin: 3786 4110 edit_move_to_top (edit); … … edit_stack_free (void) 4050 4374 /** move i lines */ 4051 4375 4052 4376 void 4053 edit_move_up (WEdit * edit, long i, gboolean do_scroll )4377 edit_move_up (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines) 4054 4378 { 4055 edit_move_updown (edit, i, do_scroll, TRUE); 4379 screen_lines &= edit_options.soft_wrap; 4380 edit_move_updown (edit, i, do_scroll, TRUE, screen_lines); 4056 4381 } 4057 4382 4058 4383 /* --------------------------------------------------------------------------------------------- */ 4059 4384 /** move i lines */ 4060 4385 4061 4386 void 4062 edit_move_down (WEdit * edit, long i, gboolean do_scroll )4387 edit_move_down (WEdit * edit, long i, gboolean do_scroll, gboolean screen_lines) 4063 4388 { 4064 edit_move_updown (edit, i, do_scroll, FALSE); 4389 screen_lines &= edit_options.soft_wrap; 4390 edit_move_updown (edit, i, do_scroll, FALSE, screen_lines); 4065 4391 } 4066 4392 4067 4393 /* --------------------------------------------------------------------------------------------- */ -
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..458072bc9 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; 149 byte = edit_buffer_get_byte (buf, first); 150 if (byte == '\t' || (all_kinds && byte == '\v')) 151 cnt++; 152 ++first; 153 } 154 return cnt; 155 } 156 139 157 /* --------------------------------------------------------------------------------------------- */ 140 158 /** 141 159 * Initialize editor buffers. … … edit_buffer_get_byte_ptr (const edit_buffer_t * buf, off_t byte_index) 144 162 */ 145 163 146 164 void 147 edit_buffer_init ( edit_buffer_t * buf, off_t size)165 edit_buffer_init (WEdit * e, edit_buffer_t * buf, off_t size) 148 166 { 149 167 buf->b1 = g_ptr_array_new_full (32, g_free); 150 168 buf->b2 = g_ptr_array_new_full (32, g_free); 169 buf->edit_widget = e; 170 buf->end_col = 73; 151 171 152 172 buf->curs1 = 0; 153 173 buf->curs2 = 0; … … void 167 187 edit_buffer_clean (edit_buffer_t * buf) 168 188 { 169 189 if (buf->b1 != NULL) 190 { 170 191 g_ptr_array_free (buf->b1, TRUE); 192 } 171 193 172 194 if (buf->b2 != NULL) 195 { 173 196 g_ptr_array_free (buf->b2, TRUE); 197 } 174 198 } 175 199 176 200 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_clean (edit_buffer_t * buf) 182 206 * 183 207 * @return '\n' if byte_index is negative or larger than file size; byte at byte_index otherwise. 184 208 */ 209 int 210 edit_buffer_get_byte_ex (const edit_buffer_t * buf, off_t byte_index) 211 { 212 char *p; 213 214 p = edit_buffer_get_byte_ptr (buf, byte_index); 215 216 return (p != NULL) ? *(unsigned char *) p : -1; 217 } 185 218 186 219 int 187 220 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 356 */ 324 357 325 358 long 326 edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last )359 edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last, gboolean screen_lines) 327 360 { 328 long lines = 0; 361 long lines = 0, prev_eol = 0, eol; 362 screen_lines &= edit_options.soft_wrap; 329 363 330 364 first = MAX (first, 0); 331 365 last = MIN (last, buf->size); 332 366 333 while (first < last) 334 if (edit_buffer_get_byte (buf, first++) == '\n') 335 lines++; 367 if (first == last) 368 return 0; 336 369 370 while (first <= last) 371 { 372 eol = edit_buffer_get_eol (buf, first, screen_lines); 373 /* Advance in buffer */ 374 if (edit_buffer_get_byte_ex (buf, eol) == '\n' || ~screen_lines || eol == prev_eol) 375 first = eol + 1; 376 else 377 first = eol; 378 prev_eol = eol; 379 /* Count line */ 380 lines++; 381 } 337 382 return lines; 338 383 } 339 384 … … edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last) 348 393 */ 349 394 350 395 off_t 351 edit_buffer_get_bol (const edit_buffer_t * buf, off_t current )396 edit_buffer_get_bol (const edit_buffer_t * buf, off_t current_bol, gboolean screen_lines) 352 397 { 353 if (current <= 0) 398 off_t current_save = current_bol; 399 off_t current_eol = current_bol; 400 screen_lines &= edit_options.soft_wrap; 401 if (current_bol <= 0) 402 { 354 403 return 0; 355 356 for (; edit_buffer_get_byte (buf, current - 1) != '\n'; current--)404 } 405 for (; current_bol > 0 && edit_buffer_get_byte (buf, current_bol - 1) != '\n'; current_bol -= 1) 357 406 ; 358 407 359 return current; 408 for (; 409 (edit_buffer_get_byte (buf, current_eol) != '\n' || current_save == current_eol) 410 && current_eol < buf->size; current_eol += 1); 411 412 413 if (screen_lines) 414 { 415 off_t pos = current_save - 416 edit_move_forward3 (buf->edit_widget, current_bol, 0, current_save, TRUE, buf->end_col); 417 return pos; 418 } 419 return current_bol; 360 420 } 361 421 362 422 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_get_bol (const edit_buffer_t * buf, off_t current) 370 430 */ 371 431 372 432 off_t 373 edit_buffer_get_eol (const edit_buffer_t * buf, off_t current )433 edit_buffer_get_eol (const edit_buffer_t * buf, off_t current_eol, gboolean screen_lines) 374 434 { 375 if (current >= buf->size) 435 off_t current_save = current_eol; 436 off_t current_bol = current_eol; 437 off_t q; 438 screen_lines &= edit_options.soft_wrap; 439 if (current_eol >= buf->size) 376 440 return buf->size; 377 441 378 for (; edit_buffer_get_byte (buf, current) != '\n'; current++)442 for (; current_bol > 0 && edit_buffer_get_byte (buf, current_bol - 1) != '\n'; current_bol--) 379 443 ; 380 444 381 return current; 445 if (screen_lines) 446 { 447 off_t prev_eol = 0; 448 for (; 449 (edit_buffer_get_byte_ex (buf, current_eol) != '\n') && 450 current_eol <= buf->size && 451 (current_eol == current_save 452 || 453 ((q = 454 edit_move_forward3 (buf->edit_widget, current_bol, 0, current_eol, FALSE, 455 0) % buf->end_col) != 0)); 456 current_eol = 457 edit_move_forward3 (buf->edit_widget, current_eol, 1, 0, FALSE, 0), current_eol += 458 prev_eol == current_eol ? 1 : 0, prev_eol = current_eol) 459 ; 460 if (current_eol > buf->size && edit_buffer_get_byte_ex (buf, current_eol) != '\n') 461 current_eol = buf->size; 462 } 463 else 464 for (; (edit_buffer_get_byte (buf, current_eol) != '\n') && current_eol < buf->size; 465 current_eol++) 466 ; 467 468 469 return current_eol; 382 470 } 383 471 384 472 /* --------------------------------------------------------------------------------------------- */ … … edit_buffer_backspace (edit_buffer_t * buf) 638 726 */ 639 727 640 728 off_t 641 edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, off_t upto) 729 edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines, off_t upto, 730 gboolean screen_lines) 642 731 { 732 screen_lines &= edit_options.soft_wrap; 643 733 if (upto != 0) 644 return (off_t) edit_buffer_count_lines (buf, current, upto );734 return (off_t) edit_buffer_count_lines (buf, current, upto, screen_lines); 645 735 646 736 lines = MAX (lines, 0); 647 737 738 if (lines > 0) 739 { 740 edit_update_curs_col (buf->edit_widget); 741 if (buf->edit_widget->curs_col == buf->end_col) 742 lines--; 743 } 744 648 745 while (lines-- != 0) 649 746 { 650 long next; 747 off_t next; 748 int byte; 651 749 652 next = edit_buffer_get_eol (buf, current) + 1; 653 if (next > buf->size) 750 next = edit_buffer_get_eol (buf, current, screen_lines); 751 byte = edit_buffer_get_byte_ex (buf, next); 752 753 if (byte == '\n' || !screen_lines) 754 next++; 755 if (next > buf->size + 1) 654 756 break; 655 757 current = next; 656 758 } 657 658 759 return current; 659 760 } 660 761 … … edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long l 670 771 */ 671 772 672 773 off_t 673 edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines) 774 edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines, 775 gboolean screen_lines) 674 776 { 777 screen_lines &= edit_options.soft_wrap; 675 778 lines = MAX (lines, 0); 676 current = edit_buffer_get_bol (buf, current );779 current = edit_buffer_get_bol (buf, current, screen_lines); 677 780 678 781 while (lines-- != 0 && current != 0) 679 current = edit_buffer_get_bol (buf, current - 1); 782 { 783 current = edit_buffer_get_bol (buf, current - 1, screen_lines); 784 if (screen_lines && current > 0 && 785 edit_buffer_get_byte_ex (buf, current) == '\n' && 786 edit_buffer_get_byte_ex (buf, current - 1) != '\n') 787 lines++; 788 } 789 790 if (current > 0 && screen_lines && edit_buffer_get_byte_ex (buf, current - 1) != '\n') 791 current = edit_buffer_get_eol (buf, current - 1, screen_lines); 680 792 681 793 return current; 682 794 } -
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..4ba9cadbe 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 off_t b; 127 128 base_line = edit_buffer_count_lines (&edit->buffer, 0, edit->start_display, FALSE); 129 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0, FALSE); 130 131 for (row = start_row; row < end_row; row++) 132 { 133 int pplines_add = 0; 134 if (!edit_options.soft_wrap) 135 pplines_add = -prev_plines; 136 line_data = edit_prepare_this_line (edit, b, row, row + prev_plines + pplines_add, 137 start_column, end_column, -1, FALSE, base_line); 138 line_data->plines_count += pplines_add; 139 prev_ldata = (MCELineData *) page_line_data->pdata[row]; 140 if (prev_ldata == NULL || prev_ldata->plines_count != line_data->plines_count) 141 /* Return true if any plines changed */ 142 ret = TRUE; 143 page_line_data->pdata[row] = line_data; 144 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 145 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 146 } 147 return ret; 148 } 149 150 int 151 sum_plines_to_row_full (GPtrArray * page_line_data, int row, gboolean count_only_second_etc_lines) 152 { 153 int prev_plines = 0; 154 155 if (!edit_options.soft_wrap) 156 return prev_plines; 157 158 for (int idx = 0; idx < row && idx < (long) page_line_data->len; idx++) 159 { 160 MCELineData *line_data = page_line_data->pdata[idx]; 161 if (line_data != NULL) 162 prev_plines += 163 (line_data->plines_count > 164 0) ? line_data->plines_count - (count_only_second_etc_lines ? 1 : 0) : 0; 165 else 166 prev_plines += count_only_second_etc_lines ? 0 : 1; 167 } 168 return prev_plines; 169 } 170 91 171 static inline void 92 172 printwstr (const char *s, int len) 93 173 { … … static inline void 101 181 status_string (WEdit * edit, char *s, int w) 102 182 { 103 183 char byte_str[16]; 184 off_t bol; 185 off_t col; 104 186 105 187 /* 106 188 * If we are at the end of file, print <EOF>, … … status_string (WEdit * edit, char *s, int w) 136 218 } 137 219 138 220 /* The field lengths just prevent the status line from shortening too much */ 221 bol = edit_buffer_get_current_bol (&edit->buffer); 222 col = edit_move_forward3 (edit, bol, 0, 223 edit->buffer.curs1, FALSE, 0); 224 139 225 if (edit_options.simple_statusbar) 140 226 g_snprintf (s, w, 141 227 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s", … … status_string (WEdit * edit, char *s, int w) 143 229 edit->modified ? 'M' : '-', 144 230 macro_index < 0 ? '-' : 'R', 145 231 edit->overwrite == 0 ? '-' : 'O', 146 edit->curs_col + edit->over_col,232 col, 147 233 edit->buffer.curs_line + 1, 148 234 edit->buffer.lines + 1, (long) edit->buffer.curs1, (long) edit->buffer.size, 149 235 byte_str, … … status_string (WEdit * edit, char *s, int w) 158 244 edit->modified ? 'M' : '-', 159 245 macro_index < 0 ? '-' : 'R', 160 246 edit->overwrite == 0 ? '-' : 'O', 161 edit->curs_col + edit->over_col,247 col, 162 248 edit->start_line + 1, 163 249 edit->curs_row, 164 250 edit->buffer.curs_line + 1, … … edit_status_fullscreen (WEdit * edit, int color) 185 271 const int w = h->rect.cols; 186 272 const int gap = 3; /* between the filename and the status */ 187 273 const int right_gap = 5; /* at the right end of the screen */ 188 const int preferred_fname_len = 1 6;274 const int preferred_fname_len = 14; 189 275 char *status; 190 276 size_t status_size; 191 277 int status_len; … … edit_draw_window_icons (const WEdit * edit, int color) 377 463 /* --------------------------------------------------------------------------------------------- */ 378 464 379 465 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) 466 print_to_widget (WEdit * edit, MCELineData * line_data) 382 467 { 468 int linesize = line_data->size; 469 long row = edit_options.soft_wrap ? line_data->row : line_data->scr_index; 470 int q = line_data->q; 471 int start_col_real = line_data->start_col_real; 472 long ec = line_data->ec, idx; 473 line *line_ = line_data->ldata; 474 char *status = line_data->status; 475 int bookmarked = line_data->bookmarked; 476 383 477 Widget *w = WIDGET (edit); 384 line _s*p;478 line *p; 385 479 int x, x1, y, cols_to_skip; 386 int i ;387 int wrap_start;480 int i, yp; 481 int f_start; 388 482 int len; 389 483 484 if (row < line_data->row) 485 { 486 row = line_data->row; 487 } 390 488 x = start_col_real; 391 x1 = start_col+ EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;489 x1 = q + EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 392 490 y = row + EDIT_TEXT_VERTICAL_OFFSET; 393 491 cols_to_skip = abs (x); 394 492 … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 398 496 y++; 399 497 } 400 498 401 tty_setcolor (EDITOR_NORMAL_COLOR); 402 if (bookmarked != 0) 403 tty_setcolor (bookmarked); 499 len = ec + 1 - q; 500 f_start = edit_options.word_wrap_line_length + edit->start_col; 404 501 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) 502 for (idx = 0; idx < line_data->plines_count || idx == 0; idx++) 409 503 { 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) 504 if (len > 0 && w->rect.y + y >= 0) 413 505 { 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); 506 if (!edit_options.show_right_margin || f_start > ec) 507 { 508 tty_setcolor (EDITOR_NORMAL_COLOR); 509 if (bookmarked != 0) 510 tty_setcolor (bookmarked); 421 511 422 len -= wrap_start; 423 if (len > 0) 512 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', len); 513 } 514 else if (f_start < 0) 424 515 { 425 516 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 426 tty_draw_hline (w->rect.y + y, w->rect.x + x1 + wrap_start, ' ', len); 517 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', len); 518 } 519 else 520 { 521 if (f_start > 0) 522 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1, ' ', f_start); 523 524 len -= f_start; 525 if (len > 0) 526 { 527 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 528 tty_draw_hline (w->rect.y + y + idx, w->rect.x + x1 + f_start, ' ', len); 529 } 530 } 531 } 532 } 533 if (edit_options.line_state) 534 { 535 tty_setcolor (LINE_STATE_COLOR); 536 for (yp = 0; (edit_options.soft_wrap && yp <= linesize / ec + 537 (linesize % ec != 0 ? 0 : -1) + 538 (linesize == 0 ? 1 : 0)) || (!edit_options.soft_wrap && yp < 1); ++yp) 539 { 540 for (i = 0; i < LINE_STATE_WIDTH; i++) 541 { 542 edit_move (x1 + i - edit_options.line_state_width, y + yp); 543 if (yp == 0) 544 { 545 if (status[i] == '\0') 546 status[i] = ' '; 547 tty_print_char (status[i]); 548 } 549 else 550 tty_print_char (' '); 427 551 } 428 552 } 429 553 } 430 554 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 } 555 edit->end_col = ec; 556 edit->buffer.end_col = ec; 443 557 444 558 edit_move (x1, y); 445 559 446 560 i = 1; 447 for (p = line; p->ch != 0; p++) 561 for (idx = 0, p = &line_[-edit->start_col]; 562 (edit_options.soft_wrap && linesize-- > 0) || (!edit_options.soft_wrap 563 && (linesize-- + edit->start_col > 0) 564 && p->ch != 0); p++, idx++) 448 565 { 566 449 567 int style; 450 568 unsigned int textchar; 451 569 int color; 452 453 if (cols_to_skip != 0) 570 if (!edit_options.soft_wrap && cols_to_skip != 0) 454 571 { 455 572 cols_to_skip--; 456 573 continue; 457 574 } 458 575 576 /* Position each physical line */ 577 if (edit_options.soft_wrap && idx % ec == 0) 578 edit_move (x1, y++); 579 459 580 style = p->style & 0xFF00; 460 581 textchar = p->ch; 461 582 /* If non-printable - use black background */ … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 482 603 { 483 604 if (i > edit_options.word_wrap_line_length + edit->start_col) 484 605 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); 485 i++;486 606 } 607 i++; 487 608 488 609 tty_print_anychar (textchar); 489 610 } … … print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, 492 613 /* --------------------------------------------------------------------------------------------- */ 493 614 /** b is a pointer to the beginning of the line */ 494 615 495 static void 496 edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col) 616 static MCELineData * 617 edit_prepare_this_line (WEdit * edit, off_t b, long order_idx, long row, long start_col, 618 long end_col, long soft_last_row_idx, gboolean draw, long base_line) 497 619 { 620 long line_count, cur_line; 621 MCELineData *line_data; 498 622 Widget *w = WIDGET (edit); 499 line_s line[MAX_LINE_LEN]; 500 line_s *p = line; 623 line *p; 501 624 off_t q; 502 int col, start_col_real; 625 int wrap_line_len, line_size, start_col_real = 0; 626 int col; 627 int color; 503 628 int abn_style; 504 629 int book_mark = 0; 505 char line_stat[LINE_STATE_WIDTH + 1] = "\0";506 630 507 if (row > w->rect.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1)) 508 return; 631 q = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 632 line_size = edit_move_forward3 (edit, b, 0, q, FALSE, 0); 633 line_data = (MCELineData *) g_malloc0 (sizeof (MCELineData) + sizeof (line) * 634 (line_size + /* sentinel —→ */ 1 + 635 edit_buffer_count_tabs (&edit->buffer, b, q, 636 FALSE) * 8)); 637 p = line_data->ldata; 509 638 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; 639 /* Helper var */ 640 if (edit_options.soft_wrap) 641 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 517 642 else 518 abn_style = MOD_ABNORMAL;643 wrap_line_len = abs (edit_options.word_wrap_line_length); 519 644 520 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;521 645 if (!edit->fullscreen) 522 646 { 523 647 end_col--; 524 648 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols) 525 649 end_col--; 526 650 } 651 wrap_line_len = end_col; 527 652 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; 653 line_count = edit_buffer_count_lines (&edit->buffer, edit->start_display, q - 1, FALSE); 654 line_count += base_line + (line_count > 0 ? -1 : 0); 655 656 line_data->soft_last_row = soft_last_row_idx; 657 line_data->row = row; 658 line_data->plines_count = line_size / wrap_line_len + ((line_size % wrap_line_len) ? 1 : 0); 659 if (!edit_options.soft_wrap) 660 line_data->plines_count = 0; 661 line_data->index = line_count + (line_count > 0 ? -1 : 0); 662 line_data->scr_index = line_data->index - edit->start_line; 663 line_data->order_idx = order_idx; /* for investigation */ 664 line_data->size = line_size; 665 line_data->q = !edit_options.soft_wrap ? edit->start_col : 0; 666 line_data->ec = end_col; 667 line_data->visible = (order_idx <= line_data->soft_last_row); 668 669 if (!edit_options.soft_wrap) 670 line_data->plines_count = 0; 671 672 if (book_mark_query_color (edit, line_data->index, BOOK_MARK_COLOR)) 673 book_mark = BOOK_MARK_COLOR; 674 else if (book_mark_query_color (edit, line_data->index, BOOK_MARK_FOUND_COLOR)) 675 book_mark = BOOK_MARK_FOUND_COLOR; 676 677 line_data->bookmarked = book_mark; 678 679 if (book_mark != 0) 680 abn_style = book_mark << 16; 681 else 682 abn_style = MOD_ABNORMAL; 683 if (!edit_options.soft_wrap) 684 { 685 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width; 686 if (!edit->fullscreen) 687 { 688 end_col--; 689 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols) 690 end_col--; 691 } 692 } 693 694 color = edit_get_syntax_color (edit, b - 1); 695 if (edit_options.soft_wrap) 696 { 697 q = b; 698 col = (int) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 699 } 700 else 701 { 702 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0, FALSE, 0); 703 col = (int) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 704 line_data->start_col_real = start_col_real = col + edit->start_col; 705 } 531 706 532 707 if (edit_options.line_state) 533 708 { 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); 709 int line_cnt = 0; 710 cur_line = line_data->index; 711 if (line_data->order_idx == line_data->scr_index || cur_line + 1 < line_cnt) 712 g_snprintf (line_data->status, sizeof (line_data->status), "%7li ", cur_line + 1); 539 713 else 540 714 { 541 memset (line_ stat, ' ', LINE_STATE_WIDTH);542 line_ stat[LINE_STATE_WIDTH] = '\0';715 memset (line_data->status, ' ', LINE_STATE_WIDTH); 716 line_data->status[LINE_STATE_WIDTH] = '\0'; 543 717 } 544 545 718 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR)) 546 g_snprintf (line_ stat, 2, "*");719 g_snprintf (line_data->status, 2, "*"); 547 720 } 548 721 549 722 if (col <= -(edit->start_col + 16)) … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 553 726 off_t m1 = 0, m2 = 0; 554 727 555 728 eval_marks (edit, &m1, &m2); 556 557 if (row <= edit->buffer.lines - edit->start_line) 729 if (order_idx <= edit->buffer.lines - edit->start_line) 558 730 { 559 731 off_t tws = 0; 560 732 561 if ( edit_options.visible_tws && tty_use_colors ())562 for (tws = edit_buffer_get_eol (&edit->buffer, b ); tws > b; tws--)733 if (tty_use_colors () && edit_options.visible_tws) 734 for (tws = edit_buffer_get_eol (&edit->buffer, b, FALSE); tws > b; tws--) 563 735 { 564 736 unsigned int c; 565 737 … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 568 740 break; 569 741 } 570 742 571 while (col <= end_col - edit->start_col) 743 while ((edit_options.soft_wrap && col <= line_data->size) || 744 (!edit_options.soft_wrap && col <= line_data->size)) 572 745 { 573 746 int char_length = 1; 574 747 unsigned int c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 586 759 { 587 760 long x, cl; 588 761 589 x = (long) edit_move_forward3 (edit, b, 0, q );762 x = (long) edit_move_forward3 (edit, b, 0, q, FALSE, 0); 590 763 cl = MIN (edit->column1, edit->column2); 591 764 if (x >= cl) 592 765 { … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 614 787 p->style |= book_mark << 16; 615 788 else 616 789 { 617 int color;618 619 790 color = edit_get_syntax_color (edit, q); 620 791 p->style |= color << 16; 621 792 } … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 623 794 switch (c) 624 795 { 625 796 case '\n': 626 col = end_col - edit->start_col + 1; /* quit */ 797 if (edit_options.soft_wrap) 798 col = line_data->size + 1; /* quit */ 799 else 800 col = line_data->size + 1; 627 801 break; 628 802 629 803 case '\t': 630 804 { 631 int tab_over ;805 int tab_over = 0; 632 806 int i; 633 807 634 808 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; 809 810 /* Supress off-screen part only if not in Soft Wraps mode */ 811 if (!edit_options.soft_wrap || edit_options.soft_wrap) 812 { 813 tab_over = end_col - (col + i - 1); 814 if (tab_over < 0) 815 i += tab_over; 816 } 638 817 col += i; 639 if ((edit_options.visible_tabs || (edit_options.visible_tws && q >= tws)) 640 && enable_show_tabs_tws && tty_use_colors ()) 818 if (tty_use_colors () 819 && (edit_options.visible_tabs || (edit_options.visible_tws && q >= tws)) 820 && enable_show_tabs_tws) 641 821 { 642 822 if ((p->style & MOD_MARKED) != 0) 643 823 c = p->style; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 669 849 p->style = c; 670 850 p++; 671 851 } 672 else 852 else if (i > 0) 673 853 { 674 854 p->ch = '>'; 675 855 p->style = c; 676 856 p++; 677 857 } 678 858 } 679 else if ( edit_options.visible_tws && q >= tws && enable_show_tabs_tws680 && tty_use_colors ())859 else if (tty_use_colors () && edit_options.visible_tws && q >= tws 860 && enable_show_tabs_tws) 681 861 { 682 862 p->ch = '.'; 683 863 p->style |= MOD_WHITESPACE; 684 864 c = p->style & ~MOD_CURSOR; 685 865 p++; 686 while (--i !=0)866 while (--i > 0) 687 867 { 688 868 p->ch = ' '; 689 869 p->style = c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 695 875 p->ch |= ' '; 696 876 c = p->style & ~MOD_CURSOR; 697 877 p++; 698 while (--i !=0)878 while (--i > 0) 699 879 { 700 880 p->ch = ' '; 701 881 p->style = c; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 706 886 break; 707 887 708 888 case ' ': 709 if ( edit_options.visible_tws && q >= tws && enable_show_tabs_tws710 && tty_use_colors ())889 if (tty_use_colors () && edit_options.visible_tws && q >= tws 890 && enable_show_tabs_tws) 711 891 { 712 892 p->ch = '.'; 713 893 p->style |= MOD_WHITESPACE; … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 796 976 if (char_length > 1) 797 977 q += char_length - 1; 798 978 799 if (col > (end_col - edit->start_col + 1)) 979 if ((edit_options.soft_wrap && col > (line_data->size + 1)) 980 || (!edit_options.soft_wrap && (col > line_data->size + 1))) 800 981 { 801 982 if (wide_width_char) 802 983 { … … edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c 814 995 } 815 996 816 997 p->ch = 0; 817 818 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark); 998 if (draw) 999 print_to_widget (edit, line_data); 1000 return line_data; 819 1001 } 820 1002 821 1003 /* --------------------------------------------------------------------------------------------- */ 822 1004 823 1005 static inline void 824 edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column) 1006 edit_draw_this_char (WEdit * edit, off_t curs, long order_idx, long row, long start_column, 1007 long end_column) 825 1008 { 1009 MCELineData *line_data; 826 1010 off_t b; 827 1011 828 b = edit_buffer_get_bol (&edit->buffer, curs); 829 edit_draw_this_line (edit, b, row, start_column, end_column); 1012 b = edit_buffer_get_bol (&edit->buffer, curs, FALSE); 1013 line_data = 1014 edit_prepare_this_line (edit, b, order_idx, row, start_column, end_column, 0, TRUE, 0); 1015 edit->page_line_data->pdata[order_idx] = line_data; 830 1016 } 831 1017 832 1018 /* --------------------------------------------------------------------------------------------- */ … … edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long 835 1021 static inline void 836 1022 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column) 837 1023 { 838 static long prev_curs_row = 0;839 static off_t prev_curs = 0;1024 long base_line, y = 0, y_pos; 1025 MCELineData *line_data = NULL; 840 1026 841 Widget *we = WIDGET (edit); 842 Widget *wh = WIDGET (we->owner); 843 WRect *w = &we->rect; 1027 Widget *w = WIDGET (edit); 1028 Widget *wh = WIDGET (w->owner); 844 1029 845 int force = edit->force ;1030 int force = edit->force, prev_plines = 0; 846 1031 int y1, x1, y2, x2; 847 1032 int last_line, last_column; 1033 GPtrArray *page_line_data; 1034 base_line = edit_buffer_count_lines (&edit->buffer, 0, edit->start_display, FALSE); 1035 base_line += edit->start_display == 0 ? 1 : 0; 1036 page_line_data = edit->page_line_data; 848 1037 1038 if (edit->page_line_data == NULL) 1039 page_line_data = edit->page_line_data = g_ptr_array_new_full (LINES, g_free); 1040 g_ptr_array_set_size (edit->page_line_data, LINES); 1041 1042 y_pos = edit->array_row; 849 1043 /* draw only visible region */ 850 1044 851 1045 last_line = wh->rect.y + wh->rect.lines - 1; 852 1046 853 y1 = w-> y;1047 y1 = w->rect.y; 854 1048 if (y1 > last_line - 1 /* buttonbar */ ) 855 1049 return; 856 1050 857 1051 last_column = wh->rect.x + wh->rect.cols - 1; 858 1052 859 x1 = w-> x;1053 x1 = w->rect.x; 860 1054 if (x1 > last_column) 861 1055 return; 862 1056 863 y2 = w-> y + w->lines - 1;1057 y2 = w->rect.y + w->rect.lines - 1; 864 1058 if (y2 < wh->rect.y + 1 /* menubar */ ) 865 1059 return; 866 1060 867 x2 = w-> x + w->cols - 1;1061 x2 = w->rect.x + w->rect.cols - 1; 868 1062 if (x2 < wh->rect.x) 869 1063 return; 870 1064 … … render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, 874 1068 /* draw only visible region */ 875 1069 876 1070 if (y2 <= last_line - 1 /* buttonbar */ ) 877 end_row = w-> lines - 1;1071 end_row = w->rect.lines - 1; 878 1072 else if (y1 >= wh->rect.y + 1 /* menubar */ ) 879 1073 end_row = wh->rect.lines - 1 - y1 - 1; 880 1074 else 881 1075 end_row = start_row + wh->rect.lines - 1 - 1; 1076 soft_last_row = end_row; 882 1077 883 1078 if (x2 <= last_column) 884 end_column = w-> cols - 1;1079 end_column = w->rect.cols - 1; 885 1080 else if (x1 >= wh->rect.x) 886 1081 end_column = wh->rect.cols - 1 - x1; 887 1082 else 888 1083 end_column = start_column + wh->rect.cols - 1; 889 1084 } 1085 refresh_line_data (edit, page_line_data, start_column, end_column, end_row); 890 1086 1087 if (edit_options.soft_wrap) 1088 { 1089 int i, lines_occupied = 0; 1090 for (i = 1 /*skip 0 */ ; i <= end_row; ++i) 1091 { 1092 /* for i=1, it is line 0 that's 1093 * summed up, and so on */ 1094 lines_occupied = i + sum_plines_to_row (page_line_data, i); 1095 if (lines_occupied >= wh->rect.lines - 1 - 1) 1096 break; 1097 } 1098 soft_last_row = i - 1; 1099 } 1100 else 1101 soft_last_row = end_row; 891 1102 /* 892 1103 * If the position of the page has not moved then we can draw the cursor 893 1104 * 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 1110 900 1111 if ((force & REDRAW_PAGE) != 0) 901 1112 { 902 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0); 1113 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0, 1114 FALSE); 903 1115 for (row = start_row; row <= end_row; row++) 904 1116 { 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); 1117 line_data = edit_prepare_this_line (edit, b, row, row + prev_plines, 1118 start_column, end_column, soft_last_row, 1119 row <= soft_last_row, base_line); 1120 page_line_data->pdata[row] = line_data; 1121 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 1122 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 909 1123 } 910 1124 } 911 1125 else 912 1126 { 913 long curs_row = edit->curs_row;914 1127 915 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)1128 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < y_pos) 916 1129 { 917 1130 long upto; 918 1131 1132 row = start_row; 919 1133 b = edit->start_display; 920 upto = MIN ( curs_row- 1, end_row);921 for (row = start_row; row <= upto; row++)1134 upto = MIN (y_pos - 1, end_row); 1135 while (row <= upto) 922 1136 { 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); 1137 line_data = edit_prepare_this_line (edit, b, row, row + prev_plines, 1138 start_column, end_column, soft_last_row, 1139 row <= soft_last_row, base_line); 1140 page_line_data->pdata[row] = line_data; 1141 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 1142 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 1143 row++; 927 1144 } 928 1145 } 929 930 1146 /* if (force & REDRAW_LINE) ---> default */ 1147 y = (y_pos - 1 < 0) ? 0 : y_pos - 1; 931 1148 b = edit_buffer_get_current_bol (&edit->buffer); 932 if (curs_row >= start_row && curs_row <= end_row) 1149 if (y_pos - y == 1) 1150 b = edit_buffer_get_backward_offset (&edit->buffer, b, 1, FALSE); 1151 while (y <= y_pos && y >= start_row && y <= end_row) 933 1152 { 934 if (key_pending (edit)) 935 return; 936 edit_draw_this_line (edit, b, curs_row, start_column, end_column); 1153 prev_plines = sum_plines_to_row (edit->page_line_data, y); 1154 line_data = edit_prepare_this_line (edit, b, y, y + prev_plines, 1155 start_column, end_column, soft_last_row, 1156 y <= soft_last_row, base_line); 1157 page_line_data->pdata[y] = line_data; 1158 y++; 1159 if (y <= y_pos) 1160 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 937 1161 } 938 1162 939 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)1163 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > y_pos) 940 1164 { 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++) 1165 row = MAX (y_pos + 1, start_row); 1166 prev_plines = sum_plines_to_row (page_line_data, row); 1167 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, row, 0, 1168 FALSE); 1169 for (; row <= end_row; row++) 943 1170 { 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); 1171 line_data = 1172 edit_prepare_this_line (edit, b, row, row + prev_plines, start_column, 1173 end_column, soft_last_row, row <= soft_last_row, 1174 base_line); 1175 page_line_data->pdata[row] = line_data; 1176 prev_plines += (line_data->plines_count > 0) ? line_data->plines_count - 1 : 0; 1177 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 948 1178 } 949 1179 } 950 1180 951 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row>= 1)1181 if ((force & REDRAW_LINE_ABOVE) != 0 && y_pos >= 1) 952 1182 { 953 row = curs_row- 1;1183 row = y_pos - 1; 954 1184 b = edit_buffer_get_backward_offset (&edit->buffer, 955 1185 edit_buffer_get_current_bol (&edit->buffer), 956 1 );1186 1, FALSE); 957 1187 if (row >= start_row && row <= end_row) 958 1188 { 959 if (key_pending (edit)) 960 return; 961 edit_draw_this_line (edit, b, row, start_column, end_column); 1189 prev_plines = sum_plines_to_row (edit->page_line_data, row); 1190 line_data = 1191 edit_prepare_this_line (edit, b, row, row + prev_plines, start_column, 1192 end_column, soft_last_row, row <= soft_last_row, 1193 base_line); 1194 page_line_data->pdata[row] = line_data; 962 1195 } 963 1196 } 964 965 if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) 1197 if ((force & REDRAW_LINE_BELOW) != 0 && y_pos < w->rect.lines - 1) 966 1198 { 967 row = curs_row+ 1;1199 row = y_pos + 1; 968 1200 b = edit_buffer_get_current_bol (&edit->buffer); 969 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0 );1201 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0, FALSE); 970 1202 if (row >= start_row && row <= end_row) 971 1203 { 972 if (key_pending (edit)) 973 return; 974 edit_draw_this_line (edit, b, row, start_column, end_column); 1204 prev_plines = sum_plines_to_row (edit->page_line_data, row); 1205 line_data = 1206 edit_prepare_this_line (edit, b, row, row + prev_plines, start_column, 1207 end_column, soft_last_row, row <= soft_last_row, 1208 base_line); 1209 page_line_data->pdata[row] = line_data; 975 1210 } 976 1211 } 977 1212 } 978 1213 } 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 1214 991 1215 edit->force = 0; 992 993 prev_curs_row = edit->curs_row;994 prev_curs = edit->buffer.curs1;995 1216 } 996 1217 997 1218 /* --------------------------------------------------------------------------------------------- */ … … edit_status (WEdit * edit, gboolean active) 1044 1265 void 1045 1266 edit_scroll_screen_over_cursor (WEdit * edit) 1046 1267 { 1047 W Rect *w = &WIDGET (edit)->rect;1268 Widget *w = WIDGET (edit); 1048 1269 1049 1270 long p; 1050 1271 long outby; 1051 1272 int b_extreme, t_extreme, l_extreme, r_extreme; 1052 1273 1053 if (w-> lines <= 0 || w->cols <= 0)1274 if (w->rect.lines <= 0 || w->rect.cols <= 0) 1054 1275 return; 1055 1276 1056 rect_resize ( w, -EDIT_TEXT_VERTICAL_OFFSET,1277 rect_resize (&w->rect, -EDIT_TEXT_VERTICAL_OFFSET, 1057 1278 -(EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width)); 1058 1279 1059 1280 if (!edit->fullscreen) 1060 rect_grow ( w, -1, -1);1281 rect_grow (&w->rect, -1, -1); 1061 1282 1062 1283 r_extreme = EDIT_RIGHT_EXTREME; 1063 1284 l_extreme = EDIT_LEFT_EXTREME; … … edit_scroll_screen_over_cursor (WEdit * edit) 1065 1286 t_extreme = EDIT_TOP_EXTREME; 1066 1287 if (edit->found_len != 0) 1067 1288 { 1068 b_extreme = MAX (w-> lines / 4, b_extreme);1069 t_extreme = MAX (w-> lines / 4, t_extreme);1289 b_extreme = MAX (w->rect.lines / 4, b_extreme); 1290 t_extreme = MAX (w->rect.lines / 4, t_extreme); 1070 1291 } 1071 if (b_extreme + t_extreme + 1 > w-> lines)1292 if (b_extreme + t_extreme + 1 > w->rect.lines) 1072 1293 { 1073 1294 int n; 1074 1295 1075 1296 n = b_extreme + t_extreme; 1076 1297 if (n == 0) 1077 1298 n = 1; 1078 b_extreme = (b_extreme * (w-> lines - 1)) / n;1079 t_extreme = (t_extreme * (w-> lines - 1)) / n;1299 b_extreme = (b_extreme * (w->rect.lines - 1)) / n; 1300 t_extreme = (t_extreme * (w->rect.lines - 1)) / n; 1080 1301 } 1081 if (l_extreme + r_extreme + 1 > w-> cols)1302 if (l_extreme + r_extreme + 1 > w->rect.cols) 1082 1303 { 1083 1304 int n; 1084 1305 1085 1306 n = l_extreme + r_extreme; 1086 1307 if (n == 0) 1087 1308 n = 1; 1088 l_extreme = (l_extreme * (w-> cols - 1)) / n;1089 r_extreme = (r_extreme * (w-> cols - 1)) / n;1309 l_extreme = (l_extreme * (w->rect.cols - 1)) / n; 1310 r_extreme = (r_extreme * (w->rect.cols - 1)) / n; 1090 1311 } 1091 1312 p = edit_get_col (edit) + edit->over_col; 1092 1313 edit_update_curs_row (edit); 1093 outby = p + edit->start_col - w-> cols + 1 + (r_extreme + edit->found_len);1314 outby = p + edit->start_col - w->rect.cols + 1 + (r_extreme + edit->found_len); 1094 1315 if (outby > 0) 1095 1316 edit_scroll_right (edit, outby); 1096 1317 outby = l_extreme - p - edit->start_col; 1097 1318 if (outby > 0) 1098 1319 edit_scroll_left (edit, outby); 1099 1320 p = edit->curs_row; 1100 outby = p - w-> lines + 1 + b_extreme;1321 outby = p - w->rect.lines + 1 + b_extreme; 1101 1322 if (outby > 0) 1102 1323 edit_scroll_downward (edit, outby); 1103 1324 outby = t_extreme - p; … … edit_scroll_screen_over_cursor (WEdit * edit) 1105 1326 edit_scroll_upward (edit, outby); 1106 1327 edit_update_curs_row (edit); 1107 1328 1108 rect_resize ( w, EDIT_TEXT_VERTICAL_OFFSET,1329 rect_resize (&w->rect, EDIT_TEXT_VERTICAL_OFFSET, 1109 1330 EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width); 1110 1331 if (!edit->fullscreen) 1111 rect_grow ( w, 1, 1);1332 rect_grow (&w->rect, 1, 1); 1112 1333 } 1113 1334 1114 1335 /* --------------------------------------------------------------------------------------------- */ -
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 };