Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: fix shortcut panel content not correct (#2267)
Wenzhao Hubf5880a8b2da
diff --git a/packages/core/src/services/locale/locale.service.ts b/packages/core/src/services/locale/locale.service.tsindex 701a5cedba..c54f305950 100644--- a/packages/core/src/services/locale/locale.service.ts+++ b/packages/core/src/services/locale/locale.service.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { Subject } from 'rxjs';+import { BehaviorSubject, Subject } from 'rxjs';import { Disposable, toDisposable } from '../../shared/lifecycle';import type { ILanguagePack, ILocales, LanguageValue } from '../../shared/locale';@@ -25,7 +25,9 @@ import { LocaleType } from '../../types/enum/locale-type';* This service provides i18n and timezone / location features to other modules.*/export class LocaleService extends Disposable {- private _currentLocale: LocaleType = LocaleType.ZH_CN;+ private _currentLocale$ = new BehaviorSubject<LocaleType>(LocaleType.ZH_CN);+ readonly currentLocale$ = this._currentLocale$.asObservable();+ private get _currentLocale(): LocaleType { return this._currentLocale$.value; }private _locales: ILocales | null = null;@@ -88,7 +90,7 @@ export class LocaleService extends Disposable {};setLocale(locale: LocaleType) {- this._currentLocale = locale;+ this._currentLocale$.next(locale);this.localeChanged$.next();}diff --git a/packages/sheets-ui/src/locale/en-US.ts b/packages/sheets-ui/src/locale/en-US.tsindex e9d0055c6d..d151471532 100644--- a/packages/sheets-ui/src/locale/en-US.ts+++ b/packages/sheets-ui/src/locale/en-US.ts@@ -494,6 +494,7 @@ const locale: typeof zhCN = {'abort-editing': 'Abort editing','break-line': 'Break line','set-bold': 'Toggle bold',+ 'start-editing': 'Start Editing (Selection into the Editor)','set-italic': 'Toggle italic','set-underline': 'Toggle underline','set-strike-through': 'Toggle strike through',diff --git a/packages/sheets-ui/src/locale/ru-RU.ts b/packages/sheets-ui/src/locale/ru-RU.tsindex d8d69b5dde..c81935ef64 100644--- a/packages/sheets-ui/src/locale/ru-RU.ts+++ b/packages/sheets-ui/src/locale/ru-RU.ts@@ -497,6 +497,7 @@ const locale: typeof zhCN = {'set-italic': 'Переключить курсив','set-underline': 'Переключить подчеркивание','set-strike-through': 'Переключить зачеркивание',+ 'start-editing': 'Начать редактирование',},},'sheet-view': 'Просмотр листа',diff --git a/packages/sheets-ui/src/locale/zh-CN.ts b/packages/sheets-ui/src/locale/zh-CN.tsindex f5a3ce2a36..858702178e 100644--- a/packages/sheets-ui/src/locale/zh-CN.ts+++ b/packages/sheets-ui/src/locale/zh-CN.ts@@ -493,6 +493,7 @@ const locale = {'set-italic': '切换斜体','set-underline': '切换下划线','set-strike-through': '切换删除线',+ 'start-editing': '开始编辑(选区切换到编辑器)',},},'sheet-view': '浏览表格',diff --git a/packages/ui/src/services/shortcut/keycode.ts b/packages/ui/src/services/shortcut/keycode.tsindex 125a813402..5cebfc6248 100644--- a/packages/ui/src/services/shortcut/keycode.ts+++ b/packages/ui/src/services/shortcut/keycode.ts@@ -145,6 +145,19 @@ export const KeyCodeToChar: { [key: number]: string } = {[KeyCode.Y]: 'Y',[KeyCode.Z]: 'Z',+ [KeyCode.F1]: 'F1',+ [KeyCode.F2]: 'F2',+ [KeyCode.F3]: 'F3',+ [KeyCode.F4]: 'F4',+ [KeyCode.F5]: 'F5',+ [KeyCode.F6]: 'F6',+ [KeyCode.F7]: 'F7',+ [KeyCode.F8]: 'F8',+ [KeyCode.F9]: 'F9',+ [KeyCode.F10]: 'F10',+ [KeyCode.F11]: 'F11',+ [KeyCode.F12]: 'F12',+[KeyCode.MINUS]: '-',[KeyCode.EQUAL]: '=',diff --git a/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx b/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsxindex f9216a1b1f..aac2eb05ed 100644--- a/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx+++ b/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx@@ -15,7 +15,7 @@*/import { LocaleService } from '@univerjs/core';-import { useDependency } from '@wendellhu/redi/react-bindings';+import { useDependency, useObservable } from '@wendellhu/redi/react-bindings';import React, { useCallback, useEffect } from 'react';import { IShortcutService } from '../../../services/shortcut/shortcut.service';@@ -38,6 +38,7 @@ interface IShortcutGroup {export function ShortcutPanel() {const shortcutService = useDependency(IShortcutService);const localeService = useDependency(LocaleService);+ const currentLocale = useObservable(localeService.currentLocale$);const [shortcutItems, setShortcutItems] = React.useState<IShortcutGroup[]>([]);@@ -75,16 +76,15 @@ export function ShortcutPanel() {.sort((a, b) => a.sequence - b.sequence);setShortcutItems(toRender);- }, [shortcutService, localeService]);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [shortcutService, localeService, currentLocale]);useEffect(() => {- // first updateupdateShortcuts();- // subscribe to shortcut changes and re-renderconst subscription = shortcutService.shortcutChanged$.subscribe(() => updateShortcuts());return () => subscription.unsubscribe();- }, [shortcutService]);+ }, [shortcutService, updateShortcuts]);return (<div className={styles.shortcutPanel}>@@ -92,7 +92,7 @@ export function ShortcutPanel() {<div className={styles.shortcutPanelGroup} key={group.name}><div className={styles.shortcutPanelGroupTitle}>{group.name}</div>{group.items.map((item, index) => (- <div className={styles.shortcutPanelItem} key={index}>+ <div className={styles.shortcutPanelItem} key={`${item.title}-${item.shortcut}`}><span className={styles.shortcutPanelItemTitle}>{item.title}</span><span className={styles.shortcutPanelItemShortcut}>{item.shortcut}</span></div>