130
130
</div >
131
131
</div >
132
132
</div >
133
- <EditorSettings v-model:visible =" settingsDialogVisible" :initial-settings =" {
134
- autoCompleteBrackets,
135
- bracketColorEnabled,
136
- horizontalLayout,
137
- language: props.language
138
- }" :t =" t" @save =" handleSettingsSave" @cancel =" handleSettingsCancel" />
133
+ <EditorSettings
134
+ v-model:visible =" settingsDialogVisible"
135
+ :initial-settings =" currentSettings"
136
+ :t =" t"
137
+ @save =" handleSettingsSave"
138
+ @cancel =" handleSettingsCancel"
139
+ />
139
140
<VariableSuggestions v-model:visible =" showVariableSuggestions" :suggestions =" variableSuggestions"
140
141
:selectedIndex =" selectedSuggestionIndex" :wrapper-ref =" wrapperRef" :t =" t" @select =" handleVariableSelect"
141
142
@close =" handleSuggestionsClose" />
@@ -279,6 +280,17 @@ const isDarkMode = ref(false);
279
280
const settingsDialogVisible = ref (false );
280
281
const autoCompleteBrackets = ref (false );
281
282
const bracketColorEnabled = ref (false );
283
+ const horizontalLayout = ref (false ); // 将horizontalLayout的定义移到前面
284
+
285
+ // 添加 currentSettings ref
286
+ const currentSettings = ref ({
287
+ autoCompleteBrackets: autoCompleteBrackets .value ,
288
+ bracketColorEnabled: bracketColorEnabled .value ,
289
+ horizontalLayout: horizontalLayout .value ,
290
+ language: props .language ,
291
+ hideVariables: props .initialSettings ?.hideVariables || false ,
292
+ hideKeyboard: props .initialSettings ?.hideKeyboard || false ,
293
+ });
282
294
283
295
// 历史记录相关变量
284
296
const history = ref <string []>([]);
@@ -310,11 +322,15 @@ const formulaTextRef = ref<HTMLDivElement | null>(null);
310
322
const fontSize = ref (MAX_FONT_SIZE );
311
323
const isCircleStyle = ref (false );
312
324
const showExpression = ref (false );
313
- const horizontalLayout = ref (true ); // 添加horizontalLayout变量
314
325
315
- // 添加显示控制的计算属性
316
- const showVariablesEnabled = computed (() => ! props .hideVariables && ! props .initialSettings ?.hideVariables );
317
- const showKeyboardEnabled = computed (() => ! props .hideKeyboard && ! props .initialSettings ?.hideKeyboard );
326
+ // 修改显示控制的计算属性
327
+ const showVariablesEnabled = computed (() => {
328
+ return ! (currentSettings .value .hideVariables );
329
+ });
330
+
331
+ const showKeyboardEnabled = computed (() => {
332
+ return ! (currentSettings .value .hideKeyboard );
333
+ });
318
334
319
335
// 计算属性
320
336
const canUndo = computed (() => historyIndex .value > 0 );
@@ -1395,6 +1411,15 @@ const toggleTheme = () => {
1395
1411
};
1396
1412
1397
1413
const showSettingsDialog = () => {
1414
+ // 更新当前设置
1415
+ currentSettings .value = {
1416
+ autoCompleteBrackets: autoCompleteBrackets .value ,
1417
+ bracketColorEnabled: bracketColorEnabled .value ,
1418
+ horizontalLayout: horizontalLayout .value ,
1419
+ language: props .language ,
1420
+ hideVariables: props .initialSettings ?.hideVariables || false ,
1421
+ hideKeyboard: props .initialSettings ?.hideKeyboard || false
1422
+ };
1398
1423
settingsDialogVisible .value = true ;
1399
1424
};
1400
1425
@@ -1424,22 +1449,37 @@ const handleSettingsSave = (settings: {
1424
1449
bracketColorEnabled: boolean ;
1425
1450
horizontalLayout: boolean ;
1426
1451
language: string ;
1427
- hideVariables: boolean ; // 修改
1428
- hideKeyboard: boolean ; // 修改
1452
+ hideVariables: boolean ;
1453
+ hideKeyboard: boolean ;
1429
1454
}) => {
1455
+ // 更新本地状态
1456
+ currentSettings .value = { ... settings };
1430
1457
autoCompleteBrackets .value = settings .autoCompleteBrackets ;
1431
1458
bracketColorEnabled .value = settings .bracketColorEnabled ;
1432
1459
horizontalLayout .value = settings .horizontalLayout ;
1460
+
1461
+ // 更新初始设置中的隐藏选项
1462
+ if (props .initialSettings ) {
1463
+ props .initialSettings .hideVariables = settings .hideVariables ;
1464
+ props .initialSettings .hideKeyboard = settings .hideKeyboard ;
1465
+ }
1466
+
1467
+ // 保存到本地存储
1468
+ localStorage .setItem (' editor-settings' , JSON .stringify (settings ));
1469
+
1470
+ // 如果语言发生变化,触发更新
1433
1471
if (settings .language !== props .language ) {
1434
1472
emit (' update:language' , settings .language );
1435
1473
}
1436
- localStorage .setItem (' editor-settings' , JSON .stringify ({
1437
- ... settings ,
1438
- horizontalLayout: horizontalLayout .value ,
1439
- hideVariables: settings .hideVariables ,
1440
- hideKeyboard: settings .hideKeyboard
1441
- }));
1474
+
1475
+ // 关闭设置对话框
1442
1476
settingsDialogVisible .value = false ;
1477
+
1478
+ // 强制重新计算布局
1479
+ nextTick (() => {
1480
+ calculateFontSize ();
1481
+ window .dispatchEvent (new Event (' resize' ));
1482
+ });
1443
1483
};
1444
1484
1445
1485
// 添加取消设置的处理方法
@@ -1451,20 +1491,20 @@ const handleSettingsCancel = () => {
1451
1491
const loadSettings = () => {
1452
1492
try {
1453
1493
const localSettings = JSON .parse (localStorage .getItem (' editor-settings' ) || ' {}' );
1454
- const settings = {
1455
- autoCompleteBrackets: localSettings .autoCompleteBrackets ?? false ,
1456
- bracketColorEnabled: localSettings .bracketColorEnabled ?? false ,
1457
- isDarkMode: localSettings .isDarkMode ?? false ,
1458
- horizontalLayout: localSettings .horizontalLayout ?? true ,
1459
- hideVariables: localSettings .hideVariables ?? false ,
1460
- hideKeyboard: localSettings .hideKeyboard ?? false
1461
- };
1462
1494
1463
- autoCompleteBrackets .value = settings .autoCompleteBrackets ;
1464
- bracketColorEnabled .value = settings .bracketColorEnabled ;
1465
- isDarkMode .value = settings .isDarkMode ;
1466
- horizontalLayout .value = settings .horizontalLayout ;
1495
+ // 应用设置
1496
+ autoCompleteBrackets .value = localSettings .autoCompleteBrackets ?? false ;
1497
+ bracketColorEnabled .value = localSettings .bracketColorEnabled ?? false ;
1498
+ horizontalLayout .value = localSettings .horizontalLayout ?? false ;
1499
+ isDarkMode .value = localSettings .isDarkMode ?? false ;
1467
1500
1501
+ // 更新初始设置中的隐藏选项
1502
+ if (props .initialSettings ) {
1503
+ props .initialSettings .hideVariables = localSettings .hideVariables ?? false ;
1504
+ props .initialSettings .hideKeyboard = localSettings .hideKeyboard ?? false ;
1505
+ }
1506
+
1507
+ // 应用深色模式
1468
1508
if (isDarkMode .value ) {
1469
1509
document .documentElement .classList .add (' dark-mode' );
1470
1510
}
@@ -1505,7 +1545,24 @@ watch(horizontalLayout, () => {
1505
1545
});
1506
1546
});
1507
1547
1508
- // popoverProps 可以删除,因为已经移到子组件中
1548
+ // 监听初始设置的变化
1549
+ watch (() => props .initialSettings , (newSettings ) => {
1550
+ if (newSettings ) {
1551
+ currentSettings .value = {
1552
+ ... currentSettings .value ,
1553
+ hideVariables: newSettings .hideVariables ?? false ,
1554
+ hideKeyboard: newSettings .hideKeyboard ?? false
1555
+ };
1556
+ }
1557
+ }, { immediate: true });
1558
+
1559
+ // 监听本地设置的变化
1560
+ watch (currentSettings , (newSettings ) => {
1561
+ if (props .initialSettings ) {
1562
+ props .initialSettings .hideVariables = newSettings .hideVariables ;
1563
+ props .initialSettings .hideKeyboard = newSettings .hideKeyboard ;
1564
+ }
1565
+ }, { deep: true });
1509
1566
1510
1567
// 新增处理变量选择的方法
1511
1568
const handleVariableSelect = (_variable : Variable ) => {
0 commit comments