mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-23 17:27:14 +09:00
Simplify UpdateDiff() interface
The callback passed to UpdateDiff() is superfluous: in the synchronous case screen.Redraw() is not needed anyway (since the screen is redrawn at every iteration of the main loop), and in the asynchronous case UpdateDiff() can just call screen.Redraw() directly.
This commit is contained in:
@@ -1320,13 +1320,9 @@ func (b *Buffer) updateDiffSync() {
|
||||
|
||||
// UpdateDiff computes the diff between the diff base and the buffer content.
|
||||
// The update may be performed synchronously or asynchronously.
|
||||
// UpdateDiff calls the supplied callback when the update is complete.
|
||||
// The argument passed to the callback is set to true if and only if
|
||||
// the update was performed synchronously.
|
||||
// If an asynchronous update is already pending when UpdateDiff is called,
|
||||
// UpdateDiff does not schedule another update, in which case the callback
|
||||
// is not called.
|
||||
func (b *Buffer) UpdateDiff(callback func(bool)) {
|
||||
// UpdateDiff does not schedule another update.
|
||||
func (b *Buffer) UpdateDiff() {
|
||||
if b.updateDiffTimer != nil {
|
||||
return
|
||||
}
|
||||
@@ -1338,19 +1334,17 @@ func (b *Buffer) UpdateDiff(callback func(bool)) {
|
||||
|
||||
if lineCount < 1000 {
|
||||
b.updateDiffSync()
|
||||
callback(true)
|
||||
} else if lineCount < 30000 {
|
||||
b.updateDiffTimer = time.AfterFunc(500*time.Millisecond, func() {
|
||||
b.updateDiffTimer = nil
|
||||
b.updateDiffSync()
|
||||
callback(false)
|
||||
screen.Redraw()
|
||||
})
|
||||
} else {
|
||||
// Don't compute diffs for very large files
|
||||
b.diffLock.Lock()
|
||||
b.diff = make(map[int]DiffStatus)
|
||||
b.diffLock.Unlock()
|
||||
callback(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1362,9 +1356,7 @@ func (b *Buffer) SetDiffBase(diffBase []byte) {
|
||||
} else {
|
||||
b.diffBaseLineCount = strings.Count(string(diffBase), "\n")
|
||||
}
|
||||
b.UpdateDiff(func(synchronous bool) {
|
||||
screen.Redraw()
|
||||
})
|
||||
b.UpdateDiff()
|
||||
}
|
||||
|
||||
// DiffStatus returns the diff status for a line in the buffer
|
||||
|
||||
Reference in New Issue
Block a user