[attr_line] fixes for empty attributes

This commit is contained in:
Timothy Stack 2022-06-13 21:01:01 -07:00
parent 6c6d1cbf41
commit 64e7b78c6b
8 changed files with 70 additions and 36 deletions

View File

@ -130,6 +130,10 @@ consume(const string_fragment text)
static void
split_attrs(attr_line_t& al, const line_range& lr)
{
if (lr.empty()) {
return;
}
string_attrs_t new_attrs;
for (auto& attr : al.al_attrs) {
@ -201,7 +205,9 @@ attr_line_t::insert(size_t index,
split_attrs(*this, indent_lr);
indent_lr.lr_end += tws->tws_padding_indent;
line_ch_count += tws->tws_padding_indent;
this->al_attrs.emplace_back(indent_lr, SA_PREFORMATTED.value());
if (!indent_lr.empty()) {
this->al_attrs.emplace_back(indent_lr, SA_PREFORMATTED.value());
}
text_to_wrap = text_to_wrap.prepend(
this->al_string.data(),
tws->tws_indent + tws->tws_padding_indent);
@ -229,8 +235,10 @@ attr_line_t::insert(size_t index,
};
split_attrs(*this, indent_lr);
indent_lr.lr_end += tws->tws_padding_indent;
this->al_attrs.emplace_back(indent_lr,
SA_PREFORMATTED.value());
if (!indent_lr.empty()) {
this->al_attrs.emplace_back(indent_lr,
SA_PREFORMATTED.value());
}
line_ch_count = tws->tws_padding_indent + ch_count;
auto trailing_space_count = 0;
if (!last_word.empty()) {
@ -296,12 +304,8 @@ attr_line_t::insert(size_t index,
return space.s_remaining;
},
[](text_stream::corrupt corrupt) {
return corrupt.c_remaining;
},
[](text_stream::eof eof) {
return eof.e_remaining;
});
[](text_stream::corrupt corrupt) { return corrupt.c_remaining; },
[](text_stream::eof eof) { return eof.e_remaining; });
if (chunk.is<text_stream::word>()) {
last_word = text_to_wrap;
@ -439,6 +443,11 @@ attr_line_t::erase(size_t pos, size_t len)
this->al_string.erase(pos, len);
shift_string_attrs(this->al_attrs, pos, -((int32_t) len));
auto new_end = std::remove_if(
this->al_attrs.begin(), this->al_attrs.end(), [](const auto& attr) {
return attr.sa_range.empty();
});
this->al_attrs.erase(new_end, this->al_attrs.end());
return *this;
}

View File

@ -81,8 +81,17 @@ struct line_range {
bool intersects(const struct line_range& other) const
{
return this->contains(other.lr_start) || this->contains(other.lr_end)
|| other.contains(this->lr_start);
if (this->contains(other.lr_start)) {
return true;
}
if (other.lr_end > 0 && this->contains(other.lr_end - 1)) {
return true;
}
if (other.contains(this->lr_start)) {
return true;
}
return false;
}
line_range intersection(const struct line_range& other) const;

View File

@ -61,6 +61,11 @@ breadcrumb_curses::do_update()
auto width = static_cast<size_t>(getmaxx(this->bc_window));
auto crumbs = this->bc_focused_crumbs.empty() ? this->bc_line_source()
: this->bc_focused_crumbs;
if (this->bc_last_selected_crumb
&& this->bc_last_selected_crumb.value() >= crumbs.size())
{
this->bc_last_selected_crumb = crumbs.size() - 1;
}
attr_line_t crumbs_line;
for (const auto& crumb : crumbs) {
auto accum_width
@ -184,6 +189,12 @@ breadcrumb_curses::focus()
}
this->bc_current_search.clear();
if (this->bc_last_selected_crumb
&& this->bc_last_selected_crumb.value()
>= this->bc_focused_crumbs.size())
{
this->bc_last_selected_crumb = this->bc_focused_crumbs.size() - 1;
}
this->bc_selected_crumb = this->bc_last_selected_crumb.value_or(0);
this->reload_data();
}

View File

@ -106,7 +106,7 @@ db_label_source::text_attrs_for_line(textview_curses& tc,
string_attrs_t& sa)
{
struct line_range lr(0, 0);
struct line_range lr2(0, -1);
const struct line_range lr2(0, -1);
if (row >= (int) this->dls_rows.size()) {
return;

View File

@ -220,9 +220,8 @@ public:
}
lr.lr_end = left = lr.lr_start + amount;
if (ci.ci_attrs != 0) {
value_out.emplace_back(
lr, VC_STYLE.value(ci.ci_attrs | A_REVERSE));
if (ci.ci_attrs != 0 && !lr.empty()) {
value_out.emplace_back(lr, VC_STYLE.value(ci.ci_attrs | A_REVERSE));
}
}

View File

@ -210,8 +210,10 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
.append(line)
.append("\n");
}
padded_text.with_attr_for_all(SA_PREFORMATTED.value());
last_block.append("\n").append(padded_text);
if (!padded_text.empty()) {
padded_text.with_attr_for_all(SA_PREFORMATTED.value());
last_block.append("\n").append(padded_text);
}
} else if (bl.is<block_quote>()) {
text_wrap_settings tws = {0, 60};
attr_line_t wrapped_text;
@ -231,8 +233,10 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
.append(line)
.append("\n");
}
padded_text.with_attr_for_all(SA_PREFORMATTED.value());
last_block.append("\n").append(padded_text);
if (!padded_text.empty()) {
padded_text.with_attr_for_all(SA_PREFORMATTED.value());
last_block.append("\n").append(padded_text);
}
} else if (bl.is<MD_BLOCK_TABLE_DETAIL*>()) {
auto* table_detail = bl.get<MD_BLOCK_TABLE_DETAIL*>();
auto tab = std::move(this->ml_tables.back());
@ -333,8 +337,10 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
block_text.append("\n");
}
}
block_text.with_attr_for_all(SA_PREFORMATTED.value());
last_block.append(block_text);
if (!block_text.empty()) {
block_text.with_attr_for_all(SA_PREFORMATTED.value());
last_block.append(block_text);
}
} else if (bl.is<block_th>()) {
this->ml_tables.back().t_headers.push_back(block_text);
} else if (bl.is<MD_BLOCK_TD_DETAIL*>()) {

View File

@ -3978,7 +3978,7 @@ lnav@googlegroups.com[1] support@lnav.org[2]
Parameters
INSERT INTO [schema-name.] table-name [( column-name1 [, ... column-nameN] )] VALUES ( expr1 [, ... exprN] )
INSERT INTO [schema-name.] table-name [( column-name1 [, ... column-nameN] )] VALUES ( expr1 [, ... exprN] )
══════════════════════════════════════════════════════════════════════
Insert rows into a table
Parameters
@ -3997,7 +3997,7 @@ lnav@googlegroups.com[1] support@lnav.org[2]
window-name The name of the window definition
SELECT result-column1 [, ... result-columnN] [FROM table1 [, ... tableN]] [WHERE cond] [GROUP BY grouping-expr1 [, ... grouping-exprN]] [ORDER BY ordering-term1 [, ... ordering-termN]] [LIMIT limit-expr1 [, ... limit-exprN]]
SELECT result-column1 [, ... result-columnN] [FROM table1 [, ... tableN]] [WHERE cond] [GROUP BY grouping-expr1 [, ... grouping-exprN]] [ORDER BY ordering-term1 [, ... ordering-termN]] [LIMIT limit-expr1 [, ... limit-exprN]]
══════════════════════════════════════════════════════════════════════
Query the database and return zero or more rows of data.
Parameters
@ -4019,7 +4019,7 @@ lnav@googlegroups.com[1] support@lnav.org[2]
UPDATE table SET column-name1 = expr1 [, ... column-nameN = exprN] [WHERE cond]
UPDATE table SET column-name1 = expr1 [, ... column-nameN = exprN] [WHERE cond]
══════════════════════════════════════════════════════════════════════
Modify a subset of values in zero or more rows of the given table
Parameters

View File

@ -1,25 +1,25 @@
[2013-09-06T20:00:48.124] TRACE trace testbork bork bork
[2013-09-06T20:00:49.124] INFO Starting up servicebork bork bork
[2013-09-06T22:00:49.124] INFO Shutting down servicebork bork bork
user:mailto:steve@example.com
[2013-09-06T22:00:59.124] DEBUG5 Details...bork bork bork
[2013-09-06T22:00:59.124] DEBUG4 Details...bork bork bork
[2013-09-06T22:00:59.124] DEBUG3 Details...bork bork bork
[2013-09-06T22:00:59.124] DEBUG2 Details...bork bork bork
[2013-09-06T22:00:59.124] DEBUG Details...bork bork bork
[2013-09-06T22:01:49.124] STATS 1 beat per secondbork bork bork
[2013-09-06T22:01:49.124] WARNING not looking goodbork bork bork
[2013-09-06T22:01:49.124] ERROR looking badbork bork bork
[2013-09-06T22:01:49.124] CRITICAL sooo badbork bork bork