21/07/2013 21:50, Hashini Senaratne:
I tried to fix this and found that this happens because cur_x variable do mot get updates as expected. I save bv.getPos(cur).x_ to cur_x, as I discussed with you earlier. But my previous observation seems to be wrong when compared to cur.targetX(). I tried with cur.targetX() too. But that also did not solve the problem.*Here I am talking about the left corner of Math equation. What is happening normally is for each key stroke, this cur_x gets updated once. (If I do not move the mouse pointer) But just after I enter Math (going from left to right) this gives two 10s; which should have been one 13.
I see it too, it is very strange. However, I think the problem is different, because it does not require to go out of the equation. You do not see it because (strangely) your test case contains a math equation in a Title layout[1] and thus with large character. Now take the attached document and arrange the zoom value (Ctrl+mouse wheel) so that an individual character is less than 10 points wide. You should keep the LyX window narrow enough so that the equation is longer than the screen.
Now look at what happens when the cursor goes past the border of the margin. Do you see something weird?
The reason for it is the following. Take for example this piece of code: // If need to slide right else if (cur_x <= left_edge) { new_x -= cur_x - 10; cur.setLeftEdge(cur_x - 10); cout<<"Loop 2:"<<left_edge<<" "<<cur_x<<" "<<endl; }You compare left_edge to cur_x, and then set it to cur_x - 10. I suspect you would get much better results by doing:
else if (cur_x <= left_edge + 10) { left_edge = max(cur_x - 10, 0); new_x -= left_edge; cur.setLeftEdge(left_edge); } Of course the same should be done for the right edge case. 3 stylistic notes about this code1/ as you see, it is better to avoid recomputing the same thing several times once left_edge has been set; repetition is prone to errors; I suspect that the two last lines in the if(){..} could be put out of it and be common to all cases.
2/ you should define a constant int const CURSOR_MARGIN = 10, and use it instead of explicit numbers
3/ you have a if/else if/else if. This is wrong, since there is a possibility that none of these branches are taken. The right way to wrote the code is
if (too much on the left) { action; } else if (too much on the right) { action; } else { //optional if there is something to do }Let me recall that I will be in vacation starting Friday. I may have access to internet sporadically, but not to LyX source or to a real computer. For the sake of mid-term evaluation, it would be great if you had pushed to scroll/master a reasonable implementation of horizontal scrolling by then. I am not sure what is the amount of work needed (plenty of small things), it looks like a concrete goal.
JMarc[1] in normal documents Title should only be used once at the beginning of the document, bt this is irrelevant here.
longequation.lyx
Description: application/lyx