Repository navigation
feat(session): drag over the conversation to select and copy its text - #173
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
||
| def drag(self, event: MouseEvent) -> bool: | ||
| """A drag over the conversation selects text, copied on release; a click without one still opens a link.""" | ||
| at = (self.view_start + event.position.y, event.position.x) |
There was a problem hiding this comment.
Wide characters copy incorrectly
drag treats event.position.x as a screen column, but prompt_toolkit passes a character index. cells then compares it with screen columns. For 日本 ok, dragging from 本 through k selects 日本 instead of 本 ok.
Convert the mouse position to screen columns, or use character indexes throughout. Add a test that sends wide-character input through the window's mouse handler.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/repl/app.py
Line: 986
Comment:
**Wide characters copy incorrectly**
`drag` treats `event.position.x` as a screen column, but prompt_toolkit passes a character index. `cells` then compares it with screen columns. For `日本 ok`, dragging from `本` through `k` selects `日本` instead of `本 ok`.
Convert the mouse position to screen columns, or use character indexes throughout. Add a test that sends wide-character input through the window's mouse handler.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| # A release here, or a move with no button held: it was let go over another part of the screen. | ||
| if kind == MouseEventType.MOUSE_UP: | ||
| sel.head = at | ||
| sel.dragging = False |
There was a problem hiding this comment.
Release outside loses the copy
Releasing a drag over the input bar does not copy the selection. That window receives the release, and drag only finishes the copy after another mouse event reaches the conversation. If the user starts typing instead, _drop_selection discards the pending copy.
Handle the release across the whole layout rather than waiting for the pointer to return. The new test only passes because it adds that later return event.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/repl/app.py
Line: 996-999
Comment:
**Release outside loses the copy**
Releasing a drag over the input bar does not copy the selection. That window receives the release, and `drag` only finishes the copy after another mouse event reaches the conversation. If the user starts typing instead, `_drop_selection` discards the pending copy.
Handle the release across the whole layout rather than waiting for the pointer to return. The new test only passes because it adds that later return event.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| # pbcopy reads its input in the locale's encoding. | ||
| env = {**os.environ, "LC_CTYPE": "UTF-8"} if command[0] == "pbcopy" else None | ||
| try: | ||
| subprocess.run(command, input=text.encode(), env=env, check=True, capture_output=True, timeout=2) |
There was a problem hiding this comment.
Copying can freeze the session
subprocess.run runs directly inside the mouse callback. If a clipboard helper stalls, the two-second timeout blocks drawing, typing and cancellation for that whole interval.
Run the helper outside the app's event loop, then send any terminal fallback and status update back to that loop.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/repl/clipboard.py
Line: 37
Comment:
**Copying can freeze the session**
`subprocess.run` runs directly inside the mouse callback. If a clipboard helper stalls, the two-second timeout blocks drawing, typing and cancellation for that whole interval.
Run the helper outside the app's event loop, then send any terminal fallback and status update back to that loop.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4007a62c74
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| def drag(self, event: MouseEvent) -> bool: | ||
| """A drag over the conversation selects text, copied on release; a click without one still opens a link.""" | ||
| at = (self.view_start + event.position.y, event.position.x) |
There was a problem hiding this comment.
Convert mouse character indexes before using them as cell columns
When a transcript row contains wide characters, event.position.x is not a terminal-cell column: prompt-toolkit's Window mouse wrapper converts screen coordinates into character indexes before dispatching to the control. Passing that index directly into Selection, whose extraction and highlighting use cell widths, selects the wrong text. For example, dragging over ok in 日本 ok produces character indexes 3–4, but selected_text interprets those as cells and copies 本. Convert the index to a cell offset using the corresponding row, or consistently use character indexes throughout selection handling; the existing wide-character test bypasses this event conversion.
Useful? React with 👍 / 👎.
| # pbcopy reads its input in the locale's encoding. | ||
| env = {**os.environ, "LC_CTYPE": "UTF-8"} if command[0] == "pbcopy" else None | ||
| try: | ||
| subprocess.run(command, input=text.encode(), env=env, check=True, capture_output=True, timeout=2) |
There was a problem hiding this comment.
Avoid capturing the background clipboard owner's output pipes
On a local Linux X11 session using xclip, this synchronous call can freeze the session for the full two-second timeout on every copy even when copying succeeds. The xclip manual describes its default mode as “fork into the background to wait for requests”; its implementation leaves stdout and stderr open in that background clipboard owner. With capture_output=True, subprocess.run waits for EOF on those inherited pipes, times out, and unnecessarily falls back to OSC 52. Redirect the unused output streams to DEVNULL rather than pipes so the completed parent process can return immediately.
Useful? React with 👍 / 👎.
|
|
||
| transcript_window: Window = Window(wrap_lines=False) | ||
| transcript_window.content = TranscriptControl(lambda: self.transcript_view(transcript_window), self.scroll) | ||
| transcript_window.content = TranscriptControl(lambda: self.transcript_view(transcript_window), self.scroll, self.drag) |
There was a problem hiding this comment.
Handle selection release outside the transcript window
If a user starts selecting in the conversation and releases over the input bar or status row, nothing is copied on release: self.drag is registered only on TranscriptControl, so the other window receives that mouse-up event. The no-button-move fallback only copies after the pointer returns to the conversation; switching directly to another application to paste leaves the previous clipboard contents, and typing in the input bar drops the selection without copying it. The existing outside-release test explicitly injects a subsequent move back over the transcript, so it does not verify copying at release. Capture the release at the application level or forward it from other windows while a selection is dragging.
Useful? React with 👍 / 👎.
…versation, copy off the app's loop
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 501185dbcf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def copy() -> None: | ||
| # Off the app's loop, so a slow clipboard command never holds up the screen. | ||
| clipboard.copy(text, lambda data: self.call_soon(lambda: self.write_raw(data))) | ||
| self.call_soon(lambda: self.flash(done)) | ||
|
|
||
| threading.Thread(target=copy, name="rae-copy", daemon=True).start() |
There was a problem hiding this comment.
Preserve clipboard request order across background copies
If a user makes another selection while the previous clipboard helper is still running, the independent threads can overwrite the newer clipboard contents with the older selection. For example, if the first helper stalls and the second succeeds, the first request's eventual timeout sends an OSC 52 fallback containing the old text, even though the newer selection remains highlighted. This ordering is reproducible with the current copy_selection and clipboard fallback code. Serialize clipboard requests or otherwise prevent superseded requests from writing clipboard contents and posting stale confirmations.
Useful? React with 👍 / 👎.
# Conflicts: # CHANGELOG.md
Why: the session takes the mouse for the wheel and for clicking files and links, so the terminal cannot select its text: nothing in the conversation could be copied.
What: dragging over the conversation highlights the text and copies it when you let go, and the status row says what was copied. A drag can end over the input bar or status row; it then copies to the end of the last line on screen. The copy runs off the app's loop with
pbcopy,wl-copy,xcliporxsel, and otherwise, or over SSH, asks the terminal to copy with OSC 52. A click without a drag still opens a link, and the wheel still scrolls. Typing,/clearor a new terminal width drops the selection.Verification:
本over日本 okcopies本 okand reverses its 5 cells, a drag let go on the input bar copies to the end of the conversation, the status row says copied, and a plain click copies nothing.Out of scope: copying the input bar or menus; a word or line on double or triple click.