]> git.lyx.org Git - features.git/commitdiff
Display bookmarks in the workarea.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 6 Jan 2021 18:21:26 +0000 (19:21 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 6 Jan 2021 19:20:03 +0000 (20:20 +0100)
The bookmarks are added as virtual elements in display Rows. Bookmarks
are shown with circled numbers. A new color "bookmarks" has been
added. Currently bookmark 0 (the return position) is not displayed
because it is very disturbing in practice.

To make this work, a new method BookmarksSection::bookmarksInPar
retuns the list of bookmarks in a paragraph along with their position.

Force redraw when using bookmark-save and bookmark-clear.

Fixes bug #2496.

src/BufferView.cpp
src/Color.cpp
src/ColorCode.h
src/Session.cpp
src/Session.h
src/TextMetrics.cpp
src/frontends/qt/GuiApplication.cpp

index 3e807ffba48fce7dac719777a6e24135dda9972e..afd9ada647d399a43200a9e6ba6b6de749da034c 100644 (file)
@@ -1449,6 +1449,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                break;
 
        case LFUN_BOOKMARK_SAVE:
+               dr.screenUpdate(Update::Force);
                saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
                break;
 
index 627b62b4a76c10a6baabf53641c1fdb9729689f4..6248e67b6a1e7c8d176c1ab51cd5d71fdb235d3f 100644 (file)
@@ -331,8 +331,9 @@ ColorSet::ColorSet()
        { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" },
        { Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"},
        { Color_previewframe, N_("preview frame"), "previewframe", black, Linen, "previewframe"},
-       { Color_inherit, N_("inherit"), "inherit", black, Linen, "inherit" },
        { Color_regexpframe, N_("regexp frame"), "regexpframe", Green, green, "regexpframe" },
+       { Color_bookmark, N_("bookmark"), "bookmark", RoyalBlue, RoyalBlue, "bookmark" },
+       { Color_inherit, N_("inherit"), "inherit", black, Linen, "inherit" },
        { Color_ignore, N_("ignore"), "ignore", black, Linen, "ignore" },
        { Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr }
        };
index 9badae91b57a9f6cf0ffe1f7cab9bb24dcca49fa..c7253ff641bfbd78d7461fd5c08a1e87eb781feb 100644 (file)
@@ -228,6 +228,8 @@ enum ColorCode {
        Color_paragraphmarker,
        /// Preview frame color
        Color_previewframe,
+       /// Bookmark indicator color
+       Color_bookmark,
 
        // Logical attributes
 
index f8d611644ca94a523dff11eadd26d418cea77114..16b6df7c61b2a3bca93cce9fb73dc85a256f3eba 100644 (file)
@@ -339,6 +339,20 @@ BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) co
 }
 
 
+BookmarksSection::BookmarkPosList
+BookmarksSection::bookmarksInPar(FileName const & fn, int const par_id) const
+{
+       // FIXME: we do not consider the case of bottom_pit.
+       // This is probably not a problem.
+       BookmarksSection::BookmarkPosList bip;
+       for (size_t i = 1; i < bookmarks.size(); ++i)
+               if (bookmarks[i].filename == fn && bookmarks[i].top_id == par_id)
+                       bip.push_back({i, bookmarks[i].top_pos});
+
+       return bip;
+}
+
+
 LastCommandsSection::LastCommandsSection(unsigned int num) :
        default_num_last_commands(30),
        absolute_max_last_commands(100)
index 09e9d7d13d9623c225c65b199f878beb2c9a53ae..857e0561000395445e11eb1f27d25fd03c80b859 100644 (file)
@@ -262,6 +262,12 @@ public:
        */
        BookmarkList & load() { return bookmarks; }
 
+       ///
+       typedef std::vector<std::pair<unsigned int, pos_type>> BookmarkPosList;
+
+       /// return a list of bookmarks and position for this paragraph
+       BookmarkPosList bookmarksInPar(support::FileName const & fn, int par_id) const;
+
 private:
 
        /// allow 9 regular bookmarks, bookmark 0 is temporary
index 0f2ef90b9d7ae51d0c49507a7dbfd72096a7f4e5..0f1814cab2ab4acf92f93a7547bb5f3183aad6c7 100644 (file)
@@ -30,6 +30,7 @@
 #include "MetricsInfo.h"
 #include "ParagraphParameters.h"
 #include "RowPainter.h"
+#include "Session.h"
 #include "Text.h"
 #include "TextClass.h"
 #include "VSpace.h"
@@ -877,6 +878,10 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
 {
        LATTEST(row.empty());
        Paragraph const & par = text_->getPar(row.pit());
+       Buffer const & buf = text_->inset().buffer();
+       BookmarksSection::BookmarkPosList bpl =
+               theSession().bookmarks().bookmarksInPar(buf.fileName(), par.id());
+
        pos_type const end = par.size();
        pos_type const pos = row.pos();
        pos_type const body_pos = par.beginOfBody();
@@ -903,7 +908,23 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
        // or the end of the par, then build a representation of the row.
        pos_type i = pos;
        FontIterator fi = FontIterator(*this, par, row.pit(), pos);
-       while (i < end && (i == pos || row.width() <= width)) {
+       // The real stopping condition is a few lines below.
+       while (true) {
+               // Firstly, check whether there is a bookmark here.
+               for (auto const & bp_p : bpl)
+                       if (bp_p.second == i) {
+                               Font f = *fi;
+                               f.fontInfo().setColor(Color_bookmark);
+                               // ❶ U+2776 DINGBAT NEGATIVE CIRCLED DIGIT ONE
+                               char_type const ch = 0x2775 + bp_p.first;
+                               row.addVirtual(i, docstring(1, ch), f, Change());
+                       }
+
+               // The stopping condition is here so that the display of a
+               // bookmark can take place at paragraph start too.
+               if (i >= end || (i != pos && row.width() > width))
+                       break;
+
                char_type c = par.getChar(i);
                // The most special cases are handled first.
                if (par.isInset(i)) {
@@ -997,9 +1018,7 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
                // in the paragraph.
                Font f(text_->layoutFont(row.pit()));
                f.fontInfo().setColor(Color_paragraphmarker);
-               BufferParams const & bparams
-                       = text_->inset().buffer().params();
-               f.setLanguage(par.getParLanguage(bparams));
+               f.setLanguage(par.getParLanguage(buf.params()));
                // ¶ U+00B6 PILCROW SIGN
                row.addVirtual(end, docstring(1, char_type(0x00B6)), f, change);
        }
index 294787ff74c8da568502a4810ca2b2d8671d4ac5..b0ec64ee0919d53f506239bd7754f689b3f42409 100644 (file)
@@ -2141,6 +2141,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
        case LFUN_BOOKMARK_CLEAR:
                theSession().bookmarks().clear();
+               dr.screenUpdate(Update::Force);
                break;
 
        case LFUN_DEBUG_LEVEL_SET: