fix(config_help): jump to section heading via psub + --jump-target
--pattern matched the first textual occurrence of the keyword anywhere in the document. Replace with psub to make bat's output seekable, then use --jump-target with the line number resolved by grep against heading lines only (^#+.*keyword), so keyword jumps land on the actual section header rather than an example or body reference.
This commit is contained in:
@@ -51,27 +51,25 @@ function config_help --description 'Open the offline fish shell configuration ma
|
||||
# bat emits: ESC[<color>m# ... so delimiter ^(\x1b\[[0-9;]*m)+# matches
|
||||
# any 8/24-bit color sequence before a '#', theme-agnostic.
|
||||
# Section nav: Space (next), ^ (previous), Alt+u (section list sidebar).
|
||||
# Keyword jump uses --pattern which positions at the first search match.
|
||||
# psub creates a seekable temp file so --jump-target works on bat output.
|
||||
if type -q ov; and type -q bat
|
||||
set -l ov_args \
|
||||
--section-delimiter "^(\x1b\[[0-9;]*m)+#" \
|
||||
--section-header
|
||||
if test -n "$argv[1]"
|
||||
set -a ov_args --pattern "$argv[1]"
|
||||
if test $start_line -gt 1
|
||||
set -a ov_args --jump-target $start_line
|
||||
end
|
||||
bat --color=always --style=plain --language=markdown "$doc_file" \
|
||||
| ov $ov_args
|
||||
ov $ov_args (bat --color=always --style=plain --language=markdown "$doc_file" | psub)
|
||||
|
||||
# ov alone: section navigation on raw Markdown; no code highlighting.
|
||||
else if type -q ov
|
||||
set -l ov_args \
|
||||
--section-delimiter "^#" \
|
||||
--section-header \
|
||||
"$doc_file"
|
||||
if test -n "$argv[1]"
|
||||
set -a ov_args --pattern "$argv[1]"
|
||||
--section-header
|
||||
if test $start_line -gt 1
|
||||
set -a ov_args --jump-target $start_line
|
||||
end
|
||||
ov $ov_args
|
||||
ov $ov_args "$doc_file"
|
||||
|
||||
# bat alone: syntax highlighting with built-in paging; no line jump.
|
||||
else if type -q bat
|
||||
|
||||
Reference in New Issue
Block a user