Skip to content

Commit e70f801

Browse files
committed
refactor
1 parent 26c4215 commit e70f801

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

scanner/context.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ func (c *Context) addDocumentIndent(column int) {
145145

146146
// If the first line of the document has already been evaluated, the number is treated as the threshold, since the `docFirstLineIndentColumn` is a positive number.
147147
if c.docFirstLineIndentColumn <= column {
148-
// In the folded state, new-line-char is normally treated as space,
149-
// but if the number of indents is different from the number of indents in the first line,
150-
// new-line-char is used as is instead of space.
151-
// Therefore, it is necessary to replace the space already added to buf.
152148
// `c.docFoldedNewLine` is a variable that is set to true for every newline.
153149
if (c.isFolded || c.isRawFolded) && c.docFoldedNewLine {
154150
c.docFoldedNewLine = false
@@ -158,10 +154,15 @@ func (c *Context) addDocumentIndent(column int) {
158154
}
159155
}
160156

161-
func (c *Context) addDocumentNewLineInFolded(column int) {
157+
// updateDocumentNewLineInFolded if Folded or RawFolded context and the content on the current line starts at the same column as the previous line,
158+
// treat the new-line-char as a space.
159+
func (c *Context) updateDocumentNewLineInFolded(column int) {
162160
if c.isLiteral {
163161
return
164162
}
163+
164+
// Folded or RawFolded.
165+
165166
if !c.docFoldedNewLine {
166167
return
167168
}
@@ -170,11 +171,6 @@ func (c *Context) addDocumentNewLineInFolded(column int) {
170171
c.buf[len(c.buf)-1] = ' '
171172
}
172173
}
173-
if c.docFirstLineIndentColumn == c.docLineIndentColumn &&
174-
c.docLineIndentColumn == c.docPrevLineIndentColumn {
175-
// use space as a new line delimiter.
176-
return
177-
}
178174
c.docFoldedNewLine = false
179175
}
180176

scanner/scanner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func (s *Scanner) scanDocument(ctx *Context, c rune) error {
576576
s.progressColumn(ctx, 1)
577577
return ErrInvalidToken(err.Error(), invalidTk)
578578
}
579-
ctx.addDocumentNewLineInFolded(s.column)
579+
ctx.updateDocumentNewLineInFolded(s.column)
580580
ctx.addBuf(c)
581581
s.progressColumn(ctx, 1)
582582
}

0 commit comments

Comments
 (0)