diff --git a/oviewer/event.go b/oviewer/event.go index 02e35e47..0eada893 100644 --- a/oviewer/event.go +++ b/oviewer/event.go @@ -45,9 +45,9 @@ func (root *Root) eventLoop(ctx context.Context, quitChan chan<- struct{}) { case *eventCloseDocument: root.closeDocument() case *eventCopySelect: - root.putClipboard(ctx) + root.copyToClipboard(ctx) case *eventPaste: - root.getClipboard(ctx) + root.pasteFromClipboard(ctx) case *eventViewMode: root.setViewMode(ev.value) case *eventInputSearch: diff --git a/oviewer/logdoc.go b/oviewer/logdoc.go index 3354c9e1..615b6d2b 100644 --- a/oviewer/logdoc.go +++ b/oviewer/logdoc.go @@ -29,15 +29,16 @@ func (m *Document) Write(p []byte) (int, error) { s := m.store chunk := s.chunkForAdd(false, s.size) s.append(chunk, true, p) - if len(chunk.lines) >= ChunkSize { - chunk = NewChunk(s.size) - s.mu.Lock() - if len(s.chunks) > 2 { - s.chunks[len(s.chunks)-2].lines = nil - atomic.StoreInt32(&s.startNum, int32(ChunkSize*(len(s.chunks)-1))) - } - s.chunks = append(s.chunks, chunk) - s.mu.Unlock() + if len(chunk.lines) < ChunkSize { + return len(p), nil } + chunk = NewChunk(s.size) + s.mu.Lock() + if len(s.chunks) > 2 { + s.chunks[len(s.chunks)-2].lines = nil + atomic.StoreInt32(&s.startNum, int32(ChunkSize*(len(s.chunks)-1))) + } + s.chunks = append(s.chunks, chunk) + s.mu.Unlock() return len(p), nil } diff --git a/oviewer/mouse.go b/oviewer/mouse.go index 655afa59..97559acb 100644 --- a/oviewer/mouse.go +++ b/oviewer/mouse.go @@ -152,8 +152,8 @@ func (root *Root) sendCopySelect() { root.postEvent(ev) } -// putClipboard writes the selection to the clipboard. -func (root *Root) putClipboard(_ context.Context) { +// copyToClipboard writes the selection to the clipboard. +func (root *Root) copyToClipboard(_ context.Context) { x1 := root.x1 x2 := root.x2 y1 := root.y1 @@ -170,7 +170,7 @@ func (root *Root) putClipboard(_ context.Context) { } buff, err := root.rangeToString(x1, y1, x2, y2) if err != nil { - root.debugMessage(fmt.Sprintf("putClipboard: %s", err.Error())) + root.debugMessage(fmt.Sprintf("copyToClipboard: %s", err.Error())) return } @@ -178,7 +178,7 @@ func (root *Root) putClipboard(_ context.Context) { return } if err := clipboard.WriteAll(buff); err != nil { - log.Printf("putClipboard: %v", err) + log.Printf("copyToClipboard: %v", err) } root.setMessage("Copy") } @@ -201,8 +201,8 @@ func (root *Root) sendPaste() { root.postEvent(ev) } -// getClipboard writes a string from the clipboard. -func (root *Root) getClipboard(_ context.Context) { +// pasteFromClipboard writes a string from the clipboard. +func (root *Root) pasteFromClipboard(_ context.Context) { input := root.input switch input.Event.Mode() { case Normal: @@ -211,7 +211,7 @@ func (root *Root) getClipboard(_ context.Context) { str, err := clipboard.ReadAll() if err != nil { - log.Printf("getClipboard: %v", err) + log.Printf("pasteFromClipboard: %v", err) return } diff --git a/oviewer/search.go b/oviewer/search.go index 0579ff8b..bc316e46 100644 --- a/oviewer/search.go +++ b/oviewer/search.go @@ -224,7 +224,6 @@ func condRegexpCompile(in string) *regexp.Regexp { } // searchPosition returns the position where the search in the argument line matched. -// searchPosition uses cache. func (root *Root) searchPosition(lN int, str string) [][]int { return root.searcher.FindAll(str) }