Repository: zyedidia/micro
File: internal/buffer/line_array.go (Go)

Code before:
		i++

		if i == n {
			break
		}
	}
	return count
}

// A searchState contains the search match info for a single line
type searchState struct {
	search     string
	useRegex   bool
	ignorecase bool
	match      [][2]int
	done       bool
}

// A Line contains the data in bytes as well as a highlight state, match
// and a flag for whether the highlighting needs to be updated
type Line struct {
	data []byte

	state highlight.State
	match highlight.LineMatch

	// The search states for the line, used for highlighting of search matches,
	// separately from the syntax highlighting.
	// A map is used because the line array may be shared between multiple buffers
	// (multiple instances of the same file opened in different edit panes)
	// which have distinct searches, so in the general case there are multiple
	// searches per a line, one search per a Buffer containing this line.
	search map[*Buffer]*searchState
}

const (
	// Line ending file formats
	FFAuto = 0 // Autodetect format
	FFUnix = 1 // LF line endings (unix style '\n')
	FFDos  = 2 // CRLF line endings (dos style '\r\n')
)

type FileFormat byte

// A LineArray simply stores and array of lines and makes it easy to insert
// and delete in it
type LineArray struct {
	lines    []Line
	Endings  FileFormat
	initsize uint64
	lock     sync.Mutex

Review comment (suggestion):
Just a note: I can actually imagine a use for it: if we move all the highlighting to the async goroutine (to fix the other race we were talking about: the race between initial highlighting in the async goroutine and rehighlighting in the main goroutine; i.e. to ensure that initial highlighting and rehighlighting for the given line are done in the correct order), then the main goroutine may call `SetRehighlight()` to let the async goroutine know that the given line requires rehighlighting.

But it's probably better to do such notifications using a channel, not a mutex-locked shared variable. So I'm ok with removing this.

Code after:
		i++

		if i == n {
			break
		}
	}
	return count
}

// A searchState contains the search match info for a single line
type searchState struct {
	search     string
	useRegex   bool
	ignorecase bool
	match      [][2]int
	done       bool
}

// A Line contains the data in bytes as well as a highlight state, match
// and a flag for whether the highlighting needs to be updated
type Line struct {
	data []byte

	state highlight.State
	match highlight.LineMatch
	lock  sync.Mutex

	// The search states for the line, used for highlighting of search matches,
	// separately from the syntax highlighting.
	// A map is used because the line array may be shared between multiple buffers
	// (multiple instances of the same file opened in different edit panes)
	// which have distinct searches, so in the general case there are multiple
	// searches per a line, one search per a Buffer containing this line.
	search map[*Buffer]*searchState
}

const (
	// Line ending file formats
	FFAuto = 0 // Autodetect format
	FFUnix = 1 // LF line endings (unix style '\n')
	FFDos  = 2 // CRLF line endings (dos style '\r\n')
)

type FileFormat byte

// A LineArray simply stores and array of lines and makes it easy to insert
// and delete in it
type LineArray struct {
	lines    []Line
	Endings  FileFormat
	initsize uint64