Skip to content

Commit

Permalink
fix: 修复编辑器光标错乱问题 (#2927)
Browse files Browse the repository at this point in the history
* fix: 修复手动添加换行符导致光标错乱

* fix: 编辑配置文件侧滑关闭,重置内容
  • Loading branch information
Yuikill authored Jan 25, 2024
1 parent a0156af commit df136bc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ const formDataContent = ref({
const showContent = computed({
get: () => (formData.value.type === 'shell' ? formDataContent.value.shell : formDataContent.value.python),
set: (val) => {
if (!val.endsWith('\n')) {
val += '\n';
}
formData.value.type === 'shell' ? formDataContent.value.shell = val : formDataContent.value.python = val;
},
});
Expand Down Expand Up @@ -133,6 +130,9 @@ const handleCreate = async () => {
try {
pending.value = true;
formData.value.tag = selectTags.value[0];
if (!formData.value.content.endsWith('\n')) {
formData.value.content += '\n';
}
await createScript(spaceId.value, formData.value);
BkMessage({
theme: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ const handleSelectPrivilege = (index: number, val: number[]) => {
};
const handleStringContentChange = (val: string) => {
if (!val.endsWith('\n')) {
val += '\n';
}
stringContent.value = val;
change();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
@change="handleFormChange"
/>
<section class="action-btns">
<bk-button theme="primary" :loading="pending" :disabled="fileUploading" @click="handleSubmit">{{ t('保存') }}</bk-button>
<bk-button theme="primary" :loading="pending" :disabled="fileUploading" @click="handleSubmit">{{
t('保存')
}}</bk-button>
<bk-button @click="close">{{ t('取消') }}</bk-button>
</section>
</bk-sideslider>
Expand Down Expand Up @@ -63,7 +65,6 @@ watch(
},
);
const handleFormChange = (data: IConfigEditParams, configContent: IFileConfigContentSummary | string) => {
configForm.value = data;
const { privilege, user, user_group } = data;
Expand Down Expand Up @@ -94,9 +95,11 @@ const handleSubmit = async () => {
pending.value = true;
const sign = await formRef.value.getSignature();
let size = 0;
if (configForm.value.file_type === 'binary') {
size = Number((content.value as IFileConfigContentSummary).size);
} else {
if (typeof content.value === 'string' && !content.value.endsWith('\n')) content.value += '\n';
const stringContent = content.value as string;
size = new Blob([stringContent]).size;
await updateConfigContent(props.bkBizId, props.appId, stringContent, sign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const handleSubmit = async () => {
if (configForm.value.file_type === 'binary') {
size = Number((content.value as IFileConfigContentSummary).size);
} else {
if (typeof content.value === 'string' && !content.value.endsWith('\n')) content.value += '\n';
const stringContent = content.value as string;
size = new Blob([stringContent]).size;
await updateConfigContent(props.bkBizId, props.appId, stringContent, sign);
Expand All @@ -159,6 +160,8 @@ const handleSubmit = async () => {
};
const close = () => {
content.value = '';
configForm.value = getConfigEditParams();
emits('update:show', false);
};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const handleCreateConfirm = async (pkgIds: number[]) => {
if (configForm.value.file_type === 'binary') {
size = Number((content.value as IFileConfigContentSummary).size);
} else {
if (typeof content.value === 'string' && !content.value.endsWith('\n')) content.value += '\n';
const stringContent = content.value as string;
size = new Blob([stringContent]).size;
await updateTemplateContent(spaceId.value, currentTemplateSpace.value, stringContent, sign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const getBoundCount = async () => {
// 上传配置内容
const uploadContent = async () => {
const signature = await getSignature();
if (typeof stringContent.value === 'string' && !stringContent.value.endsWith('\n')) stringContent.value += '\n';
const data = formData.value.file_type === 'binary' ? fileContent.value : stringContent.value;
uploadPending.value = true;
// @ts-ignore
Expand Down

0 comments on commit df136bc

Please sign in to comment.