@@ -122,14 +122,14 @@ file_outline <- function(pattern = NULL,
122
122
file_content <- rlang :: set_names(path )
123
123
# Not warn
124
124
file_content <- purrr :: map(file_content , function (x ) readLines(fs :: path_real(x ), encoding = " UTF-8" , warn = FALSE ))
125
- # Combine everything into a tibble that contains file, line_id , content
126
- file_content <- purrr :: map(file_content , function (x ) tibble :: enframe(x , name = " line_id " , value = " content" ))
125
+ # Combine everything into a tibble that contains file, line , content
126
+ file_content <- purrr :: map(file_content , function (x ) tibble :: enframe(x , name = " line " , value = " content" ))
127
127
file_content <- dplyr :: bind_rows(file_content , .id = " file" )
128
128
} else {
129
129
file_content <-
130
130
purrr :: map(
131
131
.x = list (" unsaved-doc.R" = rstudioapi :: getSourceEditorContext()$ contents ),
132
- .f = function (x ) tibble :: enframe(x , name = " line_id " , value = " content" )
132
+ .f = function (x ) tibble :: enframe(x , name = " line " , value = " content" )
133
133
)
134
134
file_content <- dplyr :: bind_rows(file_content , .id = " file" )
135
135
}
@@ -365,7 +365,7 @@ print.outline_report <- function(x, ...) {
365
365
link = list (rlang :: set_names(
366
366
link_rs_api ,
367
367
purrr :: map_chr(
368
- paste0(" {.file " , file , " :" , line_id , " }" ),
368
+ paste0(" {.file " , file , " :" , line , " }" ),
369
369
cli :: format_inline
370
370
)
371
371
)),
@@ -507,19 +507,19 @@ display_outline_element <- function(.data) {
507
507
y <- dplyr :: mutate(
508
508
x ,
509
509
has_title_el =
510
- ((line_id == 1 & ! is_todo_fixme & ! is_test_name & ! is_snap_file ) |
510
+ ((line == 1 & ! is_todo_fixme & ! is_test_name & ! is_snap_file ) |
511
511
(is_doc_title & ! is_subtitle & ! is_snap_file & ! is_second_level_heading_or_more )) & ! is_news ,
512
512
.by = " file"
513
513
)
514
514
y <- withCallingHandlers(
515
515
dplyr :: mutate(y ,
516
- title_el_line = ifelse(has_title_el , line_id [
517
- (line_id == 1 & ! is_todo_fixme & ! is_test_name & ! is_snap_file ) |
516
+ title_el_line = ifelse(has_title_el , line [
517
+ (line == 1 & ! is_todo_fixme & ! is_test_name & ! is_snap_file ) |
518
518
(is_doc_title & ! is_subtitle & ! is_snap_file & ! is_second_level_heading_or_more )
519
519
][1 ], # take the first element to avoid problems (may be the reason why problems occur)
520
- NA
520
+ NA_integer_
521
521
),
522
- title_el = outline_el [line_id == title_el_line ],
522
+ title_el = outline_el [line == title_el_line ],
523
523
.by = " file"
524
524
),
525
525
error = function (e ) {
@@ -529,15 +529,19 @@ display_outline_element <- function(.data) {
529
529
)
530
530
y <- dplyr :: relocate(
531
531
y ,
532
- " outline_el" , " line_id " , " title_el" , " title_el_line" , " has_title_el" ,
532
+ " outline_el" , " line " , " title_el" , " title_el_line" , " has_title_el" ,
533
533
.after = " content"
534
534
)
535
535
536
536
537
537
y $ outline_el <- ifelse(y $ has_title_el , NA_character_ , y $ outline_el )
538
- na_if0 <- function (x ) {
538
+ na_if0 <- function (x , which ) {
539
539
if (length(x ) == 0 ) {
540
- x <- NA
540
+ if (which == " title" ) {
541
+ x <- NA_character_
542
+ } else {
543
+ x <- NA_integer_
544
+ }
541
545
}
542
546
if (length(x ) != 1 ) {
543
547
cli :: cli_inform(" {x} are detected as document title. Internal error" )
@@ -547,8 +551,8 @@ display_outline_element <- function(.data) {
547
551
if (! all(is.na(y $ title_el ))) {
548
552
y <- dplyr :: mutate(
549
553
y ,
550
- title_el = na_if0(title_el [! is.na(title_el )]),
551
- title_el_line = na_if0(title_el_line [! is.na(title_el_line )]),
554
+ title_el = na_if0(title_el [! is.na(title_el )], " title " ),
555
+ title_el_line = na_if0(title_el_line [! is.na(title_el_line )], " line " ),
552
556
.by = " file"
553
557
)
554
558
}
@@ -591,7 +595,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
591
595
as.character(trim_outline(.data $ outline_el [cn ], width - 8L )),
592
596
" - {.run [Done{cli::symbol$tick}?](reuseme::complete_todo(" ,
593
597
# Removed ending dot. (possibly will fail with older versions)
594
- .data $ line_id [cn ], " , '" , .data $ file [cn ], " ', '" ,
598
+ .data $ line [cn ], " , '" , .data $ file [cn ], " ', '" ,
595
599
# modify regex twice if needed (see below)
596
600
stringr :: str_sub(stringr :: str_replace_all(.data $ content [cn ], " \\ ^|\\ $|'|\\ {|\\ }|\\ )|\\ (|\\ [\\ ]|\\ +" , " ." ), start = - 15L ), " '))}" ,
597
601
.data $ rs_version [cn ]
@@ -613,7 +617,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
613
617
# Removed ending dot. (possibly will fail with older versions)
614
618
615
619
# modify regex twice if needed (see above)
616
- line_id , " , '" , file , " ', '" , stringr :: str_sub(stringr :: str_replace_all(content , " \\ ^|\\ $|'|\\ {|\\ }|\\ )|\\ (|\\ [\\ ]|\\ +" , " ." ), start = - 15L ), " '))}" ,
620
+ line , " , '" , file , " ', '" , stringr :: str_sub(stringr :: str_replace_all(content , " \\ ^|\\ $|'|\\ {|\\ }|\\ )|\\ (|\\ [\\ ]|\\ +" , " ." ), start = - 15L ), " '))}" ,
617
621
rs_version
618
622
),
619
623
outline_el2
@@ -622,7 +626,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
622
626
)
623
627
624
628
.data <- dplyr :: mutate(.data ,
625
- link = paste0(outline_el2 , " {.path " , file , " :" , line_id , " }" ),
629
+ link = paste0(outline_el2 , " {.path " , file , " :" , line , " }" ),
626
630
# rstudioapi::documentOpen works in the visual mode!! but not fully.
627
631
file_path = .data $ file ,
628
632
is_saved_doc = .env $ is_saved_doc ,
@@ -642,23 +646,25 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
642
646
}
643
647
644
648
dplyr :: mutate(.data ,
645
- # link_rs_api = paste0("{.run [", outline_el, "](reuseme::open_rs_doc('", file_path, "', line = ", line_id , "))}"),
649
+ # link_rs_api = paste0("{.run [", outline_el, "](reuseme::open_rs_doc('", file_path, "', line = ", line , "))}"),
646
650
link_rs_api = dplyr :: case_when(
647
651
is.na(outline_el2 ) ~ NA_character_ ,
648
- ! is_saved_doc ~ paste0(" line " , line_id , " -" , outline_el2 ),
652
+ ! is_saved_doc ~ paste0(" line " , line , " -" , outline_el2 ),
649
653
rs_avail_file_link ~ paste0(
650
654
" {cli::style_hyperlink(" , style_fun , ' , "' ,
651
- paste0(" file://" , file_path ), ' ", params = list(line = ' , line_id , " , col = 1))} " , outline_el2
655
+ paste0(" file://" , file_path ), ' ", params = list(line = ' , line , " , col = 1))} " , outline_el2
652
656
),
653
- .default = paste0(rs_version , " {.run [i](reuseme::open_rs_doc('" , file_path , " ', line = " , line_id , " ))} " , outline_el2 )
657
+ .default = paste0(rs_version , " {.run [i](reuseme::open_rs_doc('" , file_path , " ', line = " , line , " ))} " , outline_el2 )
654
658
),
655
659
file_hl = dplyr :: case_when(
656
660
! is_saved_doc ~ file_path ,
657
661
rs_avail_file_link ~ paste0(" {.href [" , text_in_link , " ](file://" , file_path , " )}" ),
658
662
.default = paste0(" {.run [" , text_in_link , " ](reuseme::open_rs_doc('" , file_path , " '))}" )
659
663
),
660
664
rs_version = NULL ,
661
- outline_el2 = NULL
665
+ outline_el2 = NULL ,
666
+ condition_to_truncate = NULL ,
667
+ condition_to_truncate2 = NULL
662
668
) | >
663
669
dplyr :: filter(is.na(outline_el ) | grepl(pattern , outline_el , ignore.case = TRUE ))
664
670
}
0 commit comments