Skip to content

Commit

Permalink
1.0.26 文件编辑问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobaidadada committed Dec 19, 2024
1 parent 84a2c75 commit 5ad5857
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filecat",
"version": "1.0.25",
"version": "1.0.26",
"description": "filecat 文件管理器",
"author": "xiaobaidadada",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/web/project/component/file/component/Ace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {editor_data} from "../../../util/store.util";



export default function Ace(props:{name: string,on_change?:()=>void,init?:(editor:AceItem.Editor)=>void,options?: Partial<AceItem.EditorOptions>}) {
export default function Ace(props:{name: string,on_change?:()=>void,options?: Partial<AceItem.EditorOptions>}) {
const editorRef = useRef(null);

useEffect(() => {
Expand Down Expand Up @@ -50,10 +50,10 @@ export default function Ace(props:{name: string,on_change?:()=>void,init?:(edito
}
});
editorRef.current = editor;
if (props.init) {
props.init(editor);
}
editor_data.set_editor_temp(editor);

return () => {
editor_data.set_editor_temp(null);
editor.destroy();
};
}, []);
Expand Down
10 changes: 7 additions & 3 deletions src/web/project/component/file/component/FileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Ace from "./Ace";
export default function FileEditor() {
const [editorSetting, setEditorSetting] = useRecoilState($stroe.editorSetting)
const [have_update,set_have_update] = useState(false);
const [editor,set_editor] = useState(undefined);

function handleEditorChange() {
if (!have_update) {
Expand All @@ -27,7 +26,7 @@ export default function FileEditor() {
}
async function save() {
if (editorSetting.save && have_update) {
await editorSetting.save(editor.getValue() );
await editorSetting.save(editor_data.get_deitor_value() );
editor_data.set_value_temp('');
// NotySucess("保存成功")
set_have_update(false);
Expand All @@ -42,6 +41,11 @@ export default function FileEditor() {
}
}
};
useEffect(() => {
return () => {
set_have_update(false);
}
}, [editorSetting]);
useEffect(() => {
document.addEventListener('keydown', handleKeyDown);

Expand All @@ -56,7 +60,7 @@ export default function FileEditor() {
{editorSetting.menu_list && editorSetting.menu_list}
{have_update && <ActionButton title={"保存"} icon={"save"} onClick={save}/>}
</Header>
<Ace name={editorSetting.fileName} on_change={handleEditorChange} init={(v)=>set_editor(v)}/>
<Ace name={editorSetting.fileName} on_change={handleEditorChange} />
</div>;
return editorSetting.open && div
}
3 changes: 3 additions & 0 deletions src/web/project/component/prompts/FileNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export function FileNew(props) {
<div className="card-content">
<InputText placeholderOut={t("输入文件名")} value={name}
handleInputChange={(value) => setName(value)}/>
<Select value={format} onChange={(value:FileCompressType)=>{
setFormat(value);
}} options={select_item}/>
</div>]}
confirm_enter={dirnew}
/>)
Expand Down
13 changes: 13 additions & 0 deletions src/web/project/util/store.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {$stroe} from "./store";
import {saveTxtReq} from "../../../common/req/file.req";
import {useTranslation} from "react-i18next";
import { MAX_SIZE_TXT } from "../../../common/ValueUtil";
import ace, {Ace as AceItem, version as ace_version} from "ace-builds";

async function get_file_context(path,is_sys_path) {
if(is_sys_path) {
Expand Down Expand Up @@ -120,11 +121,23 @@ export const user_click_file = () => {
export class editor_data {

static cache_str: string = "";
static editor:AceItem.Editor|null = null;

public static set_value_temp(v: string) {
editor_data.cache_str = v;
}

public static set_editor_temp(v:AceItem.Editor |null) {
editor_data.editor = v;
}

public static get_deitor_value() {
if (!editor_data.editor) {
throw "不存在编辑器";
}
return editor_data.editor.getValue();
}

public static get_value_temp() {
return editor_data.cache_str;
}
Expand Down

0 comments on commit 5ad5857

Please sign in to comment.