]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Disable language combo if there is nothing to select
[lyx.git] / src / BufferView.cpp
index 35a126b18ac6e87bb6e4240f34f999b146554f4b..900207c23871e6e684e3896ef6ac68e7471e627b 100644 (file)
@@ -316,9 +316,6 @@ struct BufferView::Private
        /// a slice pointing to the start of the row where the cursor
        /// is (at last draw time)
        CursorSlice current_row_slice_;
-       /// a slice pointing to the start of the row where cursor was
-       /// at previous draw event
-       CursorSlice last_row_slice_;
 
        // The vertical size of the blinking caret. Only used for math
        // Using it for text could be bad when undo restores the cursor
@@ -500,11 +497,6 @@ void BufferView::processUpdateFlags(Update::flags flags)
         */
        buffer_.updateMacros();
 
-       // SinglePar is ignored for now (this should probably change). We
-       // set it ourselves below, at the price of always rebreaking the
-       // paragraph at cursor. This can be expensive for large tables.
-       flags = flags & ~Update::SinglePar;
-
        // First check whether the metrics and inset positions should be updated
        if (flags & Update::Force) {
                // This will update the CoordCache items and replace Force
@@ -512,15 +504,14 @@ void BufferView::processUpdateFlags(Update::flags flags)
                updateMetrics(flags);
        }
 
-       // Detect whether we can only repaint a single paragraph.
+       // Detect whether we can only repaint a single paragraph (if we
+       // are not already redrawing all).
        // We handle this before FitCursor because the later will require
        // correct metrics at cursor position.
-       if (!(flags & Update::ForceDraw)) {
-               if (singleParUpdate())
-                       flags = flags | Update::SinglePar;
-               else
+       if (!(flags & Update::ForceDraw)
+           && (flags & Update::SinglePar)
+               && !singleParUpdate())
                        updateMetrics(flags);
-       }
 
        // Then make sure that the screen contains the cursor if needed
        if (flags & Update::FitCursor) {
@@ -538,7 +529,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
        LYXERR(Debug::PAINTING, "Cumulative flags: " << flagsAsString(flags));
 
        // Now compute the update strategy
-       // Possibly values in flag are None, Decoration, ForceDraw
+       // Possibly values in flag are None, SinglePar, Decoration, ForceDraw
        LATTEST((d->update_flags_ & ~(Update::None | Update::SinglePar
                                      | Update::Decoration | Update::ForceDraw)) == 0);
 
@@ -2551,8 +2542,9 @@ TextMetrics & BufferView::textMetrics(Text const * t)
        LBUFERR(t);
        TextMetricsCache::iterator tmc_it  = d->text_metrics_.find(t);
        if (tmc_it == d->text_metrics_.end()) {
-               tmc_it = d->text_metrics_.insert(
-                       make_pair(t, TextMetrics(this, const_cast<Text *>(t)))).first;
+               tmc_it = d->text_metrics_.emplace(std::piecewise_construct,
+                               std::forward_as_tuple(t),
+                               std::forward_as_tuple(this, const_cast<Text *>(t))).first;
        }
        return tmc_it->second;
 }
@@ -3072,30 +3064,24 @@ int BufferView::horizScrollOffset(Text const * text,
 }
 
 
-bool BufferView::hadHorizScrollOffset(Text const * text,
-                                      pit_type pit, pos_type pos) const
-{
-       return !d->last_row_slice_.empty()
-              && &text->inset() == d->last_row_slice_.inset().asInsetText()
-              && pit ==  d->last_row_slice_.pit()
-              && pos ==  d->last_row_slice_.pos();
-}
-
-
 void BufferView::setCurrentRowSlice(CursorSlice const & rowSlice)
 {
        // nothing to do if the cursor was already on this row
-       if (d->current_row_slice_ == rowSlice) {
-               d->last_row_slice_ = CursorSlice();
+       if (d->current_row_slice_ == rowSlice)
                return;
-       }
 
        // if the (previous) current row was scrolled, we have to
        // remember it in order to repaint it next time.
-       if (d->horiz_scroll_offset_ != 0)
-               d->last_row_slice_ = d->current_row_slice_;
-       else
-               d->last_row_slice_ = CursorSlice();
+       if (d->horiz_scroll_offset_ != 0) {
+               // search the old row in cache and mark it changed
+               for (auto & tm_pair : d->text_metrics_) {
+                       if (&tm_pair.first->inset() == rowSlice.inset().asInsetText()) {
+                               tm_pair.second.setRowChanged(rowSlice.pit(), rowSlice.pos());
+                               // We found it, no need to continue.
+                               break;
+                       }
+               }
+       }
 
        // Since we changed row, the scroll offset is not valid anymore
        d->horiz_scroll_offset_ = 0;
@@ -3152,8 +3138,7 @@ void BufferView::checkCursorScrollOffset()
                       << d->horiz_scroll_offset_ << " to " << offset);
 
        if (d->update_strategy_ == NoScreenUpdate
-           && (offset != d->horiz_scroll_offset_
-               || !d->last_row_slice_.empty())) {
+           && offset != d->horiz_scroll_offset_) {
                // FIXME: if one uses SingleParUpdate, then home/end
                // will not work on long rows. Why?
                d->update_strategy_ = FullScreenUpdate;