add DB's tweaks to do_enter() and remove the now-unused center_cursor()
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1769 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
c372488179
commit
228148b87a
|
@ -92,7 +92,7 @@ CVS code -
|
||||||
- Call enable_signals() at the beginning and disable_signals()
|
- Call enable_signals() at the beginning and disable_signals()
|
||||||
at the end, so that we get a SIGINT when Ctrl-C is pressed
|
at the end, so that we get a SIGINT when Ctrl-C is pressed
|
||||||
during wait() and can then call cancel_fork() properly. (DLR)
|
during wait() and can then call cancel_fork() properly. (DLR)
|
||||||
do_delete()
|
do_delete(), do_enter()
|
||||||
- Tweak for efficiency. (David Benbennick)
|
- Tweak for efficiency. (David Benbennick)
|
||||||
do_prev_word()
|
do_prev_word()
|
||||||
- Switch the last test (current != NULL or not) around to match
|
- Switch the last test (current != NULL or not) around to match
|
||||||
|
@ -275,6 +275,8 @@ CVS code -
|
||||||
- Overhaul for efficiency, (David Benbennick) DLR: Add
|
- Overhaul for efficiency, (David Benbennick) DLR: Add
|
||||||
reset_cursor() call to ensure that the cursor is always in the
|
reset_cursor() call to ensure that the cursor is always in the
|
||||||
right place.
|
right place.
|
||||||
|
update_cursor()
|
||||||
|
- Removed, as it's no longer called anywhere. (David Benbennick)
|
||||||
edit_refresh()
|
edit_refresh()
|
||||||
- Remove apparently unneeded leaveok() calls. (David Benbennick)
|
- Remove apparently unneeded leaveok() calls. (David Benbennick)
|
||||||
edit_refresh_clearok(), center_cursor()
|
edit_refresh_clearok(), center_cursor()
|
||||||
|
|
80
src/nano.c
80
src/nano.c
|
@ -1074,77 +1074,61 @@ int do_tab(void)
|
||||||
/* Someone hits return *gasp!* */
|
/* Someone hits return *gasp!* */
|
||||||
int do_enter(void)
|
int do_enter(void)
|
||||||
{
|
{
|
||||||
filestruct *newnode;
|
filestruct *newnode = make_new_node(current);
|
||||||
char *tmp;
|
size_t extra = 0;
|
||||||
|
|
||||||
newnode = make_new_node(current);
|
|
||||||
assert(current != NULL && current->data != NULL);
|
assert(current != NULL && current->data != NULL);
|
||||||
tmp = ¤t->data[current_x];
|
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* Do auto-indenting, like the neolithic Turbo Pascal editor. */
|
/* Do auto-indenting, like the neolithic Turbo Pascal editor. */
|
||||||
if (ISSET(AUTOINDENT)) {
|
if (ISSET(AUTOINDENT)) {
|
||||||
int extra = 0;
|
/* If we are breaking the line in the indentation, the new
|
||||||
const char *spc = current->data;
|
* indentation should have only current_x characters, and
|
||||||
|
* current_x should not change. */
|
||||||
while (isblank(*spc)) {
|
extra = indent_length(current->data);
|
||||||
extra++;
|
if (extra > current_x)
|
||||||
spc++;
|
|
||||||
}
|
|
||||||
/* If current_x < extra, then we are breaking the line in the
|
|
||||||
* indentation. Autoindenting should add only current_x
|
|
||||||
* characters of indentation. */
|
|
||||||
if (current_x < extra)
|
|
||||||
extra = current_x;
|
extra = current_x;
|
||||||
else
|
|
||||||
current_x = extra;
|
|
||||||
totsize += extra;
|
totsize += extra;
|
||||||
|
|
||||||
newnode->data = charalloc(strlen(tmp) + extra + 1);
|
|
||||||
strncpy(newnode->data, current->data, extra);
|
|
||||||
strcpy(&newnode->data[extra], tmp);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
current_x = 0;
|
|
||||||
newnode->data = charalloc(strlen(tmp) + 1);
|
|
||||||
strcpy(newnode->data, tmp);
|
|
||||||
}
|
}
|
||||||
*tmp = '\0';
|
#endif
|
||||||
|
newnode->data = charalloc(strlen(current->data + current_x) +
|
||||||
|
extra + 1);
|
||||||
|
strcpy(&newnode->data[extra], current->data + current_x);
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
if (ISSET(AUTOINDENT))
|
||||||
|
strncpy(newnode->data, current->data, extra);
|
||||||
|
#endif
|
||||||
|
null_at(¤t->data, current_x);
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
if (current == mark_beginbuf && current_x < mark_beginx) {
|
||||||
|
mark_beginbuf = newnode;
|
||||||
|
mark_beginx += extra - current_x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
current_x = extra;
|
||||||
|
|
||||||
if (current->next == NULL)
|
if (current == filebot)
|
||||||
filebot = newnode;
|
filebot = newnode;
|
||||||
splice_node(current, newnode, current->next);
|
splice_node(current, newnode, current->next);
|
||||||
|
|
||||||
totsize++;
|
totsize++;
|
||||||
renumber(current);
|
renumber(current);
|
||||||
current = newnode;
|
current = newnode;
|
||||||
align(¤t->data);
|
|
||||||
|
|
||||||
/* The logic here is as follows:
|
|
||||||
* -> If we are at the bottom of the buffer, we want to recenter
|
|
||||||
* (read: rebuild) the screen and forcibly move the cursor.
|
|
||||||
* -> otherwise, we want simply to redraw the screen and update
|
|
||||||
* where we think the cursor is.
|
|
||||||
*/
|
|
||||||
if (current_y == editwinrows - 1) {
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
if (ISSET(SMOOTHSCROLL))
|
/* If we're in smooth scrolling mode and we're on the last line of
|
||||||
edit_update(current, NONE);
|
* the edit window, move edittop down one line so that current is
|
||||||
else
|
* onscreen. This prevents edit_refresh() from centering the
|
||||||
|
* screen. */
|
||||||
|
if (ISSET(SMOOTHSCROLL) && current_y == editwinrows - 1)
|
||||||
|
edittop = edittop->next;
|
||||||
#endif
|
#endif
|
||||||
edit_update(current, CENTER);
|
edit_refresh();
|
||||||
reset_cursor();
|
|
||||||
} else {
|
|
||||||
current_y++;
|
|
||||||
edit_refresh();
|
|
||||||
update_cursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
totlines++;
|
totlines++;
|
||||||
set_modified();
|
set_modified();
|
||||||
|
|
||||||
placewewant = xplustabs();
|
placewewant = xplustabs();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -513,7 +513,6 @@ void reset_cursor(void);
|
||||||
void edit_add(const filestruct *fileptr, const char *converted, int
|
void edit_add(const filestruct *fileptr, const char *converted, int
|
||||||
yval, size_t start);
|
yval, size_t start);
|
||||||
void update_line(const filestruct *fileptr, size_t index);
|
void update_line(const filestruct *fileptr, size_t index);
|
||||||
void update_cursor(void);
|
|
||||||
void edit_refresh(void);
|
void edit_refresh(void);
|
||||||
void edit_update(filestruct *fileptr, topmidnone location);
|
void edit_update(filestruct *fileptr, topmidnone location);
|
||||||
int statusq(int allowtabs, const shortcut *s, const char *def,
|
int statusq(int allowtabs, const shortcut *s, const char *def,
|
||||||
|
|
22
src/winio.c
22
src/winio.c
|
@ -2195,28 +2195,6 @@ void update_line(const filestruct *fileptr, size_t index)
|
||||||
mvwaddch(edit, line, COLS - 1, '$');
|
mvwaddch(edit, line, COLS - 1, '$');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function updates current, based on where current_y is;
|
|
||||||
* reset_cursor() does the opposite. */
|
|
||||||
void update_cursor(void)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stderr, "Moved to (%d, %d) in edit buffer\n", current_y,
|
|
||||||
current_x);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
current = edittop;
|
|
||||||
while (i < current_y && current->next != NULL) {
|
|
||||||
current = current->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stderr, "current->data = \"%s\"\n", current->data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Refresh the screen without changing the position of lines. */
|
/* Refresh the screen without changing the position of lines. */
|
||||||
void edit_refresh(void)
|
void edit_refresh(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue