about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--src/GridText.c134
-rw-r--r--src/GridText.h5
-rw-r--r--src/LYMainLoop.c38
4 files changed, 134 insertions, 48 deletions
diff --git a/CHANGES b/CHANGES
index 1aa4dba1..7e556a79 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,10 @@
--- $LynxId: CHANGES,v 1.569 2012/02/05 19:14:53 tom Exp $
+-- $LynxId: CHANGES,v 1.570 2012/02/07 01:45:24 tom Exp $
 ===============================================================================
 Changes since Lynx 2.8 release
 ===============================================================================
 
-2012-02-05 (2.8.8dev.10)
+2012-02-06 (2.8.8dev.10)
+* extend ^X-e editing of textarea's to include single-line fields -TD
 * modify comparison for splitting lines to allow for long preformatted lines,
   e.g., using  's to not wrap when the line-wrap mode is disabled -TD
 * modify cfg2html.pl to handle options which contain a digit, e.g.,
diff --git a/src/GridText.c b/src/GridText.c
index 2d13c02f..57d9aa78 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: GridText.c,v 1.220 2012/02/05 21:39:18 tom Exp $
+ * $LynxId: GridText.c,v 1.224 2012/02/07 01:43:47 tom Exp $
  *
  *		Character grid hypertext object
  *		===============================
@@ -12919,37 +12919,16 @@ static BOOLEAN IsFormsTextarea(FormInfo * form, TextAnchor *anchor_ptr)
 		      !strcmp(anchor_ptr->input_field->name, form->name));
 }
 
-static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
-			      char *ed_temp,
-			      int orig_cnt)
+static char *readEditedFile(char *ed_temp)
 {
     struct stat stat_info;
     size_t size;
 
     FILE *fp;
 
-    TextAnchor *anchor_ptr;
-    TextAnchor *end_anchor = NULL;
-    BOOLEAN wrapalert = FALSE;
-
-    int entry_line = form_link->anchor_line_num;
-    int exit_line = 0;
-    int line_cnt = 1;
-
-    HTLine *htline = NULL;
-
     char *ebuf;
-    char *line;
-    char *lp;
-    char *cp;
-    int match_tag = 0;
-    int newlines = 0;
-    int len, len0;
-    int wanted_fieldlen_wrap = -1;	/* not yet asked; 0 means don't. */
-    char *skip_at = NULL;
-    int skip_num = 0, i;
 
-    CTRACE((tfp, "GridText: entered HText_ExtEditForm()\n"));
+    CTRACE((tfp, "GridText: entered HText_EditTextArea()\n"));
 
     /*
      * Read back the edited temp file into our buffer.
@@ -12961,7 +12940,7 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
 	ebuf = typecalloc(char);
 
 	if (!ebuf)
-	    outofmem(__FILE__, "HText_ExtEditForm");
+	    outofmem(__FILE__, "HText_EditTextArea");
 
 	assert(ebuf != NULL);
     } else {
@@ -12992,13 +12971,47 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
 	   && (CanTrimTextArea(UCH(ebuf[size - 1])) || (ebuf[size - 1] == '\0')))
 	ebuf[--size] = '\0';
 
+    return ebuf;
+}
+
+static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
+			      char *ed_temp,
+			      int orig_cnt)
+{
+    TextAnchor *anchor_ptr;
+    TextAnchor *end_anchor = NULL;
+    BOOLEAN wrapalert = FALSE;
+
+    int entry_line = form_link->anchor_line_num;
+    int exit_line = 0;
+    int line_cnt = 1;
+
+    HTLine *htline = NULL;
+
+    char *ebuf;
+    char *line;
+    char *lp;
+    char *cp;
+    int match_tag = 0;
+    int newlines = 0;
+    int len, len0;
+    int wanted_fieldlen_wrap = -1;	/* not yet asked; 0 means don't. */
+    char *skip_at = NULL;
+    int skip_num = 0, i;
+
+    CTRACE((tfp, "GridText: entered HText_EditTextArea()\n"));
+
+    if ((ebuf = readEditedFile(ed_temp)) == 0) {
+	return 0;
+    }
+
     /*
      * Copy each line from the temp file into the corresponding anchor
      * struct.  Add new lines to the TEXTAREA if needed.  (Always leave
      * the user with a blank line at the end of the TEXTAREA.)
      */
     if ((line = typeMallocn(char, MAX_LINE)) == 0)
-	  outofmem(__FILE__, "HText_ExtEditForm");
+	  outofmem(__FILE__, "HText_EditTextArea");
 
     assert(line != NULL);
 
@@ -13192,7 +13205,7 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
  *
  * --KED 02/01/99
  */
-int HText_ExtEditForm(LinkInfo * form_link)
+int HText_EditTextArea(LinkInfo * form_link)
 {
     char *ed_temp;
     FILE *fp;
@@ -13209,7 +13222,7 @@ int HText_ExtEditForm(LinkInfo * form_link)
 
     FormInfo *form = form_link->l_form;
 
-    CTRACE((tfp, "GridText: entered HText_ExtEditForm()\n"));
+    CTRACE((tfp, "GridText: entered HText_EditTextArea()\n"));
 
     ed_temp = typeMallocn(char, LY_MAXPATH);
 
@@ -13274,7 +13287,7 @@ int HText_ExtEditForm(LinkInfo * form_link)
     LYRemoveTemp(ed_temp);
     FREE(ed_temp);
 
-    CTRACE((tfp, "GridText: exiting HText_ExtEditForm()\n"));
+    CTRACE((tfp, "GridText: exiting HText_EditTextArea()\n"));
 
     /*
      * Return the offset needed to move the cursor from its current
@@ -13286,6 +13299,69 @@ int HText_ExtEditForm(LinkInfo * form_link)
 }
 
 /*
+ * Similar to HText_EditTextArea, but assume a single-line text field -TD
+ */
+void HText_EditTextField(LinkInfo * form_link)
+{
+    char *ed_temp;
+    FILE *fp;
+
+    FormInfo *form = form_link->l_form;
+
+    CTRACE((tfp, "GridText: entered HText_EditTextField()\n"));
+
+    ed_temp = typeMallocn(char, LY_MAXPATH);
+
+    if ((fp = LYOpenTemp(ed_temp, "", "w")) == 0) {
+	FREE(ed_temp);
+	return;
+    }
+
+    /*
+     * Write the anchors' text to the temp edit file.
+     */
+    fputs(form->value, fp);
+    fputc('\n', fp);
+
+    LYCloseTempFP(fp);
+
+    CTRACE((tfp, "GridText: text field |%s| dumped to tempfile\n", form_link->lname));
+    CTRACE((tfp, "GridText: invoking editor (%s) on tempfile\n", editor));
+
+    edit_temporary_file(ed_temp, "", NULL);
+
+    CTRACE((tfp, "GridText: returned from editor (%s)\n", editor));
+
+    if (!form->disabled) {
+	char *ebuf;
+	char *p;
+
+	if ((ebuf = readEditedFile(ed_temp)) != 0) {
+	    /*
+	     * Only use the first line of the result, and only that up to
+	     * the size of the field.
+	     */
+	    for (p = ebuf; *p != '\0'; ++p) {
+		if ((p - ebuf) >= form->size - 1) {
+		    *p = '\0';
+		    break;
+		} else if (*p == '\n' || *p == '\r') {
+		    *p = '\0';
+		    break;
+		}
+	    }
+	    StrAllocCopy(form->value, ebuf);
+	    FREE(ebuf);
+	}
+    }
+
+    LYRemoveTemp(ed_temp);
+    FREE(ed_temp);
+
+    CTRACE((tfp, "GridText: exiting HText_EditTextField()\n"));
+}
+
+/*
  * Expand the size of a TEXTAREA by a fixed number of lines (as specified
  * by arg2).
  *
diff --git a/src/GridText.h b/src/GridText.h
index c5ffb088..f0a9b99a 100644
--- a/src/GridText.h
+++ b/src/GridText.h
@@ -1,5 +1,5 @@
 /*
- * $LynxId: GridText.h,v 1.65 2010/09/26 23:31:23 tom Exp $
+ * $LynxId: GridText.h,v 1.67 2012/02/07 00:36:09 tom Exp $
  *
  * Specialities of GridText as subclass of HText
  */
@@ -260,7 +260,8 @@ US-ASCII control characters <32 which are not defined in Unicode standard
     extern BOOL HText_AreDifferent(HTParentAnchor *anchor,
 				   const char *full_address);
 
-    extern int HText_ExtEditForm(LinkInfo * form_link);
+    extern int HText_EditTextArea(LinkInfo * form_link);
+    extern void HText_EditTextField(LinkInfo * form_link);
     extern void HText_ExpandTextarea(LinkInfo * form_link, int newlines);
     extern int HText_InsertFile(LinkInfo * form_link);
 
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index e3066998..72160e92 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYMainLoop.c,v 1.181 2012/02/05 19:04:59 tom Exp $
+ * $LynxId: LYMainLoop.c,v 1.183 2012/02/07 00:36:19 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTAccess.h>
@@ -54,6 +54,10 @@
 		(links[linkNumber].type == WWW_FORM_LINK_TYPE && \
 		 links[linkNumber].l_form->type == F_TEXTAREA_TYPE)
 
+#define LinkIsTextLike(linkNumber) \
+	     (links[linkNumber].type == WWW_FORM_LINK_TYPE && \
+	      F_TEXTLIKE(links[linkNumber].l_form->type))
+
 #ifdef KANJI_CODE_OVERRIDE
 char *str_kcode(HTkcode code)
 {
@@ -2524,9 +2528,8 @@ static void handle_LYK_DWIMHELP(const char **cshelpfile)
      * if current link is a text input form field.  - kw
      */
     if (curdoc.link >= 0 && curdoc.link < nlinks &&
-	links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
 	!FormIsReadonly(links[curdoc.link].l_form) &&
-	F_TEXTLIKE(links[curdoc.link].l_form->type)) {
+	LinkIsTextLike(curdoc.link)) {
 	*cshelpfile = LYLineeditHelpURL();
     }
 }
@@ -2545,16 +2548,16 @@ static void handle_LYK_EDIT_TEXTAREA(BOOLEAN *refresh_screen,
 	    *old_c = real_c;
 	    HTUserMsg(NO_EDITOR);
 	}
-    }
-    /*
-     * See if the current link is in a form TEXTAREA.
-     */
-    else if (LinkIsTextarea(curdoc.link)) {
+    } else if (LinkIsTextarea(curdoc.link)) {
+	/*
+	 * if the current link is in a form TEXTAREA, it requires handling
+	 * for the possible multiple lines.
+	 */
 
 	/* stop screen */
 	stop_curses();
 
-	(void) HText_ExtEditForm(&links[curdoc.link]);
+	(void) HText_EditTextArea(&links[curdoc.link]);
 
 	/*
 	 * TODO:
@@ -2572,6 +2575,14 @@ static void handle_LYK_EDIT_TEXTAREA(BOOLEAN *refresh_screen,
 	start_curses();
 	*refresh_screen = TRUE;
 
+    } else if (LinkIsTextLike(curdoc.link)) {
+	/*
+	 * other text fields are single-line
+	 */
+	stop_curses();
+	HText_EditTextField(&links[curdoc.link]);
+	start_curses();
+	*refresh_screen = TRUE;
     } else {
 
 	HTInfoMsg(NOT_IN_TEXTAREA_NOEDIT);
@@ -6533,8 +6544,7 @@ int mainloop(void)
 
 	curlink_is_editable = (BOOLEAN)
 	    (nlinks > 0 &&
-	     (links[curdoc.link].type == WWW_FORM_LINK_TYPE) &&
-	     F_TEXTLIKE(links[curdoc.link].l_form->type));
+	     LinkIsTextLike(curdoc.link));
 
 	use_last_tfpos = (BOOLEAN)
 	    (curlink_is_editable &&
@@ -6718,8 +6728,7 @@ int mainloop(void)
 		    LKC_TO_LAC(keymap, real_c) != LYK_CHANGE_LINK) {
 		    do_change_link();
 		    if ((c == '\n' || c == '\r') &&
-			links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
-			F_TEXTLIKE(links[curdoc.link].l_form->type) &&
+			LinkIsTextLike(curdoc.link) &&
 			!textfields_need_activation) {
 			c = DO_NOTHING;
 		    }
@@ -6952,8 +6961,7 @@ int mainloop(void)
 	case 0:		/* unmapped character */
 	default:
 	    if (curdoc.link >= 0 && curdoc.link < nlinks &&
-		links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
-		F_TEXTLIKE(links[curdoc.link].l_form->type)) {
+		LinkIsTextLike(curdoc.link)) {
 
 #ifdef TEXTFIELDS_MAY_NEED_ACTIVATION
 		if (textfields_need_activation) {