Merge branch '1534_cool_cooledit'

* 1534_cool_cooledit:
  add option "Cursor beyond end of line" into "Options\General..." dialog (editor_beyond_eol in ini)
  Ticket #1534 (cool cooledit)
This commit is contained in:
Ilia Maslakov 2009-08-17 18:13:23 +00:00
commit 0ff82e59c1
8 changed files with 136 additions and 56 deletions

View File

@ -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 */

View File

@ -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() */
@ -73,6 +78,7 @@ int option_save_mode = EDIT_QUICK_SAVE;
int option_save_position = 1;
int option_max_undo = 32768;
int option_persistent_selections = 1;
int option_cursor_beyond_eol = 1;
int option_line_state = 0;
int option_line_state_width = 0;
@ -699,6 +705,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 +1089,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 +1623,39 @@ 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);
int prev = edit->prev_col;
int over = edit->over_col;
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);
}
edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->curs1);
if (option_cursor_beyond_eol) {
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;
}
} else {
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);
}
}
}
}
/* move i lines */
void edit_move_up (WEdit * edit, unsigned long i, int scroll)
{
@ -1835,6 +1866,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 +1875,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 +1922,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 +2021,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 (option_cursor_beyond_eol && 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 +2044,11 @@ static void edit_left_char_move_cmd (WEdit * edit)
if ( cw < 1 )
cw = 1;
}
edit_cursor_move (edit, -cw);
if (option_cursor_beyond_eol && edit->over_col > 0) {
edit->over_col--;
} else {
edit_cursor_move (edit, -cw);
}
}
@ -2449,6 +2493,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 ( option_cursor_beyond_eol && 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 +2584,10 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
break;
}
}
if ( option_cursor_beyond_eol && 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 +2613,10 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
break;
}
}
if ( option_cursor_beyond_eol && 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 +2677,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 ( option_cursor_beyond_eol && edit->over_col > 0)
edit->over_col--;
else
edit_cursor_move (edit, -HALF_TAB_SIZE);
edit->force &= (0xFFF - REDRAW_CHAR_ONLY);
break;
}
@ -2708,6 +2765,8 @@ 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 {
if ( option_cursor_beyond_eol )
edit_insert_over (edit);
edit_tab_cmd (edit);
if (option_auto_para_formatting) {
format_paragraph (edit, 0);
@ -2826,6 +2885,8 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
edit_cut_to_X_buf_cmd (edit);
break;
case CK_XPaste:
if ( option_cursor_beyond_eol && edit->over_col > 0 )
edit_insert_over (edit);
edit_paste_from_X_buf_cmd (edit);
break;
case CK_Selection_History:

View File

@ -51,6 +51,7 @@ extern int option_return_does_auto_indent;
extern int option_backspace_through_tabs;
extern int option_fake_half_tabs;
extern int option_persistent_selections;
extern int option_cursor_beyond_eol;
extern int option_line_state;
extern int option_save_mode;
extern int option_save_position;

View File

@ -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 {

View File

@ -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);

View File

@ -70,6 +70,7 @@ edit_options_dialog (void)
int tedit_visible_tabs = visible_tabs;
int tedit_visible_tws = visible_tws;
int tedit_persistent_selections = option_persistent_selections;
int tedit_cursor_beyond_eol = option_cursor_beyond_eol;
int toption_return_does_auto_indent = option_return_does_auto_indent;
int toption_backspace_through_tabs = option_backspace_through_tabs;
int toption_fake_half_tabs = option_fake_half_tabs;
@ -83,58 +84,61 @@ edit_options_dialog (void)
{quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), 0,
B_ENTER, 0, 0, NULL, NULL, NULL},
/* 2 */
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H,
N_("Word wrap line length: "), 0, 0, 0, 0, NULL, NULL, NULL},
/* 3 */
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6,
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5,
OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0, "edit-word-wrap", NULL, NULL},
/* 4 */
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H,
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
N_("Tab spacing: "), 0, 0, 0, 0, NULL, NULL, NULL},
/* 5 */
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 7,
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6,
OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0,
"edit-tab-spacing", NULL, NULL},
/* 6 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8,
OPT_DLG_H, N_("Cursor beyond end of line"), 8, 0, 0, 0, NULL, NULL, NULL},
/* 7 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9,
OPT_DLG_H, N_("Pers&istent selection"), 8, 0, 0, 0, NULL, NULL, NULL},
/* 7 */
/* 8 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10,
OPT_DLG_H, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL, NULL, NULL},
/* 8 */
/* 9 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11,
OPT_DLG_H, N_("Visible tabs"), 8, 0, 0, 0, NULL, NULL, NULL},
/* 9 */
/* 10 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12,
OPT_DLG_H, N_("Visible trailing spaces"), 8, 0, 0, 0, NULL, NULL, NULL},
/* 10 */
/* 11 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13,
OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL, NULL, NULL},
/* 11 */
/* 12 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14,
OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL, NULL, NULL},
/* 12 */
/* 13 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 15,
OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL, NULL, NULL},
/* 13 */
/* 14 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 16,
OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL, NULL, NULL},
/* 14 */
/* 15 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 17,
OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
/* 15 */
/* 16 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 18,
OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
/* 16 */
/* 17 */
{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 3, 0, 0,
const_cast(char **, wrap_str), "wrapm", NULL, NULL},
/* 17 */
/* 18 */
{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H,
N_("Wrap mode"), 0, 0, 0, 0, NULL, NULL, NULL},
/* 18 */
/* 19 */
{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H, "", 3, 0, 0,
const_cast(char **, key_emu_str), "keyemu", NULL, NULL},
/* 19 */
/* 20 */
{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H,
N_("Key emulation"), 0, 0, 0, 0, NULL, NULL, NULL},
NULL_QuickWidget
@ -158,16 +162,17 @@ edit_options_dialog (void)
quick_widgets[3].str_result = &p;
quick_widgets[5].text = tab_spacing;
quick_widgets[5].str_result = &q;
quick_widgets[6].result = &tedit_persistent_selections;
quick_widgets[7].result = &tedit_syntax_highlighting;
quick_widgets[8].result = &tedit_visible_tabs;
quick_widgets[9].result = &tedit_visible_tws;
quick_widgets[10].result = &toption_save_position;
quick_widgets[11].result = &tedit_confirm_save;
quick_widgets[12].result = &toption_fill_tabs_with_spaces;
quick_widgets[13].result = &toption_return_does_auto_indent;
quick_widgets[14].result = &toption_backspace_through_tabs;
quick_widgets[15].result = &toption_fake_half_tabs;
quick_widgets[6].result = &tedit_cursor_beyond_eol;
quick_widgets[7].result = &tedit_persistent_selections;
quick_widgets[8].result = &tedit_syntax_highlighting;
quick_widgets[9].result = &tedit_visible_tabs;
quick_widgets[10].result = &tedit_visible_tws;
quick_widgets[11].result = &toption_save_position;
quick_widgets[12].result = &tedit_confirm_save;
quick_widgets[13].result = &toption_fill_tabs_with_spaces;
quick_widgets[14].result = &toption_return_does_auto_indent;
quick_widgets[15].result = &toption_backspace_through_tabs;
quick_widgets[16].result = &toption_fake_half_tabs;
if (option_auto_para_formatting)
wrap_mode = 1;
@ -176,11 +181,11 @@ edit_options_dialog (void)
else
wrap_mode = 0;
quick_widgets[16].result = &wrap_mode;
quick_widgets[16].value = wrap_mode;
quick_widgets[17].result = &wrap_mode;
quick_widgets[17].value = wrap_mode;
quick_widgets[18].result = &tedit_key_emulation;
quick_widgets[18].value = tedit_key_emulation;
quick_widgets[19].result = &tedit_key_emulation;
quick_widgets[19].value = tedit_key_emulation;
Quick_options.widgets = quick_widgets;
@ -200,6 +205,7 @@ edit_options_dialog (void)
g_free (q);
}
option_cursor_beyond_eol = tedit_cursor_beyond_eol;
option_persistent_selections = tedit_persistent_selections;
option_syntax_highlighting = tedit_syntax_highlighting;
visible_tabs = tedit_visible_tabs;

View File

@ -91,7 +91,19 @@ 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;
if (option_cursor_beyond_eol) {
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;
}
} else {
edit->prev_col = event->x - edit->start_col - 1 - option_line_state_width;
}
if (--event->y > (edit->curs_row + 1))
edit_move_down (edit, event->y - (edit->curs_row + 1), 0);
@ -358,7 +370,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:

View File

@ -225,6 +225,7 @@ static const struct {
{ "editor_edit_confirm_save", &edit_confirm_save },
{ "editor_syntax_highlighting", &option_syntax_highlighting },
{ "editor_persistent_selections", &option_persistent_selections },
{ "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
{ "editor_visible_tabs", &visible_tabs },
{ "editor_visible_spaces", &visible_tws },
{ "editor_line_state", &option_line_state },