Skip to content

Commit

Permalink
Fix bug in block_is_last with multiple text input
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Apr 22, 2024
1 parent de43190 commit 0fad5f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ place_bullets <- function(type, indent, string_is_empty, bullet_number, bullets)
.Call(`_marquee_place_bullets`, type, indent, string_is_empty, bullet_number, bullets)
}

block_is_last <- function(indentation) {
.Call(`_marquee_block_is_last`, indentation)
block_is_last <- function(indentation, id) {
.Call(`_marquee_block_is_last`, indentation, id)
}
2 changes: 1 addition & 1 deletion R/grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ makeContext.marquee <- function(x) {
last_line <- ink_left

# Remove bottom-margin for blocks that are last child
block_last <- block_is_last(block_indent)
block_last <- block_is_last(block_indent, x$text$id[block_starts])
margin_bottom <- x$text$margin_bottom[block_starts]
margin_bottom[block_last] <- 0

Expand Down
8 changes: 4 additions & 4 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ extern "C" SEXP _marquee_place_bullets(SEXP type, SEXP indent, SEXP string_is_em
END_CPP11
}
// marquee.cpp
cpp11::writable::logicals block_is_last(cpp11::integers indentation);
extern "C" SEXP _marquee_block_is_last(SEXP indentation) {
cpp11::writable::logicals block_is_last(cpp11::integers indentation, cpp11::integers id);
extern "C" SEXP _marquee_block_is_last(SEXP indentation, SEXP id) {
BEGIN_CPP11
return cpp11::as_sexp(block_is_last(cpp11::as_cpp<cpp11::decay_t<cpp11::integers>>(indentation)));
return cpp11::as_sexp(block_is_last(cpp11::as_cpp<cpp11::decay_t<cpp11::integers>>(indentation), cpp11::as_cpp<cpp11::decay_t<cpp11::integers>>(id)));
END_CPP11
}

extern "C" {
static const R_CallMethodDef CallEntries[] = {
{"_marquee_block_is_last", (DL_FUNC) &_marquee_block_is_last, 1},
{"_marquee_block_is_last", (DL_FUNC) &_marquee_block_is_last, 2},
{"_marquee_marquee_c", (DL_FUNC) &_marquee_marquee_c, 2},
{"_marquee_place_bullets", (DL_FUNC) &_marquee_place_bullets, 5},
{NULL, NULL, 0}
Expand Down
7 changes: 4 additions & 3 deletions src/marquee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,15 @@ cpp11::writable::list place_bullets(cpp11::strings type, cpp11::integers indent,
}

[[cpp11::register]]
cpp11::writable::logicals block_is_last(cpp11::integers indentation) {
cpp11::writable::logicals block_is_last(cpp11::integers indentation, cpp11::integers id) {
cpp11::writable::logicals res;

for (R_xlen_t i = 0; i < indentation.size() - 1; ++i) {
int ind = indentation[i];
int this_id = id[i];
R_xlen_t next_block = i + 1;
while (next_block <= indentation.size() && ind < indentation[next_block]) next_block++;
res.push_back(next_block == indentation.size() || ind != indentation[next_block]);
while (next_block < indentation.size() && this_id == id[next_block] && ind < indentation[next_block]) next_block++;
res.push_back(next_block == indentation.size() || this_id != id[next_block] || ind != indentation[next_block]);
}
res.push_back(true);

Expand Down

0 comments on commit 0fad5f1

Please sign in to comment.