@@ -539,6 +539,7 @@ import {useWorkspaceRoots} from './composables/useWorkspaceRoots'
539539import {useGitStatus } from ' ./composables/useGitStatus'
540540import {useSessionTabs } from ' ./composables/useSessionTabs'
541541import {useEditorContextMenu } from ' ./composables/useEditorContextMenu'
542+ import {useRunConfig } from ' ./composables/useRunConfig'
542543import EditorTabs from ' ./components/EditorTabs.vue'
543544import IndentControl from ' ./components/IndentControl.vue'
544545import Sidebar from ' ./components/Sidebar.vue'
@@ -1779,44 +1780,8 @@ const handleSave = async () => {
17791780}
17801781
17811782// ===== 按文件记忆运行配置(args/stdin/env)=====
1782- const RUN_CONFIGS_KEY = ' run-configs'
1783- type RunConfig = { args: string , stdin: string , env: string }
1784- const loadRunConfigs = (): Record <string , RunConfig > =>
1785- kvGetJSON <Record <string , RunConfig >>(RUN_CONFIGS_KEY , {})
1786- // 把当前输入写入指定文件的配置(全空则删除该条)
1787- const saveRunConfig = (path : string ) => {
1788- const map = loadRunConfigs ()
1789- if (! runArgs .value && ! runStdin .value && ! runEnv .value ) {
1790- delete map [path ]
1791- }
1792- else {
1793- map [path ] = {args: runArgs .value , stdin: runStdin .value , env: runEnv .value }
1794- }
1795- kvSetJSON (RUN_CONFIGS_KEY , map )
1796- }
1797- // 载入指定文件的配置(无则清空)
1798- const loadRunConfig = (path : string | null ) => {
1799- const cfg = path ? loadRunConfigs ()[path ] : null
1800- runArgs .value = cfg ?.args || ' '
1801- runStdin .value = cfg ?.stdin || ' '
1802- runEnv .value = cfg ?.env || ' '
1803- }
1804-
1805- // 切换文件时:保存旧文件输入、载入新文件输入
1806- watch (currentFilePath , (np , op ) => {
1807- if (op ) {
1808- saveRunConfig (op )
1809- }
1810- loadRunConfig (np )
1811- })
1812-
1813- // 编辑输入时防抖保存到当前文件
1814- const persistRunConfig = debounce (() => {
1815- if (currentFilePath .value ) {
1816- saveRunConfig (currentFilePath .value )
1817- }
1818- }, 400 )
1819- watch ([runArgs , runStdin , runEnv ], () => persistRunConfig ())
1783+ // 按文件记忆运行输入(参数/stdin/环境变量)—— 抽离到 useRunConfig
1784+ useRunConfig (currentFilePath , runArgs , runStdin , runEnv )
18201785
18211786// 解析环境变量文本(KEY=值,按换行或分号分隔)
18221787const parseEnv = (text : string ): Record <string , string > => {
0 commit comments