Le 11/03/2021 à 16:26, Jürgen Spitzmüller a écrit :
Do you lean that inline could be better now that drifting is fixed?
Yes, as it more precisely indicates the position.
So, it would mean that we want the attached pair of patches.
Testing appreciated, I would like to avoid going back and forth in master.
Note that a consequence of the visualization is that bookmarks bugs
become more obvious. Simple example :
1. set a bookmark in a paragraph,
2. modify the paragraph,
3. undo
-> the bookmark disappears.
This is because the paragraph id dies in the operation. A fix is coming
soon for this.
Of course, if the paragraph id is not found, the bookmark should instead
be shown in the top level paragraph. I do not know yet how to do that,
but it is doable.
So there are two solutions now:
1/ revert bookmark display now, implement it in 2.5.0dev and fix the
issues that this reveals. I anticipate that most of the issues will be
easy to solve.
2/ keep the inline version, and deal with the incoming bug reports, that
will be about bugs which actually already existed.
Riki, Jürgen, What would you prefer?
JMarc
>From 919ba029d7fb8f47960ff11676a33f868d9f7df1 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Fri, 2 Apr 2021 16:31:19 +0200
Subject: [PATCH 1/2] Revert "Display bookmarks in the workarea (take 2)."
This reverts commit 42b23f3fb24ea38e2b40543f4822a62d492e305a.
---
src/BufferView.cpp | 1 -
src/Color.cpp | 3 +--
src/ColorCode.h | 2 --
src/ParagraphMetrics.h | 2 --
src/RowPainter.cpp | 11 -----------
src/RowPainter.h | 1 -
src/Session.cpp | 15 ---------------
src/Session.h | 6 ------
src/TextMetrics.cpp | 9 ---------
src/frontends/qt/GuiApplication.cpp | 1 -
10 files changed, 1 insertion(+), 50 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index ed5a09f0aa..f423c11380 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1516,7 +1516,6 @@ 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;
diff --git a/src/Color.cpp b/src/Color.cpp
index cf297e909b..53fd0ee974 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -341,9 +341,8 @@ 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_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_regexpframe, N_("regexp frame"), "regexpframe", Green, green, "regexpframe" },
{ Color_ignore, N_("ignore"), "ignore", black, Linen, "ignore" },
{ Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr }
};
diff --git a/src/ColorCode.h b/src/ColorCode.h
index c7253ff641..9badae91b5 100644
--- a/src/ColorCode.h
+++ b/src/ColorCode.h
@@ -228,8 +228,6 @@ enum ColorCode {
Color_paragraphmarker,
/// Preview frame color
Color_previewframe,
- /// Bookmark indicator color
- Color_bookmark,
// Logical attributes
diff --git a/src/ParagraphMetrics.h b/src/ParagraphMetrics.h
index 988947355e..2e57f834d9 100644
--- a/src/ParagraphMetrics.h
+++ b/src/ParagraphMetrics.h
@@ -69,8 +69,6 @@ public:
RowList const & rows() const { return rows_; }
///
int rightMargin(BufferView const & bv) const;
- ///
- Paragraph const & par() const { return *par_; }
/// dump some information to lyxerr
void dump() const;
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 8cc7202ccc..2175e4fbd6 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -627,18 +627,7 @@ void RowPainter::paintSelection() const
pi_.pain.fillRectangle(int(x), y1,
int(xo_ + tm_.width()) - int(x), y2 - y1,
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);
}
diff --git a/src/RowPainter.h b/src/RowPainter.h
index 918fc9f989..275ff92b51 100644
--- a/src/RowPainter.h
+++ b/src/RowPainter.h
@@ -44,7 +44,6 @@ public:
void paintText();
void paintOnlyInsets();
void paintSelection() const;
- void paintBookmark(int num) const;
private:
void paintLanguageMarkings(Row::Element const & e) const;
diff --git a/src/Session.cpp b/src/Session.cpp
index a814991e59..ec33599cff 100644
--- a/src/Session.cpp
+++ b/src/Session.cpp
@@ -339,20 +339,6 @@ 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;
-}
-
-
void BookmarksSection::adjustPosAfterPos(FileName const & fn,
int const par_id, pos_type pos, int offset)
{
@@ -361,7 +347,6 @@ void BookmarksSection::adjustPosAfterPos(FileName const & fn,
bkm.top_pos += offset;
}
-
LastCommandsSection::LastCommandsSection(unsigned int num) :
default_num_last_commands(30),
absolute_max_last_commands(100)
diff --git a/src/Session.h b/src/Session.h
index b7443b9cab..8b885bfc98 100644
--- a/src/Session.h
+++ b/src/Session.h
@@ -262,12 +262,6 @@ 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;
-
/* An insertion/deletion in paragraph \c par_id of buffer \c fn
* lead to an offset \c offset after position \c pos. Update
* bookmarks accordingly.
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index e95757c88b..6616956f4f 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -30,7 +30,6 @@
#include "MetricsInfo.h"
#include "ParagraphParameters.h"
#include "RowPainter.h"
-#include "Session.h"
#include "Text.h"
#include "TextClass.h"
#include "VSpace.h"
@@ -1858,9 +1857,6 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
if (text_->isRTL(pit))
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) {
Row const & row = pm.rows()[i];
@@ -1949,11 +1945,6 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
rp.paintText();
rp.paintTooLargeMarks(row_x + row.left_x() < 0,
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();
#if 0
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 7d9bb9433f..e632c0ad8d 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -2214,7 +2214,6 @@ 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:
--
2.27.0
>From fad6d699a537cd297426ebdd4fc26fcc68c1a154 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Fri, 2 Apr 2021 16:33:14 +0200
Subject: [PATCH 2/2] Revert "Revert "Display bookmarks in the workarea.""
This reverts commit e4ab91d802084d42a1544bf04c34754e5f9284a5.
---
src/BufferView.cpp | 1 +
src/Color.cpp | 3 ++-
src/ColorCode.h | 2 ++
src/Session.cpp | 15 +++++++++++++++
src/Session.h | 6 ++++++
src/TextMetrics.cpp | 27 +++++++++++++++++++++++----
src/frontends/qt/GuiApplication.cpp | 1 +
7 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index f423c11380..ed5a09f0aa 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1516,6 +1516,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;
diff --git a/src/Color.cpp b/src/Color.cpp
index 53fd0ee974..cf297e909b 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -341,8 +341,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 }
};
diff --git a/src/ColorCode.h b/src/ColorCode.h
index 9badae91b5..c7253ff641 100644
--- a/src/ColorCode.h
+++ b/src/ColorCode.h
@@ -228,6 +228,8 @@ enum ColorCode {
Color_paragraphmarker,
/// Preview frame color
Color_previewframe,
+ /// Bookmark indicator color
+ Color_bookmark,
// Logical attributes
diff --git a/src/Session.cpp b/src/Session.cpp
index ec33599cff..8e88fb9582 100644
--- a/src/Session.cpp
+++ b/src/Session.cpp
@@ -347,6 +347,21 @@ void BookmarksSection::adjustPosAfterPos(FileName const & fn,
bkm.top_pos += offset;
}
+
+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)
diff --git a/src/Session.h b/src/Session.h
index 8b885bfc98..88737b2f26 100644
--- a/src/Session.h
+++ b/src/Session.h
@@ -269,6 +269,12 @@ public:
void adjustPosAfterPos(support::FileName const & fn,
int const par_id, pos_type pos, int offset);
+ ///
+ 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
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 6616956f4f..c31247842e 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -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"
@@ -879,6 +880,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();
@@ -905,7 +910,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)) {
@@ -999,9 +1020,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);
}
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index e632c0ad8d..7d9bb9433f 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -2214,6 +2214,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:
--
2.27.0
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel