@@ -122,14 +122,14 @@ file_outline <- function(pattern = NULL,
122122 file_content <- rlang :: set_names(path )
123123 # Not warn
124124 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" ))
127127 file_content <- dplyr :: bind_rows(file_content , .id = " file" )
128128 } else {
129129 file_content <-
130130 purrr :: map(
131131 .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" )
133133 )
134134 file_content <- dplyr :: bind_rows(file_content , .id = " file" )
135135 }
@@ -365,7 +365,7 @@ print.outline_report <- function(x, ...) {
365365 link = list (rlang :: set_names(
366366 link_rs_api ,
367367 purrr :: map_chr(
368- paste0(" {.file " , file , " :" , line_id , " }" ),
368+ paste0(" {.file " , file , " :" , line , " }" ),
369369 cli :: format_inline
370370 )
371371 )),
@@ -507,19 +507,19 @@ display_outline_element <- function(.data) {
507507 y <- dplyr :: mutate(
508508 x ,
509509 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 ) |
511511 (is_doc_title & ! is_subtitle & ! is_snap_file & ! is_second_level_heading_or_more )) & ! is_news ,
512512 .by = " file"
513513 )
514514 y <- withCallingHandlers(
515515 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 ) |
518518 (is_doc_title & ! is_subtitle & ! is_snap_file & ! is_second_level_heading_or_more )
519519 ][1 ], # take the first element to avoid problems (may be the reason why problems occur)
520- NA
520+ NA_integer_
521521 ),
522- title_el = outline_el [line_id == title_el_line ],
522+ title_el = outline_el [line == title_el_line ],
523523 .by = " file"
524524 ),
525525 error = function (e ) {
@@ -529,15 +529,19 @@ display_outline_element <- function(.data) {
529529 )
530530 y <- dplyr :: relocate(
531531 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" ,
533533 .after = " content"
534534 )
535535
536536
537537 y $ outline_el <- ifelse(y $ has_title_el , NA_character_ , y $ outline_el )
538- na_if0 <- function (x ) {
538+ na_if0 <- function (x , which ) {
539539 if (length(x ) == 0 ) {
540- x <- NA
540+ if (which == " title" ) {
541+ x <- NA_character_
542+ } else {
543+ x <- NA_integer_
544+ }
541545 }
542546 if (length(x ) != 1 ) {
543547 cli :: cli_inform(" {x} are detected as document title. Internal error" )
@@ -547,8 +551,8 @@ display_outline_element <- function(.data) {
547551 if (! all(is.na(y $ title_el ))) {
548552 y <- dplyr :: mutate(
549553 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 " ),
552556 .by = " file"
553557 )
554558 }
@@ -591,7 +595,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
591595 as.character(trim_outline(.data $ outline_el [cn ], width - 8L )),
592596 " - {.run [Done{cli::symbol$tick}?](reuseme::complete_todo(" ,
593597 # Removed ending dot. (possibly will fail with older versions)
594- .data $ line_id [cn ], " , '" , .data $ file [cn ], " ', '" ,
598+ .data $ line [cn ], " , '" , .data $ file [cn ], " ', '" ,
595599 # modify regex twice if needed (see below)
596600 stringr :: str_sub(stringr :: str_replace_all(.data $ content [cn ], " \\ ^|\\ $|'|\\ {|\\ }|\\ )|\\ (|\\ [\\ ]|\\ +" , " ." ), start = - 15L ), " '))}" ,
597601 .data $ rs_version [cn ]
@@ -613,7 +617,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
613617 # Removed ending dot. (possibly will fail with older versions)
614618
615619 # 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 ), " '))}" ,
617621 rs_version
618622 ),
619623 outline_el2
@@ -622,7 +626,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
622626 )
623627
624628 .data <- dplyr :: mutate(.data ,
625- link = paste0(outline_el2 , " {.path " , file , " :" , line_id , " }" ),
629+ link = paste0(outline_el2 , " {.path " , file , " :" , line , " }" ),
626630 # rstudioapi::documentOpen works in the visual mode!! but not fully.
627631 file_path = .data $ file ,
628632 is_saved_doc = .env $ is_saved_doc ,
@@ -642,23 +646,25 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
642646 }
643647
644648 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 , "))}"),
646650 link_rs_api = dplyr :: case_when(
647651 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 ),
649653 rs_avail_file_link ~ paste0(
650654 " {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
652656 ),
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 )
654658 ),
655659 file_hl = dplyr :: case_when(
656660 ! is_saved_doc ~ file_path ,
657661 rs_avail_file_link ~ paste0(" {.href [" , text_in_link , " ](file://" , file_path , " )}" ),
658662 .default = paste0(" {.run [" , text_in_link , " ](reuseme::open_rs_doc('" , file_path , " '))}" )
659663 ),
660664 rs_version = NULL ,
661- outline_el2 = NULL
665+ outline_el2 = NULL ,
666+ condition_to_truncate = NULL ,
667+ condition_to_truncate2 = NULL
662668 ) | >
663669 dplyr :: filter(is.na(outline_el ) | grepl(pattern , outline_el , ignore.case = TRUE ))
664670}
0 commit comments