From 16ea6c7d39e5f3bf865d64293d2444507ede5509 Mon Sep 17 00:00:00 2001 From: HellowVirgil <1135895008@qq.com> Date: Mon, 19 Jan 2026 21:00:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(libro-context-key):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=A8=A1=E5=BC=8F=E7=8A=B6=E6=80=81=E6=9C=AA?= =?UTF-8?q?=E8=80=83=E8=99=91=E7=84=A6=E7=82=B9=E7=8A=B6=E6=80=81=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 确保命令模式的启用和状态更新都检查了libroService.focus状态,避免在无焦点时错误启用命令模式 --- packages/libro-core/src/libro-context-key.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/libro-core/src/libro-context-key.ts b/packages/libro-core/src/libro-context-key.ts index 86fd3a1c..0fedc77d 100644 --- a/packages/libro-core/src/libro-context-key.ts +++ b/packages/libro-core/src/libro-context-key.ts @@ -35,7 +35,7 @@ export class LibroContextKey { enableCommandMode = () => { this.commandModeEnabled = true; - this.commandMode.set(this.isCommandMode); + this.commandMode.set(this.isCommandMode && !!this.libroService.focus); }; protected setupActive() { @@ -54,6 +54,9 @@ export class LibroContextKey { protected setupFocus() { this.libroService.onFocusChanged(() => { this.focus.set(!!this.libroService.focus); + this.commandMode.set( + this.isCommandMode && this.commandModeEnabled && !!this.libroService.focus, + ); }); this.focus = this.contextKeyService.createKey( LibroContextKeys.focus, @@ -64,16 +67,22 @@ export class LibroContextKey { protected setupCommandMode() { this.commandMode = this.contextKeyService.createKey( LibroContextKeys.commandMode, - !!this.libroService.active?.model.commandMode, + !!this.libroService.active?.model.commandMode && !!this.libroService.focus, ); this.listenToActive(); } protected listenToActive = () => { const active = this.libroService.active; if (active) { + this.isCommandMode = !!active.model.commandMode; + this.commandMode.set( + this.isCommandMode && this.commandModeEnabled && !!this.libroService.focus, + ); this.toDisposeOnActiveChanged = active.model.onCommandModeChanged(() => { this.isCommandMode = !!active.model.commandMode; - this.commandMode.set(this.isCommandMode && this.commandModeEnabled); + this.commandMode.set( + this.isCommandMode && this.commandModeEnabled && !!this.libroService.focus, + ); }); } };