[prev in list] [next in list] [prev in thread] [next in thread]
List: nano-devel
Subject: Re: [Nano-devel] undoings of do_wrap()
From: Mark Majeres <mark () engine12 ! com>
Date: 2014-06-14 15:36:20
Message-ID: CAG40++H9xuObD6M=Q+k-WhiBHQ0KHJACMQw0wb4L6uG9BwGi9Q () mail ! gmail ! com
[Download RAW message or body]
Benno,
The attached patch should resolve these issues.
-Mark Majeres
On 6/9/14, Benno Schulenberg <bensberg@justemail.net> wrote:
> It works nicely. The only thing I don't like is that, when undoing
> text additions that caused line wraps, it says on the status line:
> "Undid action (line wrap)". It should say "Undid action (text add)"
> instead -- the line wrapping is only a side effect of the adding of
> text. The linewrap and the textadd get undone together, which is
> good, but the latter gets undone last, and is what the user actually
> did, so this is what should get mentioned on the status line. But I
> don't see how to easily fix that.
> Something else. Select some words with the mark, hit M-6, and
> then paste them into the line with multiple ^Us (while you have
> started nano with something like -r44). When the line becomes
> overlong, it does not wrap, it just grows and grows. Type ^Us
> until the line is more than 200 characters long. Then type a
> letter, the line breaks once; type another letter, the line breaks
> again; and so on, until it is fully chopped up. This has always
> been this way, but it is very odd behaviour. I think a ^U should
> behave as if all the inserted stuff had been typed in. But maybe
> that is hard to make, so don't bother with it if it's complicated.
["undoredo.wrap.4962.patch" (text/x-patch)]
Index: src/cut.c
===================================================================
--- src/cut.c (revision 4962)
+++ src/cut.c (working copy)
@@ -280,6 +280,11 @@
update_undo(PASTE);
#endif
+#ifndef DISABLE_WRAPPING
+ if (!ISSET(NO_WRAP))
+ do_wrap(openfile->current);
+#endif
+
/* Set the current place we want to where the text from the
* cutbuffer ends. */
openfile->placewewant = xplustabs();
Index: src/text.c
===================================================================
--- src/text.c (revision 4962)
+++ src/text.c (working copy)
@@ -439,7 +439,7 @@
undo *u = openfile->current_undo;
filestruct *t = 0;
size_t len = 0;
- char *undidmsg, *data;
+ char *undidmsg=NULL, *data;
filestruct *oldcutbuffer = cutbuffer, *oldcutbottom = cutbottom;
if (!u) {
@@ -483,7 +483,6 @@
break;
#ifndef DISABLE_WRAPPING
case SPLIT_END:
- undidmsg = _("line wrap");
goto_line_posx(u->lineno, u->begin);
openfile->current_undo = openfile->current_undo->next;
openfile->last_action = OTHER;
@@ -491,6 +490,7 @@
do_undo();
u = openfile->current_undo;
f = openfile->current;
+ case SPLIT_BEGIN:
break;
#endif /* !DISABLE_WRAPPING */
case UNSPLIT:
@@ -557,6 +557,7 @@
renumber(f);
if (gotolinecolumn)
do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE);
+ if(undidmsg)
statusbar(_("Undid action (%s)"), undidmsg);
openfile->current_undo = openfile->current_undo->next;
openfile->last_action = OTHER;
@@ -569,7 +570,7 @@
bool gotolinecolumn = FALSE;
undo *u = openfile->undotop;
size_t len = 0;
- char *undidmsg, *data;
+ char *undidmsg=NULL, *data;
for (; u != NULL && u->next != openfile->current_undo; u = u->next)
;
@@ -624,7 +625,6 @@
break;
#ifndef DISABLE_WRAPPING
case SPLIT_BEGIN:
- undidmsg = _("line wrap");
goto_line_posx(u->lineno, u->begin);
openfile->current_undo = u;
openfile->last_action = OTHER;
@@ -632,6 +632,7 @@
do_redo();
u = openfile->current_undo;
goto_line_posx(u->lineno, u->begin);
+ case SPLIT_END:
break;
#endif /* !DISABLE_WRAPPING */
case UNSPLIT:
@@ -675,6 +676,7 @@
if (gotolinecolumn)
do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE);
+ if(undidmsg)
statusbar(_("Redid action (%s)"), undidmsg);
openfile->current_undo = u;
@@ -1126,6 +1128,30 @@
prepend_wrap = FALSE;
}
+ssize_t get_wrap_index(filestruct *line, size_t line_len)
+{
+ /* Find the last blank where we can break the line. */
+ ssize_t wrap_loc = break_line(line->data, fill
+#ifndef DISABLE_HELP
+ , FALSE
+#endif
+ );
+
+ /* If we couldn't break the line, or we've reached the end of it, we
+ * don't wrap. */
+ if (wrap_loc == -1 || wrap_loc >= line_len)
+ return 0;
+
+ /* Otherwise, move forward to the character just after the blank. */
+ wrap_loc += move_mbright(line->data + wrap_loc, 0);
+
+ /* After the move, check again. If we've reached the end of the line, we don't wrap. */
+ if (wrap_loc >= line_len)
+ return 0;
+
+ return wrap_loc;
+}
+
/* Try wrapping the given line. Return TRUE if wrapped, FALSE otherwise. */
bool do_wrap(filestruct *line)
{
@@ -1133,12 +1159,6 @@
/* The length of the line we wrap. */
ssize_t wrap_loc;
/* The index of line->data where we wrap. */
-#ifndef NANO_TINY
- const char *indent_string = NULL;
- /* Indentation to prepend to the new line. */
- size_t indent_len = 0;
- /* The length of indent_string. */
-#endif
const char *after_break;
/* The text after the wrap point. */
size_t after_break_len;
@@ -1167,36 +1187,11 @@
line_len = strlen(line->data);
/* Find the last blank where we can break the line. */
- wrap_loc = break_line(line->data, fill
-#ifndef DISABLE_HELP
- , FALSE
-#endif
- );
-
- /* If we couldn't break the line, or we've reached the end of it, we
- * don't wrap. */
- if (wrap_loc == -1 || line->data[wrap_loc] == '\0')
+ wrap_loc = get_wrap_index(line, line_len);
+ if (!wrap_loc)
return FALSE;
- /* Otherwise, move forward to the character just after the blank. */
- wrap_loc += move_mbright(line->data + wrap_loc, 0);
-
- /* If we've reached the end of the line, we don't wrap. */
- if (line->data[wrap_loc] == '\0')
- return FALSE;
-
#ifndef NANO_TINY
- /* If autoindent is turned on, and we're on the character just after
- * the indentation, we don't wrap. */
- if (ISSET(AUTOINDENT)) {
- /* Get the indentation of this line. */
- indent_string = line->data;
- indent_len = indent_length(indent_string);
-
- if (wrap_loc == indent_len)
- return FALSE;
- }
-
add_undo(SPLIT_BEGIN);
#endif
@@ -1254,19 +1249,33 @@
}
}
+ if (old_x < wrap_loc)
+ prepend_wrap = TRUE;
+ else
+ prepend_wrap = FALSE;
+
+ while(wrap_loc){
/* Go to the wrap location and split the line there. */
openfile->current_x = wrap_loc;
do_enter(FALSE);
- if (old_x < wrap_loc) {
- openfile->current_x = old_x;
- openfile->current = oldLine;
+ line = openfile->current;
+ assert(line != NULL && line->data != NULL);
+
+ if(!prepend_wrap)
+ old_x = openfile->current_x + old_x - wrap_loc;
+ /* Find the last blank where we can break the line. */
+ wrap_loc = get_wrap_index(line, strlen(line->data));
+
+ if (!prepend_wrap && old_x < wrap_loc){
prepend_wrap = TRUE;
- } else {
- openfile->current_x += (old_x - wrap_loc);
- prepend_wrap = FALSE;
+ oldLine = openfile->current;
}
+ }
+ if (prepend_wrap)
+ openfile->current = oldLine;
+ openfile->current_x = old_x;
openfile->placewewant = xplustabs();
#ifndef NANO_TINY
_______________________________________________
Nano-devel mailing list
Nano-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/nano-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic