Skip to content

Commit

Permalink
Refactor condition
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Nov 7, 2019
1 parent 0d1afe3 commit c61d2c3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ func (s *Scanner) progressLine(ctx *Context) {
ctx.progress(1)
}

func (s *Scanner) isNeededKeepPreviousIndentNum(ctx *Context, c rune) bool {
if !s.isChangedToIndentStateUp() {
return false
}
if ctx.isDocument() {
return true
}
if c == '-' && ctx.bufferedSrc() != "" {
return true
}
return false
}

func (s *Scanner) updateIndent(ctx *Context, c rune) {
if s.isFirstCharAtLine && c == ' ' {
s.indentNum++
Expand Down Expand Up @@ -120,9 +133,7 @@ func (s *Scanner) updateIndent(ctx *Context, c rune) {
}
}
s.isFirstCharAtLine = false
if ctx.isDocument() && s.isChangedToIndentStateUp() {
return
} else if c == '-' && ctx.bufferedSrc() != "" && s.isChangedToIndentStateUp() {
if s.isNeededKeepPreviousIndentNum(ctx, c) {
return
}
s.prevIndentNum = s.indentNum
Expand Down

0 comments on commit c61d2c3

Please sign in to comment.