Angus Leeming wrote:
> I suspect that LyXText::getStringToIndex(BufferView *) is to blame,
> but my knowledge of cursor manipulation is zero. Guys, does the
> change below make sense to you. It seems to do the trick and doesn't
> affect the ability of the function to find the selection.
>
> Can I submit this change too, Lars
> Angus
Alternatively, this is guaranteed to work properly since the flow
control is not interrupted by those return statements.
Angus
string LyXText::getStringToIndex(BufferView * bview)
{
// Try implicit word selection
// If there is a change in the language the implicit word selection
// is disabled.
LyXCursor const reset_cursor = cursor;
bool const implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
string idxstring;
if (!selection.set())
bview->owner()->message(_("Nothing to index!"));
else if (selection.start.par() != selection.end.par())
bview->owner()->message(_("Cannot index more than one paragraph!"));
else
idxstring = selectionAsString(bview->buffer(), false);
}
// Reset cursors to their original position.
cursor = reset_cursor;
setCursor(bview, cursor.par(), cursor.pos());
selection.cursor = cursor;
// Implicit selections are cleared afterwards
if (implicitSelection)
clearSelection();
return idxstring;
}
Here's the diff (which I find hard to read!)
string LyXText::getStringToIndex(BufferView * bview)
{
- string idxstring;
-
// Try implicit word selection
// If there is a change in the language the implicit word selection
// is disabled.
LyXCursor const reset_cursor = cursor;
bool const implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
- if (!selection.set()) {
+ string idxstring;
+ if (!selection.set())
bview->owner()->message(_("Nothing to index!"));
- return string();
- }
- if (selection.start.par() != selection.end.par()) {
+ else if (selection.start.par() != selection.end.par())
bview->owner()->message(_("Cannot index more than one paragraph!"));
- return string();
+ else
+ idxstring = selectionAsString(bview->buffer(), false);
}
- idxstring = selectionAsString(bview->buffer(), false);
+ // Reset cursors to their original position.
+ cursor = reset_cursor;
+ setCursor(bview, cursor.par(), cursor.pos());
+ selection.cursor = cursor;
// Implicit selections are cleared afterwards
- //and cursor is set to the original position.
- if (implicitSelection) {
+ if (implicitSelection)
clearSelection();
- cursor = reset_cursor;
- setCursor(bview, cursor.par(), cursor.pos());
- selection.cursor = cursor;
- }
+
return idxstring;
}