MCPcopy
hub / github.com/micro-editor/micro / ReOpen

Method ReOpen

internal/buffer/buffer.go:598–630  ·  view source on GitHub ↗

ReOpen reloads the current buffer from disk

()

Source from the content-addressed store, hash-verified

596
597// ReOpen reloads the current buffer from disk
598func (b *Buffer) ReOpen() error {
599 file, err := os.Open(b.Path)
600 if err != nil {
601 return err
602 }
603 defer file.Close()
604
605 enc, err := htmlindex.Get(b.Settings["encoding"].(string))
606 if err != nil {
607 return err
608 }
609
610 reader := bufio.NewReader(transform.NewReader(file, enc.NewDecoder()))
611 data, err := io.ReadAll(reader)
612 txt := string(data)
613
614 if err != nil {
615 return err
616 }
617 b.EventHandler.ApplyDiff(txt)
618
619 err = b.UpdateModTime()
620 if !b.Settings["fastdirty"].(bool) {
621 if len(data) > LargeFileThreshold {
622 b.Settings["fastdirty"] = true
623 } else {
624 b.calcHash(&b.origHash)
625 }
626 }
627 b.isModified = false
628 b.RelocateCursors()
629 return err
630}
631
632// RelocateCursors relocates all cursors (makes sure they are in the buffer)
633func (b *Buffer) RelocateCursors() {

Callers

nothing calls this directly

Calls 6

UpdateModTimeMethod · 0.95
RelocateCursorsMethod · 0.95
GetMethod · 0.80
ApplyDiffMethod · 0.80
calcHashMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected