Re: [PATCH] Help Viewer - incorrect behaviour of up arrrow key

2006-12-04 Thread Pavel Tsekov
Hello Grigory,

On Fri, 1 Dec 2006, Grigory Trenin wrote:

 Pavel Tsekov wrote:

 I won't apply this patch yet. I want to investigate further.

 Oh, now I see that I had hurried over to make that patch.
 I'll check everything and make another one. Without haste.

The problem is that the structure which stores the
history of the links followed stores only the
pointer to the start of the node and doesn't store
a pointer to the start of the currently displayed
area of a node. When following a link MC does this:

 history_ptr = (history_ptr+1) % HISTORY_SIZE;
 history [history_ptr].page = currentpoint;
 history [history_ptr].link = selected_item;
 currentpoint = startpoint = help_follow_link (...);

The start of the node in the history is erronously set
to 'currentpoint'. Then when going back to the previous
node via the left key the following code is executed via
prev_node_cmd():

 currentpoint = startpoint = history [history_ptr].page;
 selected_item = history [history_ptr].link;

This leads to incorrectly setting 'startpoint' to
the previously recorded value of 'currentpoint' which
is wrong.

I think the correct solution would be to keep both
'startpoint' and 'currentpoint' in the history but I am
open to suggestions.


___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [PATCH] Help Viewer - incorrect behaviour of up arrrow key

2006-12-04 Thread Grigory Trenin

Hello Pavel,

Pavel Tsekov wrote:


I think the correct solution would be to keep both
'startpoint' and 'currentpoint' in the history but I am
open to suggestions.



Yes, I thought about it too. This is a good and safe fix.
But I have a suggestion.
Actually, 'startpoint' is used only once at line 315 of help.c:

   p = current_link - 1;
   if (p = start)
   return 0;
   p = search_char_node (p, CHAR_LINK_START, -1);
   return p;

Here 'current_link' is the pointer to the currently
selected (highlighted) link, and 'start' == 'startpoint'.
Since there can be no situation when currently selected link
is outside of the current topic, (p = start) expression
becomes true only in one rare case - when the first text in the node
is a link, for example:
^D[Topic name]^ASome link^BSome link^C

In that case 'p' will point to ']' character, and 'start_point' will
point to ^A, so (p = start) condition will be true. But
this check for (p = start) condition is not really necessary,
because search_char_node() will not search beyond the topic
boundaries, it will stop at ^D character and return NULL.

So, if that check and the 'startpoint' variable itself are not
really necessary and can be eliminated, why should we mess with
saving/restoring 'startpoint' in the history?

Please look at a new patch - what do you think?
There I removed 'startpoint' as well as the first argument of
select_prev_link() function. And after calling it there is no sense to
check if (selected_item = last_shown) - this will never happen,
so I removed it also.


Regards,
 Grigory.

--- help.c.orig 2005-07-22 13:29:50.0 +0400
+++ help.c  2006-12-02 16:35:18.0 +0300
@@ -72,7 +72,7 @@
 static const char *main_node;  /* The main node */
 static const char *last_shown = NULL;  /* Last byte shown in a screen */
 static int end_of_node = 0;/* Flag: the last character of the node shown? 
*/
-static const char *currentpoint, *startpoint;
+static const char *currentpoint;
 static const char *selected_item;
 
 /* The widget variables */
@@ -305,19 +305,11 @@
 return p - 1;
 }
 
-static const char *select_prev_link (const char *start, const char 
*current_link)
+static const char *select_prev_link (const char *current_link)
 {
-const char *p;
-
 if (!current_link)
return 0;
-
-p = current_link - 1;
-if (p = start)
-   return 0;
-
-p = search_char_node (p, CHAR_LINK_START, -1);
-return p;
+return search_char_node (current_link - 1, CHAR_LINK_START, -1);
 }
 
 static void start_link_area (int x, int y, const char *link_name)
@@ -489,7 +481,7 @@
 event-y -= 2;
 
 if (event-buttons  GPM_B_RIGHT){
-   currentpoint = startpoint = history [history_ptr].page;
+   currentpoint = history [history_ptr].page;
selected_item = history [history_ptr].link;
history_ptr--;
if (history_ptr  0)
@@ -527,7 +519,7 @@
history_ptr = (history_ptr+1) % HISTORY_SIZE;
history [history_ptr].page = currentpoint;
history [history_ptr].link = current_area-link_name;
-   currentpoint = startpoint = help_follow_link (currentpoint, 
current_area-link_name);
+   currentpoint = help_follow_link (currentpoint, current_area-link_name);
selected_item = NULL;
 } else{
if (event-y  0)
@@ -561,7 +553,7 @@
 if (p == NULL)
return;
 
-currentpoint = startpoint = p + 1;
+currentpoint = p + 1;
 selected_item = NULL;
 help_callback (h, DLG_DRAW, 0);
 }
@@ -582,7 +574,7 @@
 history[history_ptr].page = currentpoint;
 history[history_ptr].link = selected_item;
 
-currentpoint = startpoint = new_item + 1;
+currentpoint = new_item + 1;
 selected_item = NULL;
 help_callback (h, DLG_DRAW, 0);
 }
@@ -595,7 +587,7 @@
 static void prev_node_cmd (void *vp)
 {
 Dlg_head *h = vp;
-currentpoint = startpoint = history [history_ptr].page;
+currentpoint = history [history_ptr].page;
 selected_item = history [history_ptr].link;
 history_ptr--;
 if (history_ptr  0)
@@ -672,14 +664,14 @@
if (history_ptr  0)
history_ptr = HISTORY_SIZE-1;

-   currentpoint = startpoint = history [history_ptr].page;
+   currentpoint = history [history_ptr].page;
selected_item   = history [history_ptr].link;
 #endif
} else {
history_ptr = (history_ptr+1) % HISTORY_SIZE;
history [history_ptr].page = currentpoint;
history [history_ptr].link = selected_item;
-   currentpoint = startpoint = help_follow_link (currentpoint, 
selected_item) + 1;
+   currentpoint = help_follow_link (currentpoint, selected_item) + 1;
}
selected_item = NULL;
break;
@@ -704,9 +696,8 @@
 case KEY_UP:
 case ALT ('\t'):
/* select previous link */
-   new_item = select_prev_link (startpoint, selected_item);
-   selected_item = new_item;
-   if (selected_item