- 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
- 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()
/* 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 = ¤t->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);
+ }
+#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);
- strcpy(&newnode->data[extra], tmp);
- } else
#endif
- {
- current_x = 0;
- newnode->data = charalloc(strlen(tmp) + 1);
- strcpy(newnode->data, tmp);
+ 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;
}
- *tmp = '\0';
+#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(¤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
- if (ISSET(SMOOTHSCROLL))
- edit_update(current, NONE);
- else
+
+#ifndef NANO_SMALL
+ /* 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;
}
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)
{