Skip to content

fix: honor selected EOL sequence when copying query text to clipboard #10158#10160

Open
hiteshjambhale wants to merge 1 commit into
pgadmin-org:masterfrom
hiteshjambhale:fix-10158-eol-clipboard-copy
Open

fix: honor selected EOL sequence when copying query text to clipboard #10158#10160
hiteshjambhale wants to merge 1 commit into
pgadmin-org:masterfrom
hiteshjambhale:fix-10158-eol-clipboard-copy

Conversation

@hiteshjambhale

@hiteshjambhale hiteshjambhale commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #10158 — a regression of the EOL feature added in #7393.

The Query Tool status bar lets you choose LF or CRLF as the end-of-line sequence used when copying query text to the clipboard. Since #8691 this setting had no effect: copied text always used LF regardless of the choice.

Root cause

CustomEditorView.getSelectionFromState() joined the selection ranges with the chosen EOL, but sliced each range using state.sliceDoc(from, to) — which always uses the document's own line break (\n). For a normal single-range selection (the common case) there is nothing to join, so every internal line break stayed \n and the LF/CRLF choice was ignored.

This was introduced in #8691, where the copy path was reworked to fix multi-cursor copying and switched from doc.sliceString(..., lineSep) (applies the separator to line breaks) to sliceDoc(...) (does not).

Fix

Slice each range with state.doc.sliceString(range.from, range.to, lineSep) so the chosen EOL is applied to line breaks within the selection as well. The .join(lineSep) still applies it between multiple cursor ranges, so the #8691 multi-cursor fix is preserved.

- return state.selection.ranges.map((range)=>state.sliceDoc(range.from, range.to)).join(lineSep) ?? '';
+ return state.selection.ranges.map((range)=>state.doc.sliceString(range.from, range.to, lineSep)).join(lineSep) ?? '';

Test steps

  1. Open a Query Tool and enter multiple lines of SQL.
  2. In the bottom-right status bar, set the EOL toggle to CRLF.
  3. Select all (Ctrl/Cmd+A) and copy (Ctrl/Cmd+C).
  4. Inspect the raw clipboard bytes (the destination editor may normalize on paste, so check the clipboard directly):
    • macOS: pbpaste | xxd | head
    • or count: echo "CR: $(pbpaste | tr -cd '\r' | wc -c) LF: $(pbpaste | tr -cd '\n' | wc -c)"
  5. Expected: every line break is 0d 0a (CRLF) — CR and LF counts are equal and non-zero.
  6. Switch the toggle to LF, copy again, and re-check.
  7. Expected: line breaks are bare 0a (LF) — CR count is 0.

Note: pasting into another editor may convert the endings to match that editor's own EOL setting, which can mask the result — that's why the raw clipboard is the source of truth.

Summary by CodeRabbit

  • Bug Fixes
    • Improved selected-text extraction in the code editor to preserve the document’s configured line-ending format.

…gadmin-org#10158

getSelectionFromState joined selection ranges with the chosen EOL but
sliced each range with sliceDoc(), which always uses the document line
break (\n). For a normal single-range selection this meant line breaks
were always copied as LF regardless of the LF/CRLF status-bar setting,
regressing the pgadmin-org#7393 feature.

Slice each range with doc.sliceString(from, to, lineSep) so the chosen
EOL is applied to line breaks within the selection as well, while still
joining multiple cursor ranges with the same separator (keeping pgadmin-org#8691).
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 16885515-4fd4-4975-99b0-19133699d3b9

📥 Commits

Reviewing files that changed from the base of the PR and between b15c745 and 0f62977.

📒 Files selected for processing (1)
  • web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js

Walkthrough

CustomEditorView.getSelectionFromState now extracts each selection range with the document’s configured line separator, preserving CRLF or LF output when copying selected text.

Changes

Selection EOL handling

Layer / File(s) Summary
Preserve configured line endings
web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js
Selected ranges now use state.doc.sliceString with the current lineSep before joining the extracted ranges.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: honoring the selected EOL sequence when copying query text to the clipboard.
Linked Issues check ✅ Passed The change directly addresses #10158 by using the selected line separator when extracting copied query text, restoring LF/CRLF behavior.
Out of Scope Changes check ✅ Passed The patch is narrowly scoped to clipboard EOL handling and does not introduce unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Feature added in #7393 is no longer working as expected

1 participant