Skip to content

Commit

Permalink
commands: Navigate to changed on CREATE
Browse files Browse the repository at this point in the history
When working with content from IntelliJ IDE,
like WebStorm, every file save is followed by
two events: "RENAME" and then "CREATE".
  • Loading branch information
Vasiliy Solovey authored and bep committed Jul 8, 2017
1 parent fd41e70 commit 7bcc1ce
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,8 @@ func (c *commandeer) newWatcher(port int) error {

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

if name != "" {
p = Hugo.GetContentPage(name)
Expand Down Expand Up @@ -1027,11 +1027,11 @@ func (c *commandeer) newWatcher(port int) error {
return nil
}

func pickOneWritePath(events []fsnotify.Event) string {
func pickOneWriteOrCreatePath(events []fsnotify.Event) string {
name := ""

for _, ev := range events {
if ev.Op&fsnotify.Write == fsnotify.Write && len(ev.Name) > len(name) {
if (ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create) && len(ev.Name) > len(name) {
name = ev.Name
}
}
Expand Down

0 comments on commit 7bcc1ce

Please sign in to comment.