]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
#7379 avoid the wrap spell check question when buffer is empty
[lyx.git] / src / BufferView.cpp
index 488a998810f1f37b4abdba2be7d49274d7eb448e..ac22a4e618996a53145199735e6c0df51b551425 100644 (file)
@@ -269,7 +269,7 @@ struct BufferView::Private
        /** kept to send setMouseHover(false).
          * Not owned, so don't delete.
          */
-       Inset * last_inset_;
+       Inset const * last_inset_;
        /// are we hovering something that we can click
        bool clickable_inset_;
 
@@ -700,6 +700,7 @@ CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
 
 void BufferView::bookmarkEditPosition()
 {
+       d->cursor_.markEditPosition();
        // Don't eat cpu time for each keystroke
        if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
                return;
@@ -1125,7 +1126,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                if (cur.inset().lyxCode() == CAPTION_CODE)
                        return cur.inset().getStatus(cur, cmd, flag);
                // FIXME we should consider passthru paragraphs too.
-               flag.setEnabled(!cur.inset().getLayout().isPassThru());
+               flag.setEnabled(!(cur.inTexted() && cur.paragraph().isPassThru()));
                break;
 
        case LFUN_CITATION_INSERT: {
@@ -1539,10 +1540,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                FindAndReplaceOptions opt;
                istringstream iss(to_utf8(cmd.argument()));
                iss >> opt;
-               if (findAdv(this, opt))
+               if (findAdv(this, opt)) {
                        dr.screenUpdate(Update::Force | Update::FitCursor);
-               else
+                       cur.dispatched();
+                       dispatched = true;
+               } else {
+                       cur.undispatched();
                        dispatched = false;
+               }
                break;
        }
 
@@ -1875,13 +1880,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        }
 
        default:
-               dispatched = false;
+               // OK, so try the Buffer itself...
+               buffer_.dispatch(cmd, dr);
+               dispatched = dr.dispatched();
                break;
        }
 
        buffer_.undo().endUndoGroup();
        dr.dispatched(dispatched);
-       return;
 }
 
 
@@ -1986,14 +1992,12 @@ void BufferView::updateHoveredInset() const
                d->last_inset_ = 0;
        }
        
-       // const_cast because of setMouseHover().
-       Inset * inset = const_cast<Inset *>(covering_inset);
-       if (inset && inset->setMouseHover(this, true)) {
+       if (covering_inset && covering_inset->setMouseHover(this, true)) {
                need_redraw = true;
                // Only the insets that accept the hover state, do 
                // clear the last_inset_, so only set the last_inset_
                // member if the hovered setting is accepted.
-               d->last_inset_ = inset;
+               d->last_inset_ = covering_inset;
        }
 
        if (need_redraw) {
@@ -2240,6 +2244,7 @@ TextMetrics const & BufferView::textMetrics(Text const * t) const
 
 TextMetrics & BufferView::textMetrics(Text const * t)
 {
+       LASSERT(t, /**/);
        TextMetricsCache::iterator tmc_it  = d->text_metrics_.find(t);
        if (tmc_it == d->text_metrics_.end()) {
                tmc_it = d->text_metrics_.insert(
@@ -2359,6 +2364,42 @@ void BufferView::putSelectionAt(DocIterator const & cur,
 }
 
 
+bool BufferView::selectIfEmpty(DocIterator & cur)
+{
+       if (!cur.paragraph().empty())
+               return false;
+
+       pit_type const beg_pit = cur.pit();
+       if (beg_pit > 0) {
+               // The paragraph associated to this item isn't
+               // the first one, so it can be selected
+               cur.backwardPos();
+       } else {
+               // We have to resort to select the space between the
+               // end of this item and the begin of the next one
+               cur.forwardPos();
+       }
+       if (cur.empty()) {
+               // If it is the only item in the document,
+               // nothing can be selected
+               return false;
+       }
+       pit_type const end_pit = cur.pit();
+       pos_type const end_pos = cur.pos();
+       d->cursor_.clearSelection();
+       d->cursor_.reset();
+       d->cursor_.setCursor(cur);
+       d->cursor_.pit() = beg_pit;
+       d->cursor_.pos() = 0;
+       d->cursor_.setSelection(false);
+       d->cursor_.resetAnchor();
+       d->cursor_.pit() = end_pit;
+       d->cursor_.pos() = end_pos;
+       d->cursor_.setSelection();
+       return true;
+}
+
+
 Cursor & BufferView::cursor()
 {
        return d->cursor_;
@@ -2855,6 +2896,12 @@ DocIterator const & BufferView::inlineCompletionPos() const
 }
 
 
+void BufferView::resetInlineCompletionPos()
+{
+       d->inlineCompletionPos_ = DocIterator();
+}
+
+
 bool samePar(DocIterator const & a, DocIterator const & b)
 {
        if (a.empty() && b.empty())