Steve Litt schreef:
On Thursday 14 May 2009 08:37:19 am Vincent van Ravesteijn - TNW wrote:
Guys,
Where can I hide to shame for writing this piece of code:
Text3.cpp:
465 TextMetrics & tm = bv->textMetrics(this);
466 if (!tm.contains(cur.pit())) {
467 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
468 tm = bv->textMetrics(this);
469 }
Anyway, I think bug #5888 is now fixed in r29665.
Please check whether the fix is ok and the bug is fixed.
Vincent
Hi Vincent,
I'm not familiar with LyX's constructs, so none of the preceding looks
particularly bad to me, although I can't really understand line 485.
What's wrong with the preceding code?
In line 465, tm is initialized to be a reference to the textmetrics
object that is related to the current view and the current inset. After
dispatching the LFUN_SCREEN_SHOW_CURSOR, the view has most probably
changed, which also means that we need to have a reference to a new
textmetrics object. And that's what I tried to accomplish with line 468.
However, you can't reassign a reference to refer to a different object.
So, what is done in line 468 is that the 'old' textmetrics object is
being assigned the values of the new textmetrics object. But, I guess,
these textmetrics objects are sort of temporary objects (I do not grasp
this textmetrics-caching code completely, to be honest), or maybe
copying should be properly implemented.
Anyway, I wanted to have a reference/pointer to the new object, but then
you'd have to use pointers instead of references.
Vincent