1
1

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-d3aeb78583b8
Этот коммит содержится в:
David Lawrence Ramsey 2004-05-27 20:09:52 +00:00
родитель c372488179
Коммит 228148b87a
4 изменённых файлов: 35 добавлений и 72 удалений

Просмотреть файл

@ -92,7 +92,7 @@ CVS code -
- Call enable_signals() at the beginning and disable_signals()
at the end, so that we get a SIGINT when Ctrl-C is pressed
during wait() and can then call cancel_fork() properly. (DLR)
do_delete()
do_delete(), do_enter()
- Tweak for efficiency. (David Benbennick)
do_prev_word()
- Switch the last test (current != NULL or not) around to match
@ -275,6 +275,8 @@ CVS code -
- Overhaul for efficiency, (David Benbennick) DLR: Add
reset_cursor() call to ensure that the cursor is always in the
right place.
update_cursor()
- Removed, as it's no longer called anywhere. (David Benbennick)
edit_refresh()
- Remove apparently unneeded leaveok() calls. (David Benbennick)
edit_refresh_clearok(), center_cursor()

Просмотреть файл

@ -1074,77 +1074,61 @@ int do_tab(void)
/* Someone hits return *gasp!* */
int do_enter(void)
{
filestruct *newnode;
char *tmp;
filestruct *newnode = make_new_node(current);
size_t extra = 0;
newnode = make_new_node(current);
assert(current != NULL && current->data != NULL);
tmp = &current->data[current_x];
#ifndef NANO_SMALL
/* Do auto-indenting, like the neolithic Turbo Pascal editor. */
if (ISSET(AUTOINDENT)) {
int extra = 0;
const char *spc = current->data;
while (isblank(*spc)) {
extra++;
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)
/* If we are breaking the line in the indentation, the new
* indentation should have only current_x characters, and
* current_x should not change. */
extra = indent_length(current->data);
if (extra > current_x)
extra = current_x;
else
current_x = 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(&current->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;
splice_node(current, newnode, current->next);
totsize++;
renumber(current);
current = newnode;
align(&current->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
if (ISSET(SMOOTHSCROLL))
edit_update(current, NONE);
else
/* If we're in smooth scrolling mode and we're on the last line of
* the edit window, move edittop down one line so that current is
* onscreen. This prevents edit_refresh() from centering the
* screen. */
if (ISSET(SMOOTHSCROLL) && current_y == editwinrows - 1)
edittop = edittop->next;
#endif
edit_update(current, CENTER);
reset_cursor();
} else {
current_y++;
edit_refresh();
update_cursor();
}
edit_refresh();
totlines++;
set_modified();
placewewant = xplustabs();
return 1;
}

Просмотреть файл

@ -513,7 +513,6 @@ void reset_cursor(void);
void edit_add(const filestruct *fileptr, const char *converted, int
yval, size_t start);
void update_line(const filestruct *fileptr, size_t index);
void update_cursor(void);
void edit_refresh(void);
void edit_update(filestruct *fileptr, topmidnone location);
int statusq(int allowtabs, const shortcut *s, const char *def,

Просмотреть файл

@ -2195,28 +2195,6 @@ void update_line(const filestruct *fileptr, size_t index)
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. */
void edit_refresh(void)
{