MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
This commit is contained in:
commit
a80c0f886a
220 files changed
+20784
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// restoreFromHistory 把某一条历史的内容放回编辑器。
|
||||
//
|
||||
// 只改缓冲区、不写盘:恢复完让用户自己对比、自己决定保存。
|
||||
func (a *App) restoreFromHistory(path string, e histEntry) {
|
||||
d := a.find(path)
|
||||
if d == nil {
|
||||
// 目录模式里恢复的文件可能还没打开,先打开再说。
|
||||
var err error
|
||||
d, err = a.loadDoc(path)
|
||||
if err != nil {
|
||||
a.alert("恢复失败", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
data, err := readSnapshot(path, e.Hash)
|
||||
if err != nil {
|
||||
a.alert("恢复失败", err.Error())
|
||||
return
|
||||
}
|
||||
text, _, ok := decodeFile(data)
|
||||
if !ok {
|
||||
a.alert("恢复失败", "这条历史的内容无法解码。")
|
||||
return
|
||||
}
|
||||
// 用 Set 而不是 Reset:恢复出来的内容必须是「未保存」状态。
|
||||
d.buf.Set(text)
|
||||
a.histView.open = false
|
||||
a.appendOut(fmt.Sprintf("已从本地历史恢复 %s(%s),尚未保存。",
|
||||
filepath.Base(path), historyTime(e.Time)))
|
||||
a.panel = true
|
||||
a.panelTab = 0
|
||||
a.panelH = 160
|
||||
a.refresh()
|
||||
}
|
||||
|
||||
// historyTime 把毫秒时间戳格式化成「今天 14:02:33」这种。
|
||||
func historyTime(ms int64) string {
|
||||
t := time.UnixMilli(ms)
|
||||
now := time.Now()
|
||||
if t.Format("2006-01-02") == now.Format("2006-01-02") {
|
||||
return t.Format("今天 15:04:05")
|
||||
}
|
||||
return t.Format("01-02 15:04")
|
||||
}
|
||||
|
||||
// historyReason 把存储里的原因翻成给人看的词。
|
||||
func historyReason(r string) string {
|
||||
switch r {
|
||||
case "save":
|
||||
return "保存"
|
||||
case "auto":
|
||||
return "自动"
|
||||
case "close":
|
||||
return "退出时未保存"
|
||||
}
|
||||
return r
|
||||
}
|
||||
Reference in new issue
Block a user