Repository navigation
fix(mobile): 文件守卫改到冒泡阶段,不再吞掉应用自己的预览点击(#152) - #153
Open
yanzhaohui1999 wants to merge 1 commit into
Open
yanzhaohui1999 wants to merge 1 commit into
yanzhaohui1999 wants to merge 1 commit into
Conversation
捕获阶段 + stopImmediatePropagation() 会在 dsh-web 自己的处理器之前把点击吃掉, 于是所有「文案像路径」的文件链接都只剩提示、右栏预览打不开(而文案不含斜杠的同类 链接正常)。 改为冒泡阶段注册 + event.defaultPrevented 早退:应用能处理(预览优先)时让它处理, 只有应用没管、真会去调桌面端 open 时才弹提示兜底。复制按钮注入保持不变。 Refs shaobeichen#152
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 #152。
问题
手机(窄屏移动布局)上点文案是路径的文件链接(如
dsh-tablet-apk-20260926/build/ic_launcher_512.png),只会弹「手机上无法直接打开电脑上的文件」,右栏预览打不开;同一类链接只要文案不含斜杠(label 写成「点我」,或fileGuard.ts:1-13这种)就能正常预览。根因
守卫注册在捕获阶段并且
stopImmediatePropagation():所以 dsh-web 自己的处理器拿不到事件。而 dsh-web 本来就该优先处理:
dsh-context文件行:onClick: (ev) => { ev.stopPropagation(); if (previewable && props.onPreview?.(e) === true) return; if (abs !== void 0) props.onOpen?.(abs); }dsh-client-ui-reference的openReference():ctx.sidebarRight.openResource(...)判据
looksLikeFilePath(el.textContent)本身没问题,问题只是它不该在应用之前动手。改法
event.defaultPrevented时早退 → 应用处理过的点击不再被吞;stopImmediatePropagation(),保留preventDefault()(仍能挡住裸<a href>的导航);toast、隐藏「添加工作区」全部不变;client/client.js(node client/build.mjs)与test/file-guard.test.js的断言(原来断言产物必须含stopImmediatePropagation,现改为断言冒泡注册 +defaultPrevented早退 + 不再吞事件)。验证
把改动前的
startFileGuard原样抽出来放进干净页面,用 headless Chrome 各点一次(装上模拟 dsh-web 处理器的冒泡监听):button…/build/ic_launcher_512.png(改动前)button点我(改动前)npm test:179 个用例,178 pass / 1 fail;唯一失败是test/file-read.test.js往$HOME写临时文件被本机沙箱拒绝(EPERM: /Users/y/pocket-fr-home-*.txt),在未改动的干净检出上同样失败,与本次改动无关。取舍
兜底保留了:应用没处理(真的会去调桌面端
open)时仍然弹提示,这正是 #17 想要的效果。唯一的边界情况:若某个链接应用处理了、但既不
preventDefault也不stopPropagation,兜底会多弹一次提示。当前dsh-context的文件行是stopPropagation()(dsh-client-ui-reference走的是同一套右栏预览),所以不受影响;如果后续发现别处会这样,可以再收窄判据。