12/07/2013 09:03, Hashini Senaratne:
Hi Jean-Marc
I hope you found your way out of this problem. Otherwise tomorrow I will
comment on your patch and give advice.
I think I found the pr
oblem. That is because in the for loop I am updatingthe left edge all the
time. I will try to correct it.
Although I found the reason, I am still trying to correct it.
I want to call the new method cur.setLeftEdge() for only once when drawing a
page. What I have done in my last commit was totally wrong, because there I
am calling it per row.
The important thing is to know what is the row that you have decided to
slide. This is why you have defined (set|get)ToowideRow, isn't it? Why
don't you use these methods?
Here is (again) how I see the algorithm. The following pseudo code
should be placed somewhere inside the for() loop of
TextMetrics::drawParagraph:
if current row is the cursor's textRow
if cursor's getToowideRow != cursor's texRow
reset left edge to 0
endif
if cursor is not visible with current LeftEdge
increase or decrease leftedge so that the cursor is visible
endif
add cursor's leftedge to inc_x
endif
And where this draw() method gets called?
TextMetrics::draw() is called from BufferView::draw().
Another problem is; if the current algorithm is used, when a row gets slide
the cursor will be placed exactly at the right edge. Therefore the cursor
will not appear to the outside. Proper solution would be sliding by an
amount equals to (current cursor position- cursor position if the cursor is
at one letter before (to left).)
You can try a simpler solution where you keep, say, 10 pixels of margin.
Or, if pixels are not good because of high-resolution screen issues, you
could experiment with a percentage of max_width (like 3%).
Is there a direct way to get this cursor
position if the cursor is at one letter before? We may not gone through this
cursor position (if going from right to left/ if we directly select a
position using the mouse pointer).
I think this is overly complicated. But it might be useful to experiment
with that if the simple solutions proposed above do not feel right in
practice.
I noticed another thing.
What is the different between cur.targetX() and bv.getPos(cur).x_? They give
different values sometime. I feel bv.getPos(cur).x_ is more accurate. Before
and just after entering a Math equation; cur.targetX() gives the same value
(eg: 10). But bv.getPos(cur).x_ gives different values (eg 10 & 13).
targetX is where you ant the cursor to be, not where it is.
First example. Below, `|' stands for the cursor.
foo bar foo bar |foo bar
foo bar
foo bar foo bar foo bar
Imagine you press CursorDown. The situation is now
foo bar foo bar foo bar
foo bar|
foo bar foo bar foo bar
CursorDown again. Situation becomes
foo bar foo bar foo bar
foo bar
foo bar foo bar |foo bar
This is made possible because, although second paragraph is very short,
targetX makes us remember where we want to be.
Another situation where this is useful is when using cursor down in the
following text
foo bar foo |bar foo bar
foo bar<labelinset> bar
foo bar foo bar foo bar
Again, knowing the targetX will avoid a `drift' of the cursor as you
move down the document.
Does this help?
JMarc
PS: I will have many comments concerning style. Do you want them or
later when you have a proper patch? I recommend that you read first
development/coding/CodingRulesAndAdvice.lyx (or at least part of it).