-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathblock_iterator.go
More file actions
38 lines (33 loc) · 788 Bytes
/
block_iterator.go
File metadata and controls
38 lines (33 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package draftjs
type BlockIterator struct {
block *ContentBlock
index int
contentState *ContentState
}
func NewBlockIterator(contentState *ContentState) *BlockIterator {
bi := new(BlockIterator)
bi.contentState = contentState
bi.index = 0
if len(contentState.Blocks) > 0 {
bi.block = contentState.Blocks[0]
}
return bi
}
func (bi *BlockIterator) HasNext() bool {
return len(bi.contentState.Blocks) != 0 && bi.index+1 < len(bi.contentState.Blocks)
}
func (bi *BlockIterator) StepNext() *BlockIterator {
if bi.HasNext() {
bi.index++
bi.block = bi.contentState.Blocks[bi.index]
return bi
}
bi.block = nil
return nil
}
func (bi BlockIterator) NextBlock() *ContentBlock {
if bi.HasNext() {
return bi.contentState.Blocks[bi.index+1]
}
return nil
}