mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 02:28:04 +08:00 
			
		
		
		
	fix(editor): 代码编辑器只有在内容发生变化时才触发保存
This commit is contained in:
		
							parent
							
								
									42b043670e
								
							
						
					
					
						commit
						5b3c700f00
					
				@ -81,7 +81,7 @@ const setEditorValue = (v: string | any, m: string | any) => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getEditorValue = () =>
 | 
			
		||||
  props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
 | 
			
		||||
  (props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || '';
 | 
			
		||||
 | 
			
		||||
const init = async () => {
 | 
			
		||||
  if (!codeEditor.value) return;
 | 
			
		||||
@ -109,13 +109,19 @@ const init = async () => {
 | 
			
		||||
    if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
 | 
			
		||||
      e.preventDefault();
 | 
			
		||||
      e.stopPropagation();
 | 
			
		||||
      emit('save', getEditorValue());
 | 
			
		||||
      const newValue = getEditorValue();
 | 
			
		||||
      values.value = newValue;
 | 
			
		||||
      emit('save', newValue);
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  if (props.type !== 'diff' && props.autoSave) {
 | 
			
		||||
    vsEditor?.onDidBlurEditorWidget(() => {
 | 
			
		||||
      emit('save', getEditorValue());
 | 
			
		||||
      const newValue = getEditorValue();
 | 
			
		||||
      if (values.value !== newValue) {
 | 
			
		||||
        values.value = newValue;
 | 
			
		||||
        emit('save', newValue);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -146,10 +152,20 @@ onUnmounted(() => {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
defineExpose({
 | 
			
		||||
  values,
 | 
			
		||||
 | 
			
		||||
  getEditor() {
 | 
			
		||||
    return vsEditor || vsDiffEditor;
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  getVsEditor() {
 | 
			
		||||
    return vsEditor;
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  getVsDiffEditor() {
 | 
			
		||||
    return vsDiffEditor;
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  setEditorValue,
 | 
			
		||||
 | 
			
		||||
  focus() {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user