Skip to content

Commit cafad24

Browse files
committed
When opening a directory with a single file, open that file
1 parent ca0d70e commit cafad24

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: v2/neweditor.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,18 @@ func NewEditor(tty *vt100.TTY, c *vt100.Canvas, fnord FilenameOrData, lineNumber
190190

191191
// Check if this is a directory
192192
if fileInfo.IsDir() {
193-
e.dirMode = true
194-
// TODO: Support opening directories and giving a GitHub-like overview of projects and the git status
195-
// TODO: Consider supporting file rename, finding programming symbols or git push
196-
return e, "", false, errors.New("can not open directories")
193+
// Check if there is only one file in that directory
194+
matches, err := filepath.Glob(strings.TrimSuffix(e.filename, "/") + "/" + "*")
195+
if err == nil && len(matches) == 1 {
196+
found_filename := matches[0]
197+
fnord.filename = found_filename
198+
e.filename = found_filename
199+
} else {
200+
e.dirMode = true
201+
// TODO: Support opening directories and giving a GitHub-like overview of projects and the git status
202+
// TODO: Consider supporting file rename, finding programming symbols or git push
203+
return e, "", false, errors.New("can not open directories")
204+
}
197205
}
198206

199207
warningMessage, err = e.Load(c, tty, fnord)

0 commit comments

Comments
 (0)