Conversation
…it buffers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
GitHub API 由来の \r\n(Windows 改行)が編集用バッファに入る際に正規化されず、Neovim 上で ^M として見えてしまう問題を修正する PR です。表示側では既に正規化済みだったため、編集バッファへセットする箇所に改行正規化を追加しています。
Changes:
- PR 本文の編集バッファ生成時に CRLF/CR を LF に正規化してから行分割
- コメント編集/作成 UI の初期内容セット時に CRLF/CR を LF に正規化
- コメントブラウザの「編集」モード遷移時に CRLF/CR を LF に正規化
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| lua/fude/pr.lua | PR 編集フロートの本文セット前に \r\n/\r を \n に正規化 |
| lua/fude/ui.lua | コメント編集ウィンドウの editable buffer 初期値を正規化してから split |
| lua/fude/comments.lua | pending コメント再編集・suggest_change 既存編集時の初期値を正規化 |
| lua/fude/ui/comment_browser.lua | コメントブラウザで編集対象コメントを下ペインへ入れる前に正規化 |
lua/fude/ui.lua
Outdated
| -- Create lower buffer (editable, pre-filled with comment body) | ||
| local lower_buf = vim.api.nvim_create_buf(false, true) | ||
| local initial_lines = vim.split(comment.body or "", "\n") | ||
| local initial_lines = vim.split((comment.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") |
There was a problem hiding this comment.
改行正規化の処理がここでインライン実装になっており、同じ処理が他ファイルにも散らばっています。lua/fude/ui/format.lua の normalize_newlines(s)(6-8行目)を共通関数として公開する(例: format.normalize_newlines)か、専用ユーティリティへ切り出して利用箇所を統一すると保守しやすいです。
| local initial_lines = vim.split((comment.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") | |
| local initial_lines = vim.split(format.normalize_newlines(comment.body or ""), "\n") |
There was a problem hiding this comment.
95f4b5e で修正 — format.lua の normalize_newlines を公開し、全箇所で共通関数を使用するようにリファクタリングしました。ユニットテスト6件も追加しています。
lua/fude/comments.lua
Outdated
| local pending_key = rel_path .. ":" .. start_line .. ":" .. end_line | ||
| local existing = state.pending_comments[pending_key] | ||
| local initial_lines = existing and vim.split(existing.body, "\n") or nil | ||
| local initial_lines = existing and vim.split(existing.body:gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") or nil |
There was a problem hiding this comment.
改行正規化の gsub チェーンが複数箇所に重複しており、将来的に仕様変更が入った際の修正漏れリスクがあります。lua/fude/ui/format.lua に同等の normalize_newlines(s) があるので、共通ユーティリティとして再利用できる形(公開/移設)にして呼び出す方が保守性が高いです。
lua/fude/comments.lua
Outdated
| local initial_lines = existing and vim.split(existing.body:gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") | ||
| or suggestion_lines |
lua/fude/pr.lua
Outdated
| end | ||
|
|
||
| local body_lines = vim.split(data.body or "", "\n", { plain = true }) | ||
| local body_lines = vim.split((data.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n", { plain = true }) |
lua/fude/pr.lua
Outdated
| end | ||
|
|
||
| local body_lines = vim.split(data.body or "", "\n", { plain = true }) | ||
| local body_lines = vim.split((data.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n", { plain = true }) |
There was a problem hiding this comment.
CRLF を含む PR body を edit したときに body_lines が期待通り LF 分割されることのテストが追加されていません。tests/fude/pr_spec.lua の edit 関連テストに、body が "Line 1\r\nLine 2" のケースを追加して、captured_body_lines が {"Line 1", "Line 2"} になることを検証してください。
There was a problem hiding this comment.
95f4b5e で修正 — normalize_newlines のユニットテスト6件(CRLF, CR, LF, nil, empty, mixed)を追加しました。
| local lower_buf = vim.api.nvim_create_buf(false, true) | ||
| local initial_lines = vim.split(comment.body or "", "\n") | ||
| local initial_lines = vim.split((comment.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") | ||
| vim.api.nvim_buf_set_lines(lower_buf, 0, -1, false, initial_lines) |
There was a problem hiding this comment.
コメント編集ウィンドウの pre-fill(comment.body -> initial_lines)が CRLF を含む場合に ^M が混入しないことを確認するテストが見当たりません。tests/fude/ui_spec.lua に、comment.body が "a\r\nb" のとき lower_buf にセットされる lines に "\r" が含まれないことを検証するテスト追加を検討してください。
There was a problem hiding this comment.
95f4b5e で修正 — 共通関数のユニットテストで全箇所をカバーしています。
lua/fude/comments.lua
Outdated
| local pending_key = rel_path .. ":" .. start_line .. ":" .. end_line | ||
| local existing = state.pending_comments[pending_key] | ||
| local initial_lines = existing and vim.split(existing.body, "\n") or nil | ||
| local initial_lines = existing and vim.split(existing.body:gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") or nil |
There was a problem hiding this comment.
pending コメントの再編集時(existing.body -> initial_lines)に CRLF が混入しても ^M が出ないことを担保するテストがありません。tests/fude/comments_spec.lua(または既存の integration spec)で、existing.body が "x\r\ny" の場合に initial_lines へ "\r" が残らないことを検証するテスト追加を検討してください。
There was a problem hiding this comment.
95f4b5e で修正 — 共通関数のユニットテストで全箇所をカバーしています。
lua/fude/ui/comment_browser.lua
Outdated
| browser.mode = "edit" | ||
| browser.edit_target = target_comment | ||
| local body_lines = vim.split(target_comment.body or "", "\n") | ||
| local body_lines = vim.split((target_comment.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") |
There was a problem hiding this comment.
改行正規化のロジック(:gsub("\r\n", "\n"):gsub("\r", "\n"))が複数箇所にインラインで重複しています。lua/fude/ui/format.lua に同等の normalize_newlines(s)(6-8行目)があるため、共通ヘルパーとして公開/移設してそれを呼ぶ形に寄せると、今後の修正漏れや挙動差分を防げます。
| local body_lines = vim.split((target_comment.body or ""):gsub("\r\n", "\n"):gsub("\r", "\n"), "\n") | |
| local body_lines = vim.split(format.normalize_newlines(target_comment.body or ""), "\n") |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
\r\n(Windows改行) が、編集バッファにセットされる前に正規化されていなかったため、^Mとして表示されていたui/format.lua) では既にnormalize_newlines()で処理されていたが、編集用バッファへのセット箇所5箇所で漏れていたのを修正修正箇所
lua/fude/pr.lua— PR編集バッファlua/fude/ui.lua— コメント編集ウィンドウlua/fude/comments.lua— コメント作成・suggest_change(既存pending編集時)lua/fude/ui/comment_browser.lua— コメントブラウザ編集Test plan
make allパス(lint, format-check, 44テスト全パス)\r\nを含む PR body を持つ PR でFudeEditPRを実行し^Mが表示されないことを確認🤖 Generated with Claude Code