mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 22:16:14 +01:00
git-grep: add comments on highlighting support
This commit is contained in:
parent
9c70c7a8ea
commit
cd62d0f5e8
1 changed files with 4 additions and 0 deletions
|
@ -85,6 +85,9 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
|
||||||
"-I", "--null", "--break", "--heading",
|
"-I", "--null", "--break", "--heading",
|
||||||
"--line-number", "--ignore-case", "--full-name")
|
"--line-number", "--ignore-case", "--full-name")
|
||||||
if opts.Mode == RegExpGrepMode {
|
if opts.Mode == RegExpGrepMode {
|
||||||
|
// No `--column` -- regexp mode does not support highlighting in the
|
||||||
|
// current implementation as the length of the match is unknown from
|
||||||
|
// `grep` but required for highlighting.
|
||||||
cmd.AddArguments("--perl-regexp")
|
cmd.AddArguments("--perl-regexp")
|
||||||
} else {
|
} else {
|
||||||
cmd.AddArguments("--fixed-strings", "--column")
|
cmd.AddArguments("--fixed-strings", "--column")
|
||||||
|
@ -161,6 +164,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
|
||||||
if lineNum, lineCode, ok := strings.Cut(line, "\x00"); ok {
|
if lineNum, lineCode, ok := strings.Cut(line, "\x00"); ok {
|
||||||
lineNumInt, _ := strconv.Atoi(lineNum)
|
lineNumInt, _ := strconv.Atoi(lineNum)
|
||||||
res.LineNumbers = append(res.LineNumbers, lineNumInt)
|
res.LineNumbers = append(res.LineNumbers, lineNumInt)
|
||||||
|
// We support highlighting only when `--column` parameter is used.
|
||||||
if lineCol, lineCode2, ok := strings.Cut(lineCode, "\x00"); ok {
|
if lineCol, lineCode2, ok := strings.Cut(lineCode, "\x00"); ok {
|
||||||
lineColInt, _ := strconv.Atoi(lineCol)
|
lineColInt, _ := strconv.Atoi(lineCol)
|
||||||
start := lineColInt - 1
|
start := lineColInt - 1
|
||||||
|
|
Loading…
Reference in a new issue