+ LyXText * tt = getLyXText();
+ hideCursor();
+ update(tt, BufferView::SELECT|BufferView::FITCUR);
+
+ // clear the selection (if there is any)
+ toggleSelection(false);
+ update(tt, BufferView::SELECT|BufferView::FITCUR);
+
+ // clear the selection (if there is any)
+ toggleSelection(false);
+ tt->replaceSelectionWithString(this, replacestring);
+
+ tt->setSelectionRange(this, replacestring.length());
+
+ // Go back so that replacement string is also spellchecked
+ for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
+ tt->cursorLeft(this);
+ }
+ update(tt, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+}
+// End of spellchecker stuff
+
+
+bool BufferView::lockInset(UpdatableInset * inset)
+{
+ if (!inset)
+ return false;
+ // don't relock if we're already locked
+ if (theLockingInset() == inset)
+ return true;
+ if (!theLockingInset()) {
+ // first check if it's the inset under the cursor we want lock
+ // should be most of the time
+ char const c = text->cursor.par()->getChar(text->cursor.pos());
+ if (c == Paragraph::META_INSET) {
+ Inset * in = text->cursor.par()->getInset(text->cursor.pos());
+ if (inset == in) {
+ theLockingInset(inset);
+ return true;
+ }
+ }
+ // Then do a deep look of the inset and lock the right one
+ int const id = inset->id();
+ ParagraphList::iterator pit = buffer()->paragraphs.begin();
+ ParagraphList::iterator pend = buffer()->paragraphs.end();
+ for (; pit != pend; ++pit) {
+ InsetList::iterator it = pit->insetlist.begin();
+ InsetList::iterator end = pit->insetlist.end();
+ for (; it != end; ++it) {
+ if (it.getInset() == inset) {
+ text->setCursorIntern(this, &*pit, it.getPos());
+ theLockingInset(inset);
+ return true;
+ }
+ if (it.getInset()->getInsetFromID(id)) {
+ text->setCursorIntern(this, &*pit, it.getPos());
+ it.getInset()->edit(this);
+ return theLockingInset()->lockInsetInInset(this, inset);
+ }
+ }
+ }
+ return false;
+ }
+ return theLockingInset()->lockInsetInInset(this, inset);
+}
+
+
+void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
+{
+ if (available() && theLockingInset() && !theLockingInset()->nodraw()) {
+ LyXCursor cursor = text->cursor;
+ Inset * locking_inset = theLockingInset()->getLockingInset();
+
+ if ((cursor.pos() - 1 >= 0) &&
+ cursor.par()->isInset(cursor.pos() - 1) &&
+ (cursor.par()->getInset(cursor.pos() - 1) ==
+ locking_inset))
+ text->setCursor(this, cursor,
+ cursor.par(), cursor.pos() - 1);
+ LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
+ LyXText * txt = getLyXText();
+ if (locking_inset->isTextInset() &&
+ locking_inset->lyxCode() != Inset::ERT_CODE &&
+ (txt->real_current_font.language() !=
+ buffer()->params.language
+ || txt->real_current_font.isVisibleRightToLeft()
+ != buffer()->params.language->RightToLeft()))
+ shape = (txt->real_current_font.isVisibleRightToLeft())
+ ? LyXScreen::REVERSED_L_SHAPE
+ : LyXScreen::L_SHAPE;
+ y += cursor.iy() + theLockingInset()->insetInInsetY();
+ screen().showManualCursor(text, x, y, asc, desc,
+ shape);