MCPcopy Create free account
hub / github.com/cogentcore/core / Revert

Method Revert

texteditor/buffer.go:370–404  ·  view source on GitHub ↗

Revert re-opens text from the current file, if the filename is set; returns false if not. It uses an optimized diff-based update to preserve existing formatting, making it very fast if not very different.

()

Source from the content-addressed store, hash-verified

368// It uses an optimized diff-based update to preserve
369// existing formatting, making it very fast if not very different.
370func (tb *Buffer) Revert() bool { //types:add
371 tb.StopDelayedReMarkup()
372 tb.AutoSaveDelete() // justin case
373 if tb.Filename == "" {
374 return false
375 }
376
377 didDiff := false
378 if tb.NumLines() < diffRevertLines {
379 ob := NewBuffer()
380 err := ob.openFile(tb.Filename)
381 if errors.Log(err) != nil {
382 sc := tb.sceneFromEditor()
383 if sc != nil { // only if viewing
384 core.ErrorSnackbar(sc, err, "Error reopening file")
385 }
386 return false
387 }
388 tb.Stat() // "own" the new file..
389 if ob.NumLines() < diffRevertLines {
390 diffs := tb.DiffBuffers(&ob.Lines)
391 if len(diffs) < diffRevertDiffs {
392 tb.PatchFromBuffer(&ob.Lines, diffs)
393 didDiff = true
394 }
395 }
396 }
397 if !didDiff {
398 tb.openFile(tb.Filename)
399 }
400 tb.clearNotSaved()
401 tb.AutoSaveDelete()
402 tb.signalEditors(bufferNew, nil)
403 return true
404}
405
406// SaveAsFunc saves the current text into the given file.
407// Does an editDone first to save edits and checks for an existing file.

Callers 3

FileModCheckMethod · 0.95
SaveMethod · 0.95
revertVCSMethod · 0.80

Calls 13

AutoSaveDeleteMethod · 0.95
openFileMethod · 0.95
sceneFromEditorMethod · 0.95
StatMethod · 0.95
clearNotSavedMethod · 0.95
signalEditorsMethod · 0.95
LogFunction · 0.92
ErrorSnackbarFunction · 0.92
StopDelayedReMarkupMethod · 0.80
NumLinesMethod · 0.80
DiffBuffersMethod · 0.80
PatchFromBufferMethod · 0.80

Tested by

no test coverage detected