DB's movement code overhaul (smooth paging, etc.) with a few of my fixes
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1546 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
dc9c40a56d
commit
d91ab6e912
20
ChangeLog
20
ChangeLog
|
@ -55,6 +55,9 @@ CVS code -
|
||||||
- Set keypad() to TRUE regardless of whether PDCurses is being
|
- Set keypad() to TRUE regardless of whether PDCurses is being
|
||||||
used, as Meta-X apparently turns it off even under ncurses.
|
used, as Meta-X apparently turns it off even under ncurses.
|
||||||
(DLR)
|
(DLR)
|
||||||
|
do_backspace()
|
||||||
|
- Vastly simplify, and remove dependency on page_up(). (David
|
||||||
|
Benbennick)
|
||||||
help_init()
|
help_init()
|
||||||
- Document the support for Esc Esc [character]'s being
|
- Document the support for Esc Esc [character]'s being
|
||||||
interpreted as Ctrl-[character], and the support for Pico's
|
interpreted as Ctrl-[character], and the support for Pico's
|
||||||
|
@ -66,6 +69,17 @@ CVS code -
|
||||||
KEY_RESIZE, and pressing Ctrl-Z to suspend nano at the Linux
|
KEY_RESIZE, and pressing Ctrl-Z to suspend nano at the Linux
|
||||||
console with keypad(TRUE) generates Ctrl-Z instead of
|
console with keypad(TRUE) generates Ctrl-Z instead of
|
||||||
KEY_SUSPEND, both unlike ncurses. (DLR)
|
KEY_SUSPEND, both unlike ncurses. (DLR)
|
||||||
|
- move.c:
|
||||||
|
- Remove unneeded inclusion of stdio.h, make various cleanups,
|
||||||
|
and preserve the cursor's coordinates when paging up and down.
|
||||||
|
(David Benbennick) DLR: Readd the ability to behave the old
|
||||||
|
way while paging, make it so the new behavior is only used in
|
||||||
|
smooth-scrolling mode, and modify page_down() to always go
|
||||||
|
down a full page (even when there's less than one page of text
|
||||||
|
left) for consistency.
|
||||||
|
page_up()
|
||||||
|
- Removed due to rewrite of movement functions. (David
|
||||||
|
Benbennick)
|
||||||
- rcfile.c:
|
- rcfile.c:
|
||||||
parse_colors()
|
parse_colors()
|
||||||
- Generate an error if we try to use a bright background color
|
- Generate an error if we try to use a bright background color
|
||||||
|
@ -73,9 +87,15 @@ CVS code -
|
||||||
- Make sure all rcfile error messages are capitalized, for
|
- Make sure all rcfile error messages are capitalized, for
|
||||||
consistency. (DLR)
|
consistency. (DLR)
|
||||||
- winio.c:
|
- winio.c:
|
||||||
|
do_first_line()
|
||||||
|
- Call edit_update() with TOP instead of CENTER; both do the
|
||||||
|
same thing, but it works faster with TOP. (DLR)
|
||||||
titlebar()
|
titlebar()
|
||||||
- Fix problem with the available space for a filename on the
|
- Fix problem with the available space for a filename on the
|
||||||
titlebar's being short by one. (DLR)
|
titlebar's being short by one. (DLR)
|
||||||
|
edit_update()
|
||||||
|
- Tweak for efficiency and remove the fix_editbot() call. (David
|
||||||
|
Benbennick)
|
||||||
do_credits()
|
do_credits()
|
||||||
- Update the copyright years to "1999-2003", to match those
|
- Update the copyright years to "1999-2003", to match those
|
||||||
given in the rest of the code. (DLR)
|
given in the rest of the code. (DLR)
|
||||||
|
|
199
src/move.c
199
src/move.c
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "nano.h"
|
#include "nano.h"
|
||||||
|
@ -32,6 +31,7 @@ int do_home(void)
|
||||||
{
|
{
|
||||||
current_x = 0;
|
current_x = 0;
|
||||||
placewewant = 0;
|
placewewant = 0;
|
||||||
|
check_statblank();
|
||||||
update_line(current, current_x);
|
update_line(current, current_x);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -40,52 +40,48 @@ int do_end(void)
|
||||||
{
|
{
|
||||||
current_x = strlen(current->data);
|
current_x = strlen(current->data);
|
||||||
placewewant = xplustabs();
|
placewewant = xplustabs();
|
||||||
|
check_statblank();
|
||||||
update_line(current, current_x);
|
update_line(current, current_x);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void page_up(void)
|
|
||||||
{
|
|
||||||
if (edittop != fileage) {
|
|
||||||
#ifndef NANO_SMALL
|
|
||||||
if (ISSET(SMOOTHSCROLL))
|
|
||||||
edit_update(edittop->prev, TOP);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
edit_update(edittop, CENTER);
|
|
||||||
/* Now that we've updated the edit window, edittop might be
|
|
||||||
at the top of the file; if so, just move the cursor up one
|
|
||||||
line and don't center it. */
|
|
||||||
if (edittop != fileage)
|
|
||||||
center_cursor();
|
|
||||||
else
|
|
||||||
reset_cursor();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
current_y = 0;
|
|
||||||
|
|
||||||
update_cursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
int do_page_up(void)
|
int do_page_up(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
wrap_reset();
|
wrap_reset();
|
||||||
current_x = 0;
|
|
||||||
placewewant = 0;
|
|
||||||
|
|
||||||
if (current == fileage)
|
/* If edittop is the first line of the file, move current up there
|
||||||
return 0;
|
* and put the cursor at the beginning of the line. */
|
||||||
|
if (edittop == fileage) {
|
||||||
|
current = fileage;
|
||||||
|
placewewant = 0;
|
||||||
|
} else {
|
||||||
|
/* Move the top line of the edit window up a page. */
|
||||||
|
for (i = 0; i < editwinrows - 2 && edittop->prev != NULL; i++)
|
||||||
|
edittop = edittop->prev;
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
/* If we're in smooth scrolling mode and there was at least one
|
||||||
|
* page of text left, move the current line of the edit window
|
||||||
|
* up a page. */
|
||||||
|
if (ISSET(SMOOTHSCROLL) && current->lineno > editwinrows - 2)
|
||||||
|
for (i = 0; i < editwinrows - 2; i++)
|
||||||
|
current = current->prev;
|
||||||
|
/* If we're not in smooth scrolling mode and there was at least
|
||||||
|
* one page of text left, put the cursor at the beginning of the
|
||||||
|
* top line of the edit window, as Pico does. */
|
||||||
|
else {
|
||||||
|
#endif
|
||||||
|
current = edittop;
|
||||||
|
placewewant = 0;
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
/* Get the equivalent x-coordinate of the new line. */
|
||||||
|
current_x = actual_x(current, placewewant);
|
||||||
|
|
||||||
current_y = 0;
|
edit_refresh();
|
||||||
current = edittop;
|
|
||||||
for (i = 0; i <= editwinrows - 3 && current->prev != NULL; i++)
|
|
||||||
current = current->prev;
|
|
||||||
|
|
||||||
edit_update(current, TOP);
|
|
||||||
update_cursor();
|
|
||||||
|
|
||||||
check_statblank();
|
check_statblank();
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -93,42 +89,42 @@ int do_page_up(void)
|
||||||
|
|
||||||
int do_page_down(void)
|
int do_page_down(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
wrap_reset();
|
wrap_reset();
|
||||||
current_x = 0;
|
|
||||||
placewewant = 0;
|
|
||||||
|
|
||||||
if (current == filebot)
|
/* If the last line of the file is onscreen, move current down
|
||||||
return 0;
|
* there and put the cursor at the beginning of the line. */
|
||||||
|
if (edittop->lineno + editwinrows > filebot->lineno) {
|
||||||
/* AHEM, if we only have a screen or less of text, DON'T do an
|
current = filebot;
|
||||||
edit_update(), just move the cursor to editbot! */
|
placewewant = 0;
|
||||||
if (edittop == fileage && editbot == filebot && totlines < editwinrows) {
|
|
||||||
current = editbot;
|
|
||||||
reset_cursor();
|
|
||||||
#ifndef NANO_SMALL
|
|
||||||
/* ...unless marking is on, in which case we need it to update
|
|
||||||
the highlight. */
|
|
||||||
if (ISSET(MARK_ISSET))
|
|
||||||
edit_update(current, NONE);
|
|
||||||
#endif
|
|
||||||
} else if (editbot != filebot || edittop == fileage) {
|
|
||||||
current_y = 0;
|
|
||||||
current = editbot;
|
|
||||||
|
|
||||||
if (current->prev != NULL)
|
|
||||||
current = current->prev;
|
|
||||||
if (current->prev != NULL)
|
|
||||||
current = current->prev;
|
|
||||||
edit_update(current, TOP);
|
|
||||||
} else {
|
} else {
|
||||||
while (current != filebot) {
|
/* Move the top line of the edit window down a page. */
|
||||||
current = current->next;
|
for (i = 0; i < editwinrows - 2; i++)
|
||||||
current_y++;
|
edittop = edittop->next;
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
/* If we're in smooth scrolling mode and there was at least one
|
||||||
|
* page of text left, move the current line of the edit window
|
||||||
|
* down a page. */
|
||||||
|
if (ISSET(SMOOTHSCROLL) && current->lineno + editwinrows - 2 <= filebot->lineno)
|
||||||
|
for (i = 0; i < editwinrows - 2; i++)
|
||||||
|
current = current->next;
|
||||||
|
/* If we're not in smooth scrolling mode and there was at least
|
||||||
|
* one page of text left, put the cursor at the beginning of the
|
||||||
|
* top line of the edit window, as Pico does. */
|
||||||
|
else {
|
||||||
|
#endif
|
||||||
|
current = edittop;
|
||||||
|
placewewant = 0;
|
||||||
|
#ifndef NANO_SMALL
|
||||||
}
|
}
|
||||||
edit_update(edittop, TOP);
|
#endif
|
||||||
}
|
}
|
||||||
|
/* Get the equivalent x-coordinate of the new line. */
|
||||||
|
current_x = actual_x(current, placewewant);
|
||||||
|
|
||||||
|
edit_refresh();
|
||||||
|
|
||||||
update_cursor();
|
|
||||||
check_statblank();
|
check_statblank();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -136,19 +132,26 @@ int do_page_down(void)
|
||||||
int do_up(void)
|
int do_up(void)
|
||||||
{
|
{
|
||||||
wrap_reset();
|
wrap_reset();
|
||||||
if (current->prev != NULL) {
|
check_statblank();
|
||||||
current_x = actual_x(current->prev, placewewant);
|
|
||||||
current = current->prev;
|
if (current->prev == NULL)
|
||||||
if (current_y > 0) {
|
return 0;
|
||||||
update_line(current->next, 0);
|
|
||||||
/* It is necessary to change current first, so the mark
|
assert(current_y == current->lineno - edittop->lineno);
|
||||||
display will change! */
|
current = current->prev;
|
||||||
current_y--;
|
current_x = actual_x(current, placewewant);
|
||||||
update_line(current, current_x);
|
if (current_y > 0) {
|
||||||
} else
|
update_line(current->next, 0);
|
||||||
page_up();
|
/* It was necessary to change current first, so the mark
|
||||||
check_statblank();
|
* display will change! */
|
||||||
}
|
update_line(current, current_x);
|
||||||
|
} else
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
if (ISSET(SMOOTHSCROLL))
|
||||||
|
edit_update(current, TOP);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
edit_update(current, CENTER);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,32 +165,24 @@ int do_down(void)
|
||||||
if (current->next == NULL)
|
if (current->next == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
assert(current_y == current->lineno - edittop->lineno);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
current_x = actual_x(current, placewewant);
|
current_x = actual_x(current, placewewant);
|
||||||
|
|
||||||
/* Note current_y is zero-based. This test checks for the cursor's
|
/* Note that current_y is zero-based. This test checks for the
|
||||||
* being on the last row of the edit window. */
|
* cursor's being not on the last row of the edit window. */
|
||||||
if (current_y == editwinrows - 1) {
|
if (current_y != editwinrows - 1) {
|
||||||
#ifndef NANO_SMALL
|
|
||||||
if (ISSET(SMOOTHSCROLL)) {
|
|
||||||
/* In this case current_y does not change. The cursor
|
|
||||||
* remains at the bottom of the edit window. */
|
|
||||||
edittop = edittop->next;
|
|
||||||
editbot = editbot->next;
|
|
||||||
edit_refresh();
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Set edittop so editbot->next (or else editbot) is
|
|
||||||
* centered, and set current_y = editwinrows / 2. */
|
|
||||||
edit_update(editbot->next != NULL ? editbot->next : editbot, CENTER);
|
|
||||||
center_cursor();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
update_line(current->prev, 0);
|
update_line(current->prev, 0);
|
||||||
update_line(current, current_x);
|
update_line(current, current_x);
|
||||||
current_y++;
|
} else
|
||||||
}
|
#ifndef NANO_SMALL
|
||||||
|
if (ISSET(SMOOTHSCROLL))
|
||||||
|
/* In this case current_y does not change. The cursor remains
|
||||||
|
* at the bottom of the edit window. */
|
||||||
|
edit_update(edittop->next, TOP);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
edit_update(current, CENTER);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,8 +195,8 @@ int do_left(void)
|
||||||
current_x = strlen(current->data);
|
current_x = strlen(current->data);
|
||||||
}
|
}
|
||||||
placewewant = xplustabs();
|
placewewant = xplustabs();
|
||||||
update_line(current, current_x);
|
|
||||||
check_statblank();
|
check_statblank();
|
||||||
|
update_line(current, current_x);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +211,7 @@ int do_right(void)
|
||||||
current_x = 0;
|
current_x = 0;
|
||||||
}
|
}
|
||||||
placewewant = xplustabs();
|
placewewant = xplustabs();
|
||||||
update_line(current, current_x);
|
|
||||||
check_statblank();
|
check_statblank();
|
||||||
|
update_line(current, current_x);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
76
src/nano.c
76
src/nano.c
|
@ -1018,82 +1018,10 @@ void do_char(char ch)
|
||||||
|
|
||||||
int do_backspace(void)
|
int do_backspace(void)
|
||||||
{
|
{
|
||||||
int refresh = 0;
|
if (current != fileage || current_x > 0) {
|
||||||
if (current_x > 0) {
|
|
||||||
assert(current_x <= strlen(current->data));
|
|
||||||
/* Let's get dangerous */
|
|
||||||
memmove(¤t->data[current_x - 1], ¤t->data[current_x],
|
|
||||||
strlen(current->data) - current_x + 1);
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stderr, "current->data now = \"%s\"\n", current->data);
|
|
||||||
#endif
|
|
||||||
align(¤t->data);
|
|
||||||
#ifndef NANO_SMALL
|
|
||||||
if (current_x <= mark_beginx && mark_beginbuf == current)
|
|
||||||
mark_beginx--;
|
|
||||||
#endif
|
|
||||||
do_left();
|
do_left();
|
||||||
#ifdef ENABLE_COLOR
|
do_delete();
|
||||||
refresh = 1;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
filestruct *previous;
|
|
||||||
const filestruct *tmp;
|
|
||||||
|
|
||||||
if (current == fileage)
|
|
||||||
return 0; /* Can't delete past top of file */
|
|
||||||
|
|
||||||
previous = current->prev;
|
|
||||||
current_x = strlen(previous->data);
|
|
||||||
placewewant = strlenpt(previous->data);
|
|
||||||
#ifndef NANO_SMALL
|
|
||||||
if (current == mark_beginbuf) {
|
|
||||||
mark_beginx += current_x;
|
|
||||||
mark_beginbuf = previous;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
previous->data = charealloc(previous->data,
|
|
||||||
current_x + strlen(current->data) + 1);
|
|
||||||
strcpy(previous->data + current_x, current->data);
|
|
||||||
|
|
||||||
unlink_node(current);
|
|
||||||
delete_node(current);
|
|
||||||
tmp = current;
|
|
||||||
current = (previous->next ? previous->next : previous);
|
|
||||||
renumber(current);
|
|
||||||
/* We had to renumber before doing update_line. */
|
|
||||||
if (tmp == edittop)
|
|
||||||
page_up();
|
|
||||||
|
|
||||||
/* Ooops, sanity check */
|
|
||||||
if (tmp == filebot) {
|
|
||||||
filebot = current;
|
|
||||||
editbot = current;
|
|
||||||
|
|
||||||
/* Recreate the magic line if we're deleting it AND if the
|
|
||||||
line we're on now is NOT blank. if it is blank we
|
|
||||||
can just use IT for the magic line. This is how Pico
|
|
||||||
appears to do it, in any case. */
|
|
||||||
if (current->data[0] != '\0') {
|
|
||||||
new_magicline();
|
|
||||||
fix_editbot();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current = previous;
|
|
||||||
if (current_y > 0)
|
|
||||||
current_y--;
|
|
||||||
totlines--;
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stderr, "After, data = \"%s\"\n", current->data);
|
|
||||||
#endif
|
|
||||||
refresh = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
totsize--;
|
|
||||||
set_modified();
|
|
||||||
if (refresh)
|
|
||||||
edit_refresh();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
/* Macros for the flags int... */
|
/* Macros for the flags int... */
|
||||||
#define SET(bit) flags |= bit
|
#define SET(bit) flags |= bit
|
||||||
#define UNSET(bit) flags &= ~bit
|
#define UNSET(bit) flags &= ~bit
|
||||||
#define ISSET(bit) (flags & bit)
|
#define ISSET(bit) ((flags & bit) != 0)
|
||||||
#define TOGGLE(bit) flags ^= bit
|
#define TOGGLE(bit) flags ^= bit
|
||||||
|
|
||||||
/* Define charalloc as a macro rather than duplicating code */
|
/* Define charalloc as a macro rather than duplicating code */
|
||||||
|
|
|
@ -221,7 +221,6 @@ void thanks_for_all_the_fish(void);
|
||||||
/* Public functions in move.c */
|
/* Public functions in move.c */
|
||||||
int do_home(void);
|
int do_home(void);
|
||||||
int do_end(void);
|
int do_end(void);
|
||||||
void page_up(void);
|
|
||||||
int do_page_up(void);
|
int do_page_up(void);
|
||||||
int do_page_down(void);
|
int do_page_down(void);
|
||||||
int do_up(void);
|
int do_up(void);
|
||||||
|
|
|
@ -322,7 +322,7 @@ int do_first_line(void)
|
||||||
current = fileage;
|
current = fileage;
|
||||||
placewewant = 0;
|
placewewant = 0;
|
||||||
current_x = 0;
|
current_x = 0;
|
||||||
edit_update(current, CENTER);
|
edit_update(current, TOP);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1387,14 +1387,12 @@ void edit_update(filestruct *fileptr, topmidbotnone location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (location != TOP) {
|
if (location != TOP) {
|
||||||
int goal = location == NONE ? current_y - 1 : editwinrows / 2;
|
int goal = location == NONE ? current_y : editwinrows / 2;
|
||||||
|
|
||||||
for (; goal >= 0 && fileptr->prev != NULL; goal--)
|
for (; goal > 0 && fileptr->prev != NULL; goal--)
|
||||||
fileptr = fileptr->prev;
|
fileptr = fileptr->prev;
|
||||||
}
|
}
|
||||||
edittop = fileptr;
|
edittop = fileptr;
|
||||||
fix_editbot();
|
|
||||||
|
|
||||||
edit_refresh();
|
edit_refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue