@@ -917,14 +917,28 @@ function OrgMappings:open_at_point()
917917
918918 local footnote = Footnote .at_cursor ()
919919 if footnote then
920- return self :_jump_to_footnote (footnote )
920+ if footnote .is_reference then
921+ return self :_jump_to_footnote_definition (footnote )
922+ end
923+ return self :_jump_to_footnote_reference (footnote )
921924 end
922925end
923926
927+ function OrgMappings :_jump_to_footnote_reference (footnote_definition )
928+ local file = self .files :get_current_file ()
929+ local reference = file :find_footnote_reference (footnote_definition )
930+
931+ if not reference then
932+ return utils .echo_info ((' Cannot find reference for footnote "%s"' ):format (footnote_definition :get_name ()))
933+ end
934+
935+ return vim .fn .cursor ({ reference .range .start_line , reference .range .start_col })
936+ end
937+
924938--- @param footnote_reference OrgFootnote
925- function OrgMappings :_jump_to_footnote (footnote_reference )
939+ function OrgMappings :_jump_to_footnote_definition (footnote_reference )
926940 local file = self .files :get_current_file ()
927- local footnote = file :find_footnote (footnote_reference )
941+ local footnote = file :find_footnote_definition (footnote_reference )
928942
929943 if not footnote then
930944 local choice = vim .fn .confirm (' No footnote found. Create one?' , ' &Yes\n &No' )
@@ -933,31 +947,20 @@ function OrgMappings:_jump_to_footnote(footnote_reference)
933947 end
934948
935949 local footnotes_headline = file :find_headline_by_title (' footnotes' )
950+ local fndef = (' [fn:%s] ' ):format (footnote_reference .label )
936951 if footnotes_headline then
937952 local append_line = footnotes_headline :get_append_line ()
938- vim .api .nvim_buf_set_lines (0 , append_line , append_line , false , { footnote_reference . value .. ' ' })
939- vim .fn .cursor ({ append_line + 1 , # footnote_reference . value + 1 })
953+ vim .api .nvim_buf_set_lines (0 , append_line , append_line , false , { fndef })
954+ vim .fn .cursor ({ append_line + 1 , # fndef })
940955 return vim .cmd (' startinsert!' )
941956 end
942957 local last_line = vim .api .nvim_buf_line_count (0 )
943- vim .api .nvim_buf_set_lines (0 , last_line , last_line , false , { ' ' , ' * Footnotes' , footnote_reference . value .. ' ' })
944- vim .fn .cursor ({ last_line + 3 , # footnote_reference . value + 1 })
958+ vim .api .nvim_buf_set_lines (0 , last_line , last_line , false , { ' ' , ' * Footnotes' , fndef })
959+ vim .fn .cursor ({ last_line + 3 , # fndef })
945960 return vim .cmd (' startinsert!' )
946961 end
947962
948- local is_footnote_marker = footnote .range :is_same (footnote_reference .range )
949-
950- if not is_footnote_marker then
951- return vim .fn .cursor ({ footnote .range .start_line , footnote .range .start_col })
952- end
953-
954- local reference = file :find_footnote_reference (footnote )
955-
956- if reference then
957- return vim .fn .cursor ({ reference .range .start_line , reference .range .start_col })
958- end
959-
960- utils .echo_info ((' Cannot find reference for footnote "%s"' ):format (footnote_reference :get_name ()))
963+ return vim .fn .cursor ({ footnote .range .start_line , footnote .range .start_col })
961964end
962965
963966function OrgMappings :export ()
0 commit comments