/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/muya/src/ui/ui.ts
65 строк
2 KB
Ran Luo
fix(muya): let Enter pass through to the block when only the format toolbar is shown (#3196) (#4736)
26 июн 2026, 10:19
Не верифицирован
26 июн 2026, 10:19
ca9c27e
Код
Авторство
О чём код?
import type { Muya } from '../muya'; import type BaseFloat from './baseFloat'; import { EVENT_KEYS } from '../config'; const CONTENT_NAV_KEYS = new Set([ EVENT_KEYS.Enter, EVENT_KEYS.Escape, EVENT_KEYS.Tab, EVENT_KEYS.ArrowUp, EVENT_KEYS.ArrowDown, ]); export class Ui { public shownFloat: Set<BaseFloat> = new Set(); private _shownButton: Set<BaseFloat> = new Set(); constructor(public muya: Muya) { this._listen(); } private _listen() { // cache shown float box this.muya.eventCenter.subscribe('muya-float', (tool, status) => { status ? this.shownFloat.add(tool) : this.shownFloat.delete(tool); }); // cache shown btn this.muya.eventCenter.subscribe('muya-float-button', (tool, status) => { status ? this._shownButton.add(tool) : this._shownButton.delete(tool); }); } hideAllFloatTools() { for (const tool of this.shownFloat) tool.hide(); for (const btn of this._shownButton) btn.hide(); } handleContentKeydown(event: KeyboardEvent): boolean { if (this.shownFloat.size === 0 || !CONTENT_NAV_KEYS.has(event.key)) return false; if ( event.shiftKey && (event.key === EVENT_KEYS.ArrowUp || event.key === EVENT_KEYS.ArrowDown) ) { return false; } // Block the content handler only when a shown float actually captures // the key; a passive float (e.g. the format toolbar) must let it through // so Enter/Tab/arrows over a selection still work (#3196). let captured = false; for (const tool of this.shownFloat) { if (tool.capturesContentKeydown) { event.preventDefault(); captured = true; break; } } return captured; } }