mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-10-20 12:19:36 +00:00
Use GuessMimeType for mime based completion
complete_by_mimepat called mime.TypeByExtension directly, so it saw only the extensions the Go standard library knows about. Everything else in kitty that needs a mime type goes through utils.GuessMimeType, which also consults the user's mime.types, kitty's builtin types and KnownExtensions. As a result files like foo.py or foo.toml were not offered when completing arguments that ask for text/*, even though kitten pager opens them as text.
This commit is contained in:
parent
d37f845293
commit
579c735014
2 changed files with 15 additions and 11 deletions
|
|
@ -4,7 +4,6 @@ package cli
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"mime"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
|
|
@ -191,16 +190,7 @@ func complete_by_mimepat(prefix, cwd string, patterns []string) []string {
|
|||
if all_allowed {
|
||||
return true
|
||||
}
|
||||
idx := strings.Index(name, ".")
|
||||
if idx < 1 {
|
||||
return false
|
||||
}
|
||||
ext := name[idx:]
|
||||
mt := mime.TypeByExtension(ext)
|
||||
if mt == "" {
|
||||
ext = filepath.Ext(name)
|
||||
mt = mime.TypeByExtension(ext)
|
||||
}
|
||||
mt := utils.GuessMimeType(name)
|
||||
if mt == "" {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,20 @@ func TestCompleteFiles(t *testing.T) {
|
|||
if !found {
|
||||
t.Fatalf("Directory containing only an uppercase extension match not completed by FnmatchCompleter: %#v", c.Groups)
|
||||
}
|
||||
|
||||
// mime types kitty knows about but the Go stdlib does not
|
||||
create("zz.py")
|
||||
c = NewCompletions()
|
||||
MimepatCompleter("", CWD, "text/*")(c, "zz", 0)
|
||||
found = false
|
||||
for _, g := range c.Groups {
|
||||
for _, m := range g.Matches {
|
||||
found = found || m.Word == "zz.py"
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("File with a mime type known only to kitty not completed by MimepatCompleter: %#v", c.Groups)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompleteExecutables(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue