Display bookmarks in the workarea (take 2).

The bookmarks are shown with circled numbers in the right margin (or
the left margin in RTL mode). 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.

Caveats:

- this solution does not show the precise position of the bookmark
  (this is supposedly not a problem).

- if several bookmarks are on the same row, they will currently be
  garbled. It would be easy to make sure that only one is shown ; what
  would be more difficult would be to move the second bookmark lower.

- it is possible to make sure that the markers are correctly centered
  in the margin, and that the margin size is large enough to hold the
  marker (I did not try all fonts).

Fixes bug #2496.
This commit is contained in:
Jean-Marc Lasgouttes 2021-02-26 19:05:35 +01:00
parent e4ab91d802
commit 42b23f3fb2
10 changed files with 49 additions and 1 deletions

View File

@ -1472,6 +1472,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; break;
case LFUN_BOOKMARK_SAVE: case LFUN_BOOKMARK_SAVE:
dr.screenUpdate(Update::Force);
saveBookmark(convert<unsigned int>(to_utf8(cmd.argument()))); saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
break; break;

View File

@ -341,8 +341,9 @@ ColorSet::ColorSet()
{ Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" }, { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" },
{ Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"}, { Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"},
{ Color_previewframe, N_("preview frame"), "previewframe", black, Linen, "previewframe"}, { 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_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, N_("ignore"), "ignore", black, Linen, "ignore" },
{ Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr } { Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr }
}; };

View File

@ -228,6 +228,8 @@ enum ColorCode {
Color_paragraphmarker, Color_paragraphmarker,
/// Preview frame color /// Preview frame color
Color_previewframe, Color_previewframe,
/// Bookmark indicator color
Color_bookmark,
// Logical attributes // Logical attributes

View File

@ -69,6 +69,8 @@ public:
RowList const & rows() const { return rows_; } RowList const & rows() const { return rows_; }
/// ///
int rightMargin(BufferView const & bv) const; int rightMargin(BufferView const & bv) const;
///
Paragraph const & par() const { return *par_; }
/// dump some information to lyxerr /// dump some information to lyxerr
void dump() const; void dump() const;

View File

@ -627,7 +627,18 @@ void RowPainter::paintSelection() const
pi_.pain.fillRectangle(int(x), y1, pi_.pain.fillRectangle(int(x), y1,
int(xo_ + tm_.width()) - int(x), y2 - y1, int(xo_ + tm_.width()) - int(x), y2 - y1,
Color_selection); Color_selection);
}
void RowPainter::paintBookmark(int num) const
{
int const x = row_.isRTL()
? pi_.base.bv->workWidth() - pi_.base.bv->rightMargin() : 0;
FontInfo fi = pi_.base.bv->buffer().params().getFont().fontInfo();
fi.setColor(Color_bookmark);
// ❶ U+2776 DINGBAT NEGATIVE CIRCLED DIGIT ONE
char_type const ch = 0x2775 + num;
pi_.pain.text(x, yo_, ch, fi);
} }

View File

@ -44,6 +44,7 @@ public:
void paintText(); void paintText();
void paintOnlyInsets(); void paintOnlyInsets();
void paintSelection() const; void paintSelection() const;
void paintBookmark(int num) const;
private: private:
void paintLanguageMarkings(Row::Element const & e) const; void paintLanguageMarkings(Row::Element const & e) const;

View 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) : LastCommandsSection::LastCommandsSection(unsigned int num) :
default_num_last_commands(30), default_num_last_commands(30),
absolute_max_last_commands(100) absolute_max_last_commands(100)

View File

@ -262,6 +262,12 @@ public:
*/ */
BookmarkList & load() { return bookmarks; } 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: private:
/// allow 9 regular bookmarks, bookmark 0 is temporary /// allow 9 regular bookmarks, bookmark 0 is temporary

View File

@ -30,6 +30,7 @@
#include "MetricsInfo.h" #include "MetricsInfo.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "RowPainter.h" #include "RowPainter.h"
#include "Session.h"
#include "Text.h" #include "Text.h"
#include "TextClass.h" #include "TextClass.h"
#include "VSpace.h" #include "VSpace.h"
@ -1857,6 +1858,9 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
if (text_->isRTL(pit)) if (text_->isRTL(pit))
swap(pi.leftx, pi.rightx); swap(pi.leftx, pi.rightx);
BookmarksSection::BookmarkPosList bpl =
theSession().bookmarks().bookmarksInPar(bv_->buffer().fileName(), pm.par().id());
for (size_t i = 0; i != nrows; ++i) { for (size_t i = 0; i != nrows; ++i) {
Row const & row = pm.rows()[i]; Row const & row = pm.rows()[i];
@ -1945,6 +1949,11 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
rp.paintText(); rp.paintText();
rp.paintTooLargeMarks(row_x + row.left_x() < 0, rp.paintTooLargeMarks(row_x + row.left_x() < 0,
row_x + row.right_x() > bv_->workWidth()); row_x + row.right_x() > bv_->workWidth());
// indicate bookmarks presence in margin
for (auto const & bp_p : bpl)
if (bp_p.second >= row.pos() && bp_p.second < row.endpos())
rp.paintBookmark(bp_p.first);
y += row.descent(); y += row.descent();
#if 0 #if 0

View File

@ -2192,6 +2192,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
case LFUN_BOOKMARK_CLEAR: case LFUN_BOOKMARK_CLEAR:
theSession().bookmarks().clear(); theSession().bookmarks().clear();
dr.screenUpdate(Update::Force);
break; break;
case LFUN_DEBUG_LEVEL_SET: case LFUN_DEBUG_LEVEL_SET: