[LyX/master] (almost) Proper fix for caret droppings
commit 7a28258d320db0e389de8255b442d06e47d820dd Author: Jean-Marc Lasgouttes Date: Sat Nov 21 20:00:26 2020 +0100 (almost) Proper fix for caret droppings Try to find the most inner row that is overwritten by the caret. This allows to replace the hack in TextMetrics::draw, which did not really work. Note that there are still issues with emphasized caret at the beginning of inset, which will require some code reorganisation. Fixes current recipe of bug #12024. --- src/BufferView.cpp | 19 +-- src/TextMetrics.cpp | 12 ++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index db9329b..62969cb 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -3295,8 +3295,23 @@ void BufferView::draw(frontend::Painter & pain, bool paint_caret) * move at all */ if (paint_caret) { - Row const & caret_row = d->cursor_.textRow(); - caret_row.changed(true); + Cursor cur(d->cursor_); + Point p; + Dimension dim; + caretPosAndDim(p, dim); + while (cur.depth() > 1) { + if (cur.inTexted()) { + TextMetrics const & tm = textMetrics(cur.text()); + if (p.x_ >= tm.origin().x_ + && p.x_ + dim.width() <= tm.origin().x_ + tm.dim().width()) + break; + } else { + // in mathed + break; + } + cur.pop(); + } + cur.textRow().changed(true); } } diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index e937950..214fe89 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1918,16 +1918,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const LYXERR(Debug::PAINTING, "Clear rect@(" << max(row_x, 0) << ", " << y - row.ascent() << ")=" << width() << " x " << row.height()); - // FIXME: this is a hack. We clear an amount equal to - // cursor width. This will not work if the caret has a - // ridiculous width like 6. (see ticket #10797) - // This is the same formula as in GuiWorkArea. - int const caret_width = lyxrc.cursor_width - ? lyxrc.cursor_width - : 1 + int((lyxrc.currentZoom + 50) / 200.0); - pi.pain.fillRectangle(max(row_x, 0), y - row.ascent(), - width() + caret_width, - row.height(), pi.background_color); + pi.pain.fillRectangle(row_x, y - row.ascent(), + width(), row.height(), pi.background_color); } // Instrumentation for testing row cache (see also -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Compilation fix
commit d53b44273ce139dd0140dc215cc1e26d75453f60 Author: Jean-Marc Lasgouttes Date: Sat Nov 21 19:42:23 2020 +0100 Compilation fix --- src/Lexer.cpp |1 + src/support/any.h | 22 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 08fb469..17cc161 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -25,6 +25,7 @@ #include "support/lstrings.h" #include "support/lyxalgo.h" +#include // sort, lower_bound #include #include #include diff --git a/src/support/any.h b/src/support/any.h index e8f6a11..f246470 100644 --- a/src/support/any.h +++ b/src/support/any.h @@ -13,11 +13,23 @@ #define LYX_ANY_H #if __cplusplus >= 201703L - #include - namespace lyx { using std::any; } + +#include + +namespace lyx { +using std::any; +using std::any_cast; +} + #else - #include - namespace lyx { using boost::any; } -#endif + +#include + +namespace lyx { +using boost::any; +using boost::any_cast; +} + +#endif // __cplusplus >= 201703L #endif // LYX_ANY_H -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Correct caret position from the start
commit ba8ca0e38468c75ece9d19ca91b871acdbca55b3 Author: Jean-Marc Lasgouttes Date: Sat Nov 21 19:37:22 2020 +0100 Correct caret position from the start --- src/BufferView.cpp |2 ++ src/frontends/qt/GuiWorkArea.cpp |5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index bb41759..db9329b 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -3065,6 +3065,8 @@ void BufferView::caretPosAndDim(Point & p, Dimension & dim) const dim.wid = lyxrc.cursor_width; p = getPos(cur); + // center fat carets horizontally + p.x_ -= dim.wid / 2; p.y_ -= dim.asc; } diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp index c1f74f8..df0eda5 100644 --- a/src/frontends/qt/GuiWorkArea.cpp +++ b/src/frontends/qt/GuiWorkArea.cpp @@ -138,9 +138,8 @@ public: { if (dim.empty()) return; - // correction is (1) for horizontal scrolling and (2) for - // better positionning of large cursors. - int const xx = x - horiz_offset - dim.wid / 2; + // correction for horizontal scrolling + int const xx = x - horiz_offset; int const lx = dim.height() / 3; // draw caret box -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Use `std::any` when compiler supports C++17 or later
commit 8dfe07b5b54e5ba4147545407cdc1f422e753861 Author: Yuriy Skalko Date: Sat Nov 21 16:27:13 2020 +0200 Use `std::any` when compiler supports C++17 or later --- src/insets/ExternalTransforms.cpp |4 ++-- src/insets/ExternalTransforms.h |7 +++ src/support/Makefile.am |1 + src/support/any.h | 23 +++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/insets/ExternalTransforms.cpp b/src/insets/ExternalTransforms.cpp index 4f85f9d..9ff5772 100644 --- a/src/insets/ExternalTransforms.cpp +++ b/src/insets/ExternalTransforms.cpp @@ -326,13 +326,13 @@ string const sanitizeLatexOption(string const & input) namespace { template -void extractIt(boost::any const & any_factory, +void extractIt(any const & any_factory, Data const & data, Transformer & transformer) { if (any_factory.type() != typeid(Factory)) return; - Factory factory = boost::any_cast(any_factory); + Factory factory = any_cast(any_factory); if (factory) transformer = factory(data); } diff --git a/src/insets/ExternalTransforms.h b/src/insets/ExternalTransforms.h index 8b22f62..62e3342 100644 --- a/src/insets/ExternalTransforms.h +++ b/src/insets/ExternalTransforms.h @@ -14,11 +14,10 @@ #include "graphics/GraphicsParams.h" +#include "support/any.h" #include "support/Length.h" #include "support/unique_ptr.h" -#include - #include #include #include @@ -339,7 +338,7 @@ public: */ template TransformStore(TransformID id_, Factory const & factory) - : id(id_), any_factory(boost::any(factory)) {} + : id(id_), any_factory(any(factory)) {} typedef TransformCommand::ptr_type ComPtr; typedef TransformOption::ptr_type OptPtr; @@ -353,7 +352,7 @@ public: private: TransformID id; - boost::any any_factory; + any any_factory; }; } // namespace external diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 45d30b8..4ff8618 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -35,6 +35,7 @@ liblyxsupport_a_SOURCES = \ FileMonitor.h \ FileMonitor.cpp \ RandomAccessList.h \ + any.h \ bind.h \ Cache.h \ Changer.h \ diff --git a/src/support/any.h b/src/support/any.h new file mode 100644 index 000..e8f6a11 --- /dev/null +++ b/src/support/any.h @@ -0,0 +1,23 @@ +// -*- C++ -*- +/** + * \file any.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Yuriy Skalko + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYX_ANY_H +#define LYX_ANY_H + +#if __cplusplus >= 201703L + #include + namespace lyx { using std::any; } +#else + #include + namespace lyx { using boost::any; } +#endif + +#endif // LYX_ANY_H -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Use range-based loops
commit 7ca2f2b58d6c85e1383b3f4aba16f8a8c95fd325 Author: Yuriy Skalko Date: Thu Nov 19 14:03:26 2020 +0200 Use range-based loops --- src/KeyMap.cpp|6 +--- src/LyXAction.cpp |4 +- src/LyXAction.h |4 +- src/frontends/qt/GuiCommandBuffer.cpp | 31 + src/frontends/qt/qt_helpers.cpp |1 - src/insets/ExternalSupport.cpp|1 - src/insets/InsetInclude.cpp |1 - src/insets/InsetInfo.cpp |6 +--- src/insets/InsetLabel.cpp |1 - src/mathed/MathData.cpp |1 - src/output_latex.cpp |1 - src/support/lyxalgo.h | 41 - 12 files changed, 19 insertions(+), 79 deletions(-) diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp index 3698ddb..f469da5 100644 --- a/src/KeyMap.cpp +++ b/src/KeyMap.cpp @@ -531,10 +531,8 @@ KeyMap::BindingList KeyMap::listBindings(bool unbound, KeyMap::ItemType tag) con BindingList list; listBindings(list, KeySequence(nullptr, nullptr), tag); if (unbound) { - LyXAction::const_iterator fit = lyxaction.func_begin(); - LyXAction::const_iterator const fen = lyxaction.func_end(); - for (; fit != fen; ++fit) { - FuncCode action = fit->second; + for (auto const & name_code : lyxaction) { + FuncCode action = name_code.second; bool has_action = false; BindingList::const_iterator bit = list.begin(); BindingList::const_iterator const ben = list.end(); diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 8b13630..e1d78a0 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -4536,13 +4536,13 @@ bool LyXAction::funcHasFlag(FuncCode action, } -LyXAction::const_iterator LyXAction::func_begin() const +LyXAction::const_iterator LyXAction::begin() const { return lyx_func_map.begin(); } -LyXAction::const_iterator LyXAction::func_end() const +LyXAction::const_iterator LyXAction::end() const { return lyx_func_map.end(); } diff --git a/src/LyXAction.h b/src/LyXAction.h index 30aeac0..000b0fb 100644 --- a/src/LyXAction.h +++ b/src/LyXAction.h @@ -94,10 +94,10 @@ public: typedef FuncMap::const_iterator const_iterator; /// return an iterator to the start of the list of LFUNs - const_iterator func_begin() const; + const_iterator begin() const; /// return an iterator to one past the end of the list of LFUNs - const_iterator func_end() const; + const_iterator end() const; private: /// noncopyable diff --git a/src/frontends/qt/GuiCommandBuffer.cpp b/src/frontends/qt/GuiCommandBuffer.cpp index 06ca59c..d633428 100644 --- a/src/frontends/qt/GuiCommandBuffer.cpp +++ b/src/frontends/qt/GuiCommandBuffer.cpp @@ -26,7 +26,6 @@ #include "FuncRequest.h" #include "Session.h" -#include "support/lyxalgo.h" #include "support/lstrings.h" #include @@ -85,8 +84,9 @@ protected: GuiCommandBuffer::GuiCommandBuffer(GuiView * view) : view_(view) { - transform(lyxaction.func_begin(), lyxaction.func_end(), - back_inserter(commands_), firster()); + for (auto const & name_code : lyxaction) { + commands_.push_back(name_code.first); + } QPixmap qpup = getPixmap("images/", "up", "svgz,png"); QPixmap qpdown = getPixmap("images/", "down", "svgz,png"); @@ -263,18 +263,6 @@ void GuiCommandBuffer::hideParent() } -namespace { - -class prefix_p { -public: - string p; - prefix_p(string const & s) : p(s) {} - bool operator()(string const & s) const { return prefixIs(s, p); } -}; - -} // namespace - - string const GuiCommandBuffer::historyUp() { if (history_pos_ == history_.begin()) @@ -299,9 +287,10 @@ vector const GuiCommandBuffer::completions(string const & prefix, string & new_prefix) { vector comp; - - lyx::copy_if(commands_.begin(), commands_.end(), - back_inserter(comp), prefix_p(prefix)); + for (auto const & cmd : commands_) { + if (prefixIs(cmd, prefix)) + comp.push_back(cmd); + } if (comp.empty()) { new_prefix = prefix; @@ -320,8 +309,10 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix) test += tmp[test.length()]; while (test.length() < tmp.length()) { vector vtmp; - lyx::copy_if(comp.begin(), comp.end(), - back_inserter(vtmp), prefix_p(test)); + for (auto const & cmd : comp) { + if (prefixIs(cmd, test)) + vtmp.push_back(cmd); + } if (vtmp.size() != comp.size()) {
[LyX/master] Remove unused headers
commit 0b1e0b86106e0a4958530cb182bdee5ef9510568 Author: Yuriy Skalko Date: Sat Nov 21 14:14:38 2020 +0200 Remove unused headers --- src/frontends/qt/GuiApplication.cpp |1 - src/frontends/qt/GuiViewSource.cpp |4 2 files changed, 0 insertions(+), 5 deletions(-) diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index 9fa8d94..b3cfd5e 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -87,7 +87,6 @@ #include #include #include -#include #include #include #include diff --git a/src/frontends/qt/GuiViewSource.cpp b/src/frontends/qt/GuiViewSource.cpp index 40752cd..1a7a36c 100644 --- a/src/frontends/qt/GuiViewSource.cpp +++ b/src/frontends/qt/GuiViewSource.cpp @@ -25,7 +25,6 @@ #include "GuiView.h" #include "FuncRequest.h" #include "LyX.h" -#include "Paragraph.h" #include "TexRow.h" #include "support/debug.h" @@ -34,10 +33,7 @@ #include "support/docstring_list.h" #include "support/gettext.h" -#include - #include -#include #include #include #include -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Refactor checksum calculation
commit cbad214cdda5f85a177148e38c138b9560ba0c17 Author: Yuriy Skalko Date: Sat Nov 21 15:40:31 2020 +0200 Refactor checksum calculation --- src/ConverterCache.cpp | 13 ++--- src/frontends/qt/GuiApplication.cpp | 11 ++-- src/frontends/qt/GuiClipboard.cpp | 15 --- src/support/FileName.cpp| 22 src/support/Makefile.am |2 + src/support/checksum.cpp| 46 +++ src/support/checksum.h | 30 ++ 7 files changed, 95 insertions(+), 44 deletions(-) diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp index bee0253..0f4d03e 100644 --- a/src/ConverterCache.cpp +++ b/src/ConverterCache.cpp @@ -25,8 +25,8 @@ #include "support/lyxtime.h" #include "support/Package.h" +#include "support/checksum.h" #include "support/lassert.h" -#include #include #include @@ -41,14 +41,6 @@ namespace lyx { namespace { -unsigned long do_crc(string const & s) -{ - boost::crc_32_type crc; - crc = for_each(s.begin(), s.end(), crc); - return crc.checksum(); -} - - // FIXME THREAD // This should be OK because it is only assigned during init() static FileName cache_dir; @@ -62,7 +54,8 @@ public: : timestamp(t), checksum(c) { ostringstream os; - os << setw(10) << setfill('0') << do_crc(orig_from.absFileName()) + os << setw(10) << setfill('0') + << support::checksum(orig_from.absFileName()) << '-' << to_format; cache_name = FileName(addName(cache_dir.absFileName(), os.str())); LYXERR(Debug::FILES, "Add file cache item " << orig_from diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index b3cfd5e..8ab89b8 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -59,6 +59,7 @@ #include "insets/InsetText.h" +#include "support/checksum.h" #include "support/convert.h" #include "support/debug.h" #include "support/ExceptionMessage.h" @@ -146,8 +147,6 @@ #include #endif // Q_OS_MAC -#include - #include #include #include @@ -1708,9 +1707,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) && !is_open)) { // We want the ui session to be saved per document and not per // window number. The filename crc is a good enough identifier. - boost::crc_32_type crc; - crc = for_each(fname.begin(), fname.end(), crc); - createView(crc.checksum()); + createView(support::checksum(fname)); current_view_->openDocument(fname); if (!current_view_->documentBufferView()) current_view_->close(); @@ -2670,10 +2667,8 @@ void GuiApplication::restoreGuiSession() FileName const & file_name = last.file_name; if (!current_view_ || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) { - boost::crc_32_type crc; string const & fname = file_name.absFileName(); - crc = for_each(fname.begin(), fname.end(), crc); - createView(crc.checksum()); + createView(support::checksum(fname)); } current_view_->loadDocument(file_name, false); diff --git a/src/frontends/qt/GuiClipboard.cpp b/src/frontends/qt/GuiClipboard.cpp index 59e5900..f78ab1c 100644 --- a/src/frontends/qt/GuiClipboard.cpp +++ b/src/frontends/qt/GuiClipboard.cpp @@ -35,6 +35,8 @@ #include "frontends/alert.h" +#include "support/checksum.h" + #include #include #include @@ -47,8 +49,6 @@ #include #include -#include - #include #include #include @@ -431,11 +431,8 @@ void GuiClipboard::put(string const & lyx, docstring const & html, docstring con data->setData(lyxMimeType(), qlyx); // If the OS has not the concept of clipboard ownership, // we recognize internal data through its checksum. - if (!hasInternal()) { - boost::crc_32_type crc32; - crc32.process_bytes(lyx.c_str(), lyx.size()); - checksum = crc32.checksum(); - } + if (!hasInternal()) + checksum = support::checksum(lyx); } // Don't test for text.empty() since we want to be able to clear the // clipboard. @@ -528,9 +525,7 @@ bool GuiClipboard::isInternal() const // ourself by comparing its checksum with the stored one. QByteArray const ar = cache_.data(lyxMimeType()); string const data(ar.data(),
[LyX/master] Typo and reformatting
commit 2d27d033a668d8729817298de1109df250d4b328 Author: Jean-Marc Lasgouttes Date: Sat Nov 21 19:13:29 2020 +0100 Typo and reformatting --- src/TextMetrics.h |8 +++- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/TextMetrics.h b/src/TextMetrics.h index 096f92a..d65618f 100644 --- a/src/TextMetrics.h +++ b/src/TextMetrics.h @@ -76,7 +76,7 @@ public: bool const expand_on_multipars = true); /// The "nodraw" drawing stage for one single paragraph: set the - /// positions of the insets contained this paragraph in metrics + /// positions of the insets contained in this paragraph in metrics /// cache. Related to BufferView::updatePosCache. void updatePosCache(pit_type pit) const; @@ -99,11 +99,9 @@ public: /// is this position in the paragraph right-to-left? bool isRTL(CursorSlice const & sl, bool boundary) const; /// is between pos-1 and pos an RTL<->LTR boundary? - bool isRTLBoundary(pit_type pit, - pos_type pos) const; + bool isRTLBoundary(pit_type pit, pos_type pos) const; /// would be a RTL<->LTR boundary between pos and the given font? - bool isRTLBoundary(pit_type pit, - pos_type pos, Font const & font) const; + bool isRTLBoundary(pit_type pit, pos_type pos, Font const & font) const; /// Rebreaks the given paragraph. -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Erase white frame in fullscreen mode.
commit 4eb791ff18774153b9dad99fea377afc09712bc0 Author: Pavel Sanda Date: Sat Nov 21 15:34:26 2020 +0100 Erase white frame in fullscreen mode. Since Qt 5.9.4 one can't set negative margins unless explicitely allowed by a new flag. This brought back the white frame in fullscreen mode. https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg214002.html --- src/frontends/qt/GuiView.cpp | 13 + 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index 8753a63..d9e7fb2 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -1399,6 +1399,10 @@ bool GuiView::event(QEvent * e) } for (int i = 0; i != d.splitter_->count(); ++i) d.tabWorkArea(i)->setFullScreen(true); +#if QT_VERSION > 0x050903 + //Qt's 5.9.4 ba44cdae38406c safe area measures won't allow us to go negative in margins + setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, false); +#endif setContentsMargins(-2, -2, -2, -2); // bug 5274 hideDialogs("prefs", nullptr); @@ -1417,6 +1421,9 @@ bool GuiView::event(QEvent * e) } for (int i = 0; i != d.splitter_->count(); ++i) d.tabWorkArea(i)->setFullScreen(false); +#if QT_VERSION > 0x050903 + setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, true); +#endif setContentsMargins(0, 0, 0, 0); } return result; @@ -4652,8 +4659,14 @@ bool GuiView::lfunUiToggle(string const & ui_component) //are the frames in default state? d.current_work_area_->setFrameStyle(QFrame::NoFrame); if (l == 0) { +#if QT_VERSION > 0x050903 + setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, false); +#endif setContentsMargins(-2, -2, -2, -2); } else { +#if QT_VERSION > 0x050903 + setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, true); +#endif setContentsMargins(0, 0, 0, 0); } } else -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs