Skip to content

Commit 1048a98

Browse files
committed
fix: 移除配置时处理配置为空的情况
1 parent f917276 commit 1048a98

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

module/ohMyRime/lang_model.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,21 @@ func RemoveLangModel() error {
151151
return nil
152152
}
153153

154-
// 更新 config 中的 patch
155-
config[patchIndex].Value = newPatchSlice
154+
if len(newPatchSlice) == 0 {
155+
// 如果 patch 为空,则从 config 中移除 patch 字段
156+
config = append(config[:patchIndex], config[patchIndex+1:]...)
157+
} else {
158+
// 更新 config 中的 patch
159+
config[patchIndex].Value = newPatchSlice
160+
}
156161

157162
// 写入文件
158-
data, err := yaml.Marshal(config)
159-
if err != nil {
160-
return err
163+
var data []byte
164+
if len(config) > 0 {
165+
data, err = yaml.Marshal(config)
166+
if err != nil {
167+
return err
168+
}
161169
}
162170

163171
err = os.WriteFile(rimeMintCustomYamlPath, data, 0644)

0 commit comments

Comments
 (0)