]> git.lyx.org Git - features.git/blobdiff - src/BufferView.cpp
Fixup 9f92fc92: improve FIXME in SystemcallPrivate::startProcess
[features.git] / src / BufferView.cpp
index 595a304a72cc339e35a52eea08c7bc1854dd0b5a..bff44cdbf02ae98d4f8d15b789ea911cfa7bfc03 100644 (file)
@@ -331,16 +331,20 @@ BufferView::~BufferView()
 }
 
 
-int BufferView::rightMargin() const
+int BufferView::defaultMargin() const
 {
        // The value used to be hardcoded to 10
-       int const default_margin = zoomedPixels(10);
+       return zoomedPixels(20);
+}
+
+
+int BufferView::rightMargin() const
+{
        // The additional test for the case the outliner is opened.
-       if (!full_screen_ || !lyxrc.full_screen_limit
-           || width_ < lyxrc.full_screen_width + 2 * default_margin)
-               return default_margin;
+       if (full_screen_ && lyxrc.full_screen_limit)
+               return max(defaultMargin(), (width_ - lyxrc.full_screen_width) / 2);
 
-       return (width_ - lyxrc.full_screen_width) / 2;
+       return defaultMargin();
 }
 
 
@@ -913,7 +917,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
        // restoration is inaccurate. If a bookmark was within an inset,
        // it will be restored to the left of the outmost inset that contains
        // the bookmark.
-       if (bottom_pit < int(buffer_.paragraphs().size())) {
+       if (!success && bottom_pit < int(buffer_.paragraphs().size())) {
                dit = doc_iterator_begin(&buffer_);
 
                dit.pit() = bottom_pit;
@@ -1015,10 +1019,11 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool const recenter)
                LBUFERR(!pm.rows().empty());
                // FIXME: smooth scrolling doesn't work in mathed.
                CursorSlice const & cs = dit.innerTextSlice();
-               int offset = coordOffset(dit).y_;
-               int ypos = pm.position() + offset;
+               int const ypos = pm.position() + coordOffset(dit).y_;
+               ParagraphMetrics const & inner_pm =
+                       textMetrics(cs.text()).parMetrics(cs.pit());
                Dimension const & row_dim =
-                       pm.getRow(cs.pos(), dit.boundary()).dim();
+                       inner_pm.getRow(cs.pos(), dit.boundary()).dim();
                int scrolled = 0;
                if (recenter)
                        scrolled = scroll(ypos - height_/2);
@@ -2263,6 +2268,13 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        }
 
        case LFUN_COPY:
+               // With multi-cell table content, we pass down to the inset
+               if (cur.inTexted() && cur.selection()
+                   && cur.selectionBegin().idx() != cur.selectionEnd().idx()) {
+                       buffer_.dispatch(cmd, dr);
+                       dispatched = dr.dispatched();
+                       break;
+               }
                cap::copySelection(cur);
                cur.message(_("Copy"));
                break;
@@ -2375,12 +2387,50 @@ Inset const * BufferView::getCoveringInset(Text const & text,
 }
 
 
+Inset const * BufferView::clickableMathInset(InsetMathNest const * inset,
+               CoordCache::Insets const & inset_cache, int x, int y) const
+{
+       for (size_t i = 0; i < inset->nargs(); ++i) {
+               MathData const & ar = inset->cell(i);
+               for (size_t j = 0; j < ar.size(); ++j) {
+                       string const name = lyxerr.debugging(Debug::MATHED)
+                               ? insetName(ar[j].nucleus()->lyxCode())
+                               : string();
+                       LYXERR(Debug::MATHED, "Checking inset: " << name);
+                       if (ar[j].nucleus()->clickable(*this, x, y)) {
+                               if (inset_cache.covers(ar[j].nucleus(), x, y)) {
+                                       LYXERR(Debug::MATHED, "Clickable inset: "
+                                              << name);
+                                       return ar[j].nucleus();
+                               }
+                       }
+                       InsetMathNest const * imn =
+                               ar[j].nucleus()->asNestInset();
+                       if (imn) {
+                               Inset const * inner =
+                                       clickableMathInset(imn, inset_cache, x, y);
+                               if (inner)
+                                       return inner;
+                       }
+               }
+       }
+       return nullptr;
+}
+
+
 void BufferView::updateHoveredInset() const
 {
        // Get inset under mouse, if there is one.
        int const x = d->mouse_position_cache_.x_;
        int const y = d->mouse_position_cache_.y_;
        Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+       if (covering_inset && covering_inset->asInsetMath()) {
+               Inset const * inner_inset = clickableMathInset(
+                               covering_inset->asInsetMath()->asNestInset(),
+                               coordCache().getInsets(), x, y);
+               if (inner_inset)
+                       covering_inset = inner_inset;
+       }
 
        d->clickable_inset_ = covering_inset && covering_inset->clickable(*this, x, y);
 
@@ -3151,7 +3201,9 @@ void BufferView::caretPosAndDim(Point & p, Dimension & dim) const
        } else {
                Font const font = cur.real_current_font;
                frontend::FontMetrics const & fm = theFontMetrics(font);
-               dim.wid = fm.lineWidth();
+               // lineWidth() can be 0 to mean 'thin line' on HiDpi, but the
+               // caret drawing code is not prepared for that.
+               dim.wid = max(fm.lineWidth(), 1);
                dim.asc = fm.maxAscent();
                dim.des = fm.maxDescent();
        }