Skip to content

fix(db_view): 表数据过滤条回车不再插入换行 - #224

Merged
feigeCode merged 1 commit into
mainfrom
dev
Sep 18, 2026
Merged

feigeCode merged 1 commit into
mainfrom
dev

Conversation

@feigeCode

Copy link
Copy Markdown
Owner

问题

表数据页面的 WHERE / ORDER BY 过滤条里按回车,查询会发出,但同时插入了一个换行,输入框被撑成两行。

原因

两层叠加:

  1. 2f723298a Externalize gpui component integrationInputState + .multi_line(false) 换成了恒为多行的 EditorStateEditorMode::MULTI_LINE = true),新 API 里已没有 multi_line(false)
  2. macOS 上 Enter 自带 key_char = "\n"gpui_macos/src/events.rs),Window::dispatch_keystroke 在 keydown 未被消费时会把 key_char 插入输入框。旧的单行输入在 normalize_inputgpui_base .../input/base/state.rs)里剥掉 \n\r,多行编辑器不剥。

所以单加 .submit_on_enter(true) 不够:它只让编辑态自己不插换行(insert_newline = is_multi_line() && (!submit_on_enter || shift)),随后平台那次文本插入照旧。

改动

  • create_simple_editor.submit_on_enter(true)
  • SimpleCodeEditor::render:外层 div 上 plain Enter 时 cx.stop_propagation(),消费掉平台那次 "\n" 插入。keymap 动作分发早于 key_down 监听,InputEvent::PressEnter 链路不变,Shift+Enter 仍换行。

验证

  • 新增回归测试 enter_applies_the_filter_without_inserting_a_newline(真窗口 + Root):输入 age > 18 后 Enter,文本保持 age > 18 且触发一次 QueryApply;Shift+Enter 得到 age > 18\n
  • 变异验证:去掉 .submit_on_enter(true) 后该测试转红(left: "age > 18" / right: "age > 18\n")。
  • cargo test -p db_view --lib → 699 passed, 0 failed;cargo clippy -p db_view --all-targets 该文件无新增告警。

外部化 gpui-component 时 InputState 的 .multi_line(false) 换成了恒为多行的
EditorState,且 macOS 上 Enter 自带的 key_char("\n") 会被平台插入输入框
(旧单行输入在 normalize_input 里剥掉换行),回车变成换行 + 查询。

- create_simple_editor: 加 .submit_on_enter(true),编辑态不再自己插换行
- SimpleCodeEditor::render: plain Enter 时 stop_propagation,消费掉平台那次
  文本插入;Shift+Enter 仍保留换行
- 新增回归测试 enter_applies_the_filter_without_inserting_a_newline
@feigeCode
feigeCode merged commit e291363 into main Sep 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant