- Set keypad() to TRUE regardless of whether PDCurses is being
used, as Meta-X apparently turns it off even under ncurses.
(DLR)
+ do_backspace()
+ - Vastly simplify, and remove dependency on page_up(). (David
+ Benbennick)
help_init()
- Document the support for Esc Esc [character]'s being
interpreted as Ctrl-[character], and the support for Pico's
KEY_RESIZE, and pressing Ctrl-Z to suspend nano at the Linux
console with keypad(TRUE) generates Ctrl-Z instead of
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:
parse_colors()
- Generate an error if we try to use a bright background color
- Make sure all rcfile error messages are capitalized, for
consistency. (DLR)
- 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()
- Fix problem with the available space for a filename on the
titlebar's being short by one. (DLR)
+ edit_update()
+ - Tweak for efficiency and remove the fix_editbot() call. (David
+ Benbennick)
do_credits()
- Update the copyright years to "1999-2003", to match those
given in the rest of the code. (DLR)
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
#include <assert.h>
#include "proto.h"
#include "nano.h"
{
current_x = 0;
placewewant = 0;
+ check_statblank();
update_line(current, current_x);
return 1;
}
{
current_x = strlen(current->data);
placewewant = xplustabs();
+ check_statblank();
update_line(current, current_x);
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 i;
wrap_reset();
- current_x = 0;
- placewewant = 0;
- if (current == fileage)
- return 0;
-
- current_y = 0;
- current = edittop;
- for (i = 0; i <= editwinrows - 3 && current->prev != NULL; i++)
- current = current->prev;
+ /* If edittop is the first line of the file, move current up there
+ * 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);
- edit_update(current, TOP);
- update_cursor();
+ edit_refresh();
check_statblank();
return 1;
int do_page_down(void)
{
- wrap_reset();
- current_x = 0;
- placewewant = 0;
+ int i;
- if (current == filebot)
- return 0;
+ wrap_reset();
- /* AHEM, if we only have a screen or less of text, DON'T do an
- edit_update(), just move the cursor to editbot! */
- if (edittop == fileage && editbot == filebot && totlines < editwinrows) {
- current = editbot;
- reset_cursor();
+ /* If the last line of the file is onscreen, move current down
+ * there and put the cursor at the beginning of the line. */
+ if (edittop->lineno + editwinrows > filebot->lineno) {
+ current = filebot;
+ placewewant = 0;
+ } else {
+ /* Move the top line of the edit window down a page. */
+ for (i = 0; i < editwinrows - 2; i++)
+ edittop = edittop->next;
#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);
+ /* 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
- } 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 {
- while (current != filebot) {
- current = current->next;
- current_y++;
+ 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();
return 1;
}
int do_up(void)
{
wrap_reset();
- if (current->prev != NULL) {
- current_x = actual_x(current->prev, placewewant);
- current = current->prev;
- if (current_y > 0) {
- update_line(current->next, 0);
- /* It is necessary to change current first, so the mark
- display will change! */
- current_y--;
- update_line(current, current_x);
- } else
- page_up();
- check_statblank();
- }
+ check_statblank();
+
+ if (current->prev == NULL)
+ return 0;
+
+ assert(current_y == current->lineno - edittop->lineno);
+ current = current->prev;
+ current_x = actual_x(current, placewewant);
+ if (current_y > 0) {
+ update_line(current->next, 0);
+ /* It was necessary to change current first, so the mark
+ * 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;
}
if (current->next == NULL)
return 0;
+ assert(current_y == current->lineno - edittop->lineno);
current = current->next;
current_x = actual_x(current, placewewant);
- /* Note current_y is zero-based. This test checks for the cursor's
- * being on the last row of the edit window. */
- 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 {
+ /* Note that current_y is zero-based. This test checks for the
+ * cursor's being not on the last row of the edit window. */
+ if (current_y != editwinrows - 1) {
update_line(current->prev, 0);
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;
}
current_x = strlen(current->data);
}
placewewant = xplustabs();
- update_line(current, current_x);
check_statblank();
+ update_line(current, current_x);
return 1;
}
current_x = 0;
}
placewewant = xplustabs();
- update_line(current, current_x);
check_statblank();
+ update_line(current, current_x);
return 1;
}
int do_backspace(void)
{
- int refresh = 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
+ if (current != fileage || current_x > 0) {
do_left();
-#ifdef ENABLE_COLOR
- 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;
+ do_delete();
}
-
- totsize--;
- set_modified();
- if (refresh)
- edit_refresh();
return 1;
}