Browse Source

Ticket #1534 (cool cooledit)

    first commit for support drag cursor after end of line

    * change mouse movement, allow place cursor after EOL
    * change vertical select
    * fix: right scroll

Signed-off-by: Ilia Maslakov <il.smind@google.com>
Ilia Maslakov 15 years ago
parent
commit
f4fc6ad79d
5 changed files with 77 additions and 26 deletions
  1. 1 0
      edit/edit-widget.h
  2. 64 20
      edit/edit.c
  3. 1 1
      edit/editcmd.c
  4. 1 3
      edit/editdraw.c
  5. 10 2
      edit/editwidget.c

+ 1 - 0
edit/edit-widget.h

@@ -75,6 +75,7 @@ struct WEdit {
     long max_column;		/* The maximum cursor position ever reached used to calc hori scroll bar */
     long curs_row;		/* row position of cursor on the screen */
     long curs_col;		/* column position on screen */
+    long over_col;		/* pos after '\n' */
     int force;			/* how much of the screen do we redraw? */
     unsigned int overwrite:1;	/* Overwrite on type mode (as opposed to insert) */
     unsigned int modified:1;	/* File has been modified and needs saving */

+ 64 - 20
edit/edit.c

@@ -47,6 +47,11 @@
 #include "editcmddef.h"
 #include "usermap.h"
 
+#include "../src/tty/color.h"	/* EDITOR_NORMAL_COLOR */
+#include "../src/tty/tty.h"		/* attrset() */
+#include "../src/tty/key.h"		/* is_idle() */
+
+#include "../src/widget.h"	/* buttonbar_redraw() */
 #include "../src/cmd.h"		/* view_other_cmd() */
 #include "../src/user.h"	/* user_menu_cmd() */
 #include "../src/wtools.h"	/* query_dialog() */
@@ -699,6 +704,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename,
     }
     edit_purge_widget (edit);
     edit->num_widget_lines = lines;
+    edit->over_col = 0;
     edit->num_widget_columns = columns;
     edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
     edit->stat1.st_uid = getuid ();
@@ -1082,6 +1088,14 @@ edit_insert (WEdit *edit, int c)
     edit->curs1++;
 }
 
+void
+edit_insert_over (WEdit * edit)
+{
+    for (int i = 0; i < edit->over_col; i++ ) {
+        edit_insert (edit, ' ');
+    }
+    edit->over_col = 0;
+}
 
 /* same as edit_insert and move left */
 void edit_insert_ahead (WEdit * edit, int c)
@@ -1608,23 +1622,24 @@ static int left_of_four_spaces (WEdit *edit);
 void
 edit_move_to_prev_col (WEdit * edit, long p)
 {
-    edit_cursor_move (edit, edit_move_forward3 (edit, p, edit->prev_col, 0) - edit->curs1);
-
-    if (is_in_indent (edit) && option_fake_half_tabs) {
-	edit_update_curs_col (edit);
-	if (space_width)
-	if (edit->curs_col % (HALF_TAB_SIZE * space_width)) {
-	    int q = edit->curs_col;
-	    edit->curs_col -= (edit->curs_col % (HALF_TAB_SIZE * space_width));
-	    p = edit_bol (edit, edit->curs1);
-	    edit_cursor_move (edit, edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->curs1);
-	    if (!left_of_four_spaces (edit))
-		edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->curs1);
-	}
+    int prev = edit->prev_col;
+    int over = edit->over_col;
+
+    edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->curs1);
+
+    long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit_eol(edit, edit->curs1));
+
+    if (line_len < prev + edit->over_col) {
+        edit->over_col = prev + over - line_len;
+        edit->prev_col = line_len;
+        edit->curs_col = line_len;
+    } else {
+        edit->curs_col = prev + over;
+        edit->prev_col = edit->curs_col;
+        edit->over_col = 0;
     }
 }
 
-
 /* move i lines */
 void edit_move_up (WEdit * edit, unsigned long i, int scroll)
 {
@@ -1835,6 +1850,7 @@ static void edit_cursor_to_bol (WEdit * edit)
     edit_cursor_move (edit, edit_bol (edit, edit->curs1) - edit->curs1);
     edit->search_start = edit->curs1;
     edit->prev_col = edit_get_col (edit);
+    edit->over_col = 0;
 }
 
 /* goto end of line */
@@ -1843,6 +1859,7 @@ static void edit_cursor_to_eol (WEdit * edit)
     edit_cursor_move (edit, edit_eol (edit, edit->curs1) - edit->curs1);
     edit->search_start = edit->curs1;
     edit->prev_col = edit_get_col (edit);
+    edit->over_col = 0;
 }
 
 /* move cursor to line 'line' */
@@ -1889,10 +1906,10 @@ void edit_mark_cmd (WEdit * edit, int unmark)
 	edit->force |= REDRAW_PAGE;
     } else {
 	if (edit->mark2 >= 0) {
-	    edit_set_markers (edit, edit->curs1, -1, edit->curs_col, edit->curs_col);
+	    edit_set_markers (edit, edit->curs1, -1, edit->curs_col+edit->over_col, edit->curs_col+edit->over_col);
 	    edit->force |= REDRAW_PAGE;
 	} else
-	    edit_set_markers (edit, edit->mark1, edit->curs1, edit->column1, edit->curs_col);
+	    edit_set_markers (edit, edit->mark1, edit->curs1, edit->column1, edit->curs_col+edit->over_col);
     }
 }
 
@@ -1988,12 +2005,19 @@ static void edit_right_word_move_cmd (WEdit * edit)
 static void edit_right_char_move_cmd (WEdit * edit)
 {
     int cw = 1;
+    int c = 0;
     if ( edit->utf8 ) {
-        edit_get_utf (edit, edit->curs1, &cw);
+        c = edit_get_utf (edit, edit->curs1, &cw);
         if ( cw < 1 )
             cw = 1;
+    } else {
+        c = edit_get_byte (edit, edit->curs1);
+    }
+    if (c == '\n') {
+        edit->over_col++;
+    } else {
+        edit_cursor_move (edit, cw);
     }
-    edit_cursor_move (edit, cw);
 }
 
 static void edit_left_char_move_cmd (WEdit * edit)
@@ -2004,7 +2028,11 @@ static void edit_left_char_move_cmd (WEdit * edit)
         if ( cw < 1 )
             cw = 1;
     }
-    edit_cursor_move (edit, -cw);
+    if (edit->over_col > 0) {
+        edit->over_col--;
+    } else {
+        edit_cursor_move (edit, -cw);
+    }
 }
 
 
@@ -2449,6 +2477,8 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
 	    if (edit_get_byte (edit, edit->curs1) != '\n')
 		edit_delete (edit, 0);
 	}
+        if ( edit->over_col > 0 )
+            edit_insert_over (edit);
 #ifdef HAVE_CHARSET
 	if ( char_for_insertion > 255 && utf8_display == 0 ) {
             unsigned char str[6 + 1];
@@ -2538,6 +2568,10 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
                 break;
             }
         }
+        if ( edit->over_col > 0 ) {
+            edit->over_col--;
+            break;
+        }
 	if (option_backspace_through_tabs && is_in_indent (edit)) {
 	    while (edit_get_byte (edit, edit->curs1 - 1) != '\n'
 		   && edit->curs1 > 0)
@@ -2563,6 +2597,10 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
                 break;
             }
         }
+
+        if ( edit->over_col > 0 )
+            edit_insert_over (edit);
+
 	if (option_fake_half_tabs) {
 	    int i;
 	    if (is_in_indent (edit) && left_of_four_spaces (edit)) {
@@ -2623,7 +2661,10 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
     case CK_Left_Highlight:
 	if (option_fake_half_tabs) {
 	    if (is_in_indent (edit) && right_of_four_spaces (edit)) {
-		edit_cursor_move (edit, -HALF_TAB_SIZE);
+	        if ( edit->over_col > 0)
+	            edit->over_col--;
+	        else
+		    edit_cursor_move (edit, -HALF_TAB_SIZE);
 		edit->force &= (0xFFF - REDRAW_CHAR_ONLY);
 		break;
 	    }
@@ -2708,6 +2749,7 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
         if ( edit->mark1 != edit->mark2 && !option_persistent_selections ) {
             edit_move_block_to_right (edit);
         } else {
+            edit_insert_over (edit);
             edit_tab_cmd (edit);
             if (option_auto_para_formatting) {
                 format_paragraph (edit, 0);
@@ -2826,6 +2868,8 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
 	edit_cut_to_X_buf_cmd (edit);
 	break;
     case CK_XPaste:
+        if ( edit->over_col > 0 )
+            edit_insert_over (edit);
 	edit_paste_from_X_buf_cmd (edit);
 	break;
     case CK_Selection_History:

+ 1 - 1
edit/editcmd.c

@@ -953,7 +953,7 @@ int eval_marks (WEdit * edit, long *start_mark, long *end_mark)
 	} else {
 	    *start_mark = min (edit->mark1, edit->curs1);
 	    *end_mark = max (edit->mark1, edit->curs1);
-	    edit->column2 = edit->curs_col;
+	    edit->column2 = edit->curs_col + edit->over_col;
 	}
 	return 0;
     } else {

+ 1 - 3
edit/editdraw.c

@@ -235,7 +235,7 @@ void edit_scroll_screen_over_cursor (WEdit * edit)
 	l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
 	r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
     }
-    p = edit_get_col (edit);
+    p = edit_get_col (edit) + edit->over_col;
     edit_update_curs_row (edit);
     outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
     if (outby > 0)
@@ -429,8 +429,6 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
 		switch (c) {
 		case '\n':
 		    col = (end_col + utf8lag) - edit->start_col + 1;	/* quit */
-		    p->ch = ' ';
-		    p++;
 		    break;
 		case '\t':
 		    i = TAB_SIZE - ((int) col % TAB_SIZE);

+ 10 - 2
edit/editwidget.c

@@ -91,7 +91,15 @@ edit_event (WEdit * edit, Gpm_Event * event, int *result)
     if (event->type & (GPM_DOWN | GPM_UP))
 	edit_push_key_press (edit);
 
-    edit->prev_col = event->x - edit->start_col - 1 - option_line_state_width;
+    long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
+                                        edit_eol(edit, edit->curs1));
+    if ( event->x > line_len ) {
+        edit->over_col = event->x - line_len;
+        edit->prev_col = line_len;
+    } else {
+        edit->over_col = 0;
+        edit->prev_col = event->x;
+    }
 
     if (--event->y > (edit->curs_row + 1))
 	edit_move_down (edit, event->y - (edit->curs_row + 1), 0);
@@ -358,7 +366,7 @@ edit_callback (Widget *w, widget_msg_t msg, int parm)
 
     case WIDGET_CURSOR:
 	widget_move (&e->widget, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET,
-		     e->curs_col + e->start_col);
+		     e->curs_col + e->start_col + e->over_col);
 	return MSG_HANDLED;
 
     case WIDGET_DESTROY: