]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
clean up a bit
[lyx.git] / src / text2.C
index 00b4dbbc4b4a78d0db7d85fbb725b2fd31531226..16c056c7b6d603483af90cf51ad2ec0044176fed 100644 (file)
@@ -1039,33 +1039,29 @@ void LyXText::toggleFree(BufferView * bview,
 
 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) {
+       // Clear the implicit selection.
+       if (implicitSelection)
                clearSelection();
-               cursor = reset_cursor;
-               setCursor(bview, cursor.par(), cursor.pos());
-               selection.cursor = cursor;
-       }
+
        return idxstring;
 }
 
@@ -1497,7 +1493,8 @@ void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
 
        // cutSelection can invalidate the cursor so we need to set
        // it anew. (Lgb)
-       cursor = selection.start;
+       // we prefer the end for when tracking changes
+       cursor = selection.end;
 
        // need a valid cursor. (Lgb)
        clearSelection();
@@ -1561,14 +1558,13 @@ void LyXText::pasteSelection(BufferView * bview)
 }
 
 
-// sets the selection over the number of characters of string, no check!!
-void LyXText::setSelectionOverString(BufferView * bview, string const & str)
+void LyXText::setSelectionRange(BufferView * bview, lyx::pos_type length)
 {
-       if (str.empty())
+       if (!length)
                return;
 
        selection.cursor = cursor;
-       for (string::size_type i = 0; i < str.length(); ++i)
+       while (length--)
                cursorRight(bview);
        setSelection(bview);
 }
@@ -1805,7 +1801,11 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
 
        pos_type last = rowLastPrintable(old_row);
 
-       if (pos > last + 1) {
+       // None of these should happen, but we're scaredy-cats
+       if (pos > par->size()) {
+               pos = 0;
+               cur.pos(0);
+       } else if (pos > last + 1) {
                // This shouldn't happen.
                pos = last + 1;
                cur.pos(pos);