Skip to content

Commit 7bcc1ce

Browse files
goodness-from-mebep
authored andcommitted
commands: Navigate to changed on CREATE
When working with content from IntelliJ IDE, like WebStorm, every file save is followed by two events: "RENAME" and then "CREATE".
1 parent fd41e70 commit 7bcc1ce

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎commands/hugo.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,8 @@ func (c *commandeer) newWatcher(port int) error {
990990

991991
// It is probably more confusing than useful
992992
// to navigate to a new URL on RENAME etc.
993-
// so for now we use the WRITE event only.
994-
name := pickOneWritePath(dynamicEvents)
993+
// so for now we use the WRITE and CREATE events only.
994+
name := pickOneWriteOrCreatePath(dynamicEvents)
995995

996996
if name != "" {
997997
p = Hugo.GetContentPage(name)
@@ -1027,11 +1027,11 @@ func (c *commandeer) newWatcher(port int) error {
10271027
return nil
10281028
}
10291029

1030-
func pickOneWritePath(events []fsnotify.Event) string {
1030+
func pickOneWriteOrCreatePath(events []fsnotify.Event) string {
10311031
name := ""
10321032

10331033
for _, ev := range events {
1034-
if ev.Op&fsnotify.Write == fsnotify.Write && len(ev.Name) > len(name) {
1034+
if (ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create) && len(ev.Name) > len(name) {
10351035
name = ev.Name
10361036
}
10371037
}

0 commit comments

Comments
 (0)