Repository navigation
fix: 修复 OHOS 上可选择文本跨行拖选跳变及自由复制窗口无法滚动 - #172
Merged
Merged
Conversation
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.
问题
评论区长按 → 「自由复制」弹出的文本窗口存在两个问题(均为 OHOS 分支特有,上游 Android 端不存在):
同样的跨行拖选问题存在于所有经
SelectionText封装的可选择文本处(动态正文、视频简介、私信、SuperChat、日志页等)。原因
同步上游 2.1.1 时,可选择文本跟随上游从
SelectableText换成了SelectionArea(SelectionText封装)。上游在标准 Flutter 上无异常,但 OHOS Flutter fork(3.41.10-ohos)上该路径有缺陷:SelectionArea长按拖选走RenderParagraphselectable fragment 的 word 粒度边界逻辑。fork 中widgets/selectable_region.dart已更新到 3.41.3,而rendering/paragraph.dart仍停留在 3.35 版本,两层实现不匹配,拖选边缘跨行时按词边界扩展出现大幅跳选,且光标 affinity 处理缺陷导致无法停在视觉行末尾。SingleChildScrollView,超出窗口高度的文本直接被截断。修改
核心:
SelectionText封装内部由SelectionArea单点切回SelectableText(EditableText/RenderEditable 路径,与输入框选择同一套代码,按字符拖选无跳变;高度受限时自带内部滚动),即本分支同步 2.1.1 之前验证可用的旧方案。所有SelectionText/SelectionText.rich使用处(约 20 处)自动获得修复,调用方 API 不变。lib/common/widgets/selection_text.dart:重写为SelectableText.rich封装;contextMenuBuilder类型相应从SelectableRegionContextMenuBuilder改为EditableTextContextMenuBuilder,默认菜单走既有的selectableTextContextMenuBuilder(复制/分享/站内搜索),不再需要onSelectionChanged+SelectedContentCapture捕获机制(选中文本直接从EditableTextState.textEditingValue读取)。lib/pages/video/reply/widgets/reply_item_grpc.dart:自由复制窗口沿用SelectionText(现为 SelectableText 路径,长文本可内部滚动);_filterMenuBuilder改接EditableTextState;补上与上游一致的窗口宽度约束BoxConstraints.tightFor(width: 380)。lib/pages/dynamics/widgets/content_panel.dart:动态正文自定义菜单同步改接EditableTextState;动态「文本」窗口补同款宽度约束。lib/pages/setting/models/privacy_settings.dart:「账号模式详情」对话框由裸SelectionArea包整棵树改为各 API 列表块内使用SelectionText(布局不变,选择在块内进行)。lib/common/widgets/text_selection_toolbar.dart:移除不再有使用方的selectionAreaContextMenuBuilder与SelectedContentCapture,避免后续误用回问题路径。备注
ai_conclusion、article、log_table三处为真正的跨组件选择场景(整页 CustomScrollView / 表格行),只能继续使用SelectionArea,在 OHOS 上仍受跨行拖选跳变影响;该问题根因在 fork SDK 两层版本不匹配,待 fork 的rendering/paragraph.dart同步到 3.41 后有望自,应用层不做侵入式处理。