From e9527d63044dbf654ec6afc0214749f84a298a9d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 3 Oct 2018 19:13:39 +0200 Subject: [PATCH] NotificationDisplay: proper handling of marks at insert position Basically we create a pair of marks, with left/right gravity and then inject the content between. Unfortunately, when the insert position is the very end of the buffer (which it always is), this trick leads to nesting the marked regions into each other. As a remedy, we first insert the trailing newline, and then attach the insert position one step before --- src/gui/widget/error-log-display.hpp | 44 ++++++---- wiki/thinkPad.ichthyo.mm | 118 ++++++++++++++++++++++++--- 2 files changed, 132 insertions(+), 30 deletions(-) diff --git a/src/gui/widget/error-log-display.hpp b/src/gui/widget/error-log-display.hpp index a818056e2..526013c69 100644 --- a/src/gui/widget/error-log-display.hpp +++ b/src/gui/widget/error-log-display.hpp @@ -109,7 +109,8 @@ namespace widget { } - /** + + /*********************************************************************//** * Widget to display log and error messages. * Based on a multiline text display box with scrollbars. * Warning and error messages are highlighted by special formatting. @@ -168,6 +169,7 @@ namespace widget { textLog_.get_buffer()->set_text (placeholder); // discard existing content } + /** just add normal information message to buffer, * without special markup and without expanding the widget */ void @@ -201,7 +203,7 @@ namespace widget { /** * clear all mere information messages; - * retain just the errors with tags + * retain just the previously tagged errors * @remark in fact populates a new buffer */ void @@ -211,12 +213,15 @@ namespace widget { vector newMarks; for (Entry& entry : errorMarks_) { + newBuff->insert (newBuff->end(), "\n"); + auto pos = newBuff->end(); + --pos; newMarks.emplace_back( make_pair ( - newBuff->create_mark (newBuff->end(), true), // "left gravity": stays to the left of inserted text - newBuff->create_mark (newBuff->end(), false))); // "right gravity": sticks right behind the inserted text)) + newBuff->create_mark (pos, true), // "left gravity" : stays to the left of inserted text + newBuff->create_mark (pos, false))); // "right gravity": sticks right behind the inserted text)) - newBuff->insert (newBuff->end() + newBuff->insert (pos // copy from old to new buffer, complete with formatting tag ,entry.first->get_iter() ,entry.second->get_iter() ); @@ -250,27 +255,32 @@ namespace widget { private:/* ===== Internals ===== */ /** add message entry to the (ever growing) text buffer. - * @remark According to the [GTKmm tutorial], `TextView::scroll_to(iter)` is not reliable; - * rather we need to use a text mark and set that text mark to the insert position. - * Actually, there is always one predefined text mark [called "insert"][insert-mark], - * which corresponds to the text cursor. Thus it suffices to navigate to text end, - * insert and scroll into view. + * @return pair of anonymous marks bracketing the content added + * @remark an entry is content sans the following line break, which is appended automatically. + * We inject the content _between_ two marks, which will adjust when content is altered. + * @remark According to the [API doc], `TextView::scroll_to(iter)` is not reliable; preferably + * we should use a text mark and set that text mark to the [insert position][insert-mark]. + * The handling of marks and tags is described in the [GTKmm tutorial]. + * @warning Each entry creates a new pair of marks. Not sure about the impact on performance... * * [GTKmm tutorial]: https://developer.gnome.org/gtkmm-tutorial/stable/sec-textview-buffer.html.en#textview-marks * [insert-mark]: https://developer.gnome.org/gtkmm/3.22/classGtk_1_1TextMark.html#details + * [API doc]: https://developer.gnome.org/gtkmm/3.22/classGtk_1_1TextView.html#a8412941c4da9a71a381052d6049164e4 */ Entry addEntry (string const& text, Literal markupTagName =nullptr) { auto buff = textLog_.get_buffer(); - auto begin = buff->create_mark (buff->end(), true); // "left gravity": stays to the left of inserted text - auto after = buff->create_mark (buff->end(), false);// "right gravity": sticks right behind the inserted text - if (markupTagName) - buff->insert_with_tag(buff->end(), text, cuString{markupTagName}); - else - buff->insert (buff->end(), text); buff->insert (buff->end(), "\n"); - textLog_.scroll_to (after); + auto pos = buff->end(); + --pos; + auto begin = buff->create_mark (pos, true); // "left gravity" : stays to the left of inserted text + auto after = buff->create_mark (pos, false);// "right gravity": sticks right behind the inserted text + if (markupTagName) + buff->insert_with_tag(pos, text, cuString{markupTagName}); + else + buff->insert (pos, text); + textLog_.scroll_to (begin); return make_pair (move(begin), move(after)); } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index f8d26919a..106e5c755 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -1773,7 +1773,8 @@ - + + @@ -2116,8 +2117,8 @@ - - + + @@ -2146,7 +2147,7 @@ - + @@ -2161,10 +2162,27 @@ - + + + - - + + + + + + +

+ ...dann Einfügestelle davor platzieren +

+ + +
+
+
+ + +
@@ -2210,8 +2228,8 @@
- - + + @@ -2756,8 +2774,8 @@ - - + + @@ -5014,9 +5032,20 @@ + + + + + + + + + + + @@ -5028,7 +5057,7 @@

- + @@ -37869,8 +37898,9 @@ - + + @@ -38812,6 +38842,68 @@ + + + + + + + + + + + + + + + + + + + + +

+ stets zwischen den Zeichen +

+ + +
+
+ + + + + + +

+ Danke! endlich bekommt das mal jemand korrekt hin +

+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + + +