Menu ▾ ▴

#651 Selection and copy to clipboard not working in THexViewWnd

8
pending
CoolPrj (49)
1
2026-10-07
2026-09-17
No

Trying to select anything in a THexEditView window does not seem to work properly on the screen, and copying to the clipboard also does not seem to work.

Easily seen if opening a hex file in the RichEditor example.

Related

Discussion: AI obsoleting OWLNext

Discussion

  • Ognyan Chernokozhev

    Claude Code analysis:

    Why the selection drew wrong

    1. Selected bytes were never highlighted. DrawLine drew each line's hex and ASCII text in its normal colours. The only selection painting was a one-character block after the ASCII column, carried over from the text editor's end-of-line marker. It now highlights selected bytes in both columns, and the space between two selected bytes is filled too so the block looks continuous. I removed the end-of-line block.
    2. Client2Text returned position (0,0) for any point outside a data column. That included the address column, the gap between the hex and ASCII columns, and the area past the end of a line. Dragging across the gap jumped the selection back to the start of the file. The same bug moved the cursor to (0,0) after End or Ctrl+End, because ScrollToCaret converts the position to screen coordinates and back. Such points now map to the nearest position in the current column.
    3. The horizontal scroll offset was added instead of subtracted in Client2Text, so hit-testing was wrong after scrolling sideways.
    4. How dragging works now:
    5. It selects up to the byte boundary nearest the mouse, so you select a byte by dragging past its middle.
    6. A stray mouse-move at the click point no longer selects anything. This needed a new MouseDownPos member.
    7. EvLButtonUp no longer recalculates the end of the selection, which was moving it on release.
    8. Shift+click with no selection now extends from the cursor.
    9. GetTxColor returned the background colour instead of the text colour (in the header).

    Why copy didn't work

    1. No plain-text format was put on the clipboard, only the private "HexEdit Binary Data" format, so pasting into another program did nothing. Copy now also adds plain text:
    2. If the cursor is in the hex column, you get hex like 48 65 6C.
    3. If it's in the ASCII column, you get the characters as displayed, with . for unprintable ones.
    4. Clipboard memory was allocated as fixed GMEM_DDESHARE. The clipboard needs moveable memory. Copy and SetDragData now use TClipboard::AllocateData.
    5. TStreamSelection::Copy worked out the byte count wrongly for selections over more than one line. It subtracted the start position on every line, which could give a negative count passed to os.write. It now copies by byte offset. TLineSelection::Copy was changed the same way.
    6. A trailing null byte (os << ends) was appended to the copied data. I removed it.
    7. Keyboard: Ctrl+C and Ctrl+Insert now copy and Ctrl+A selects all, in case your app has no accelerators for them. I removed the PRECONDITION in CopySelection so Ctrl+C with nothing selected doesn't assert, and SelectAll now does nothing when the file is empty.
     
  • Ognyan Chernokozhev

    • status: open --> pending
     
  • Ognyan Chernokozhev

    Fix implemented by Claude Code in [r8933].

     
    👍
    1

    Related

    Commit: [r8933]

  • Vidar Hasfjord

    Vidar Hasfjord - 2026-10-07
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,3 +1,3 @@
    -Trying to select anything in a THexEditView window does not seem to work properly on the screen, and copying to the clipboard also does seem to work.
    +Trying to select anything in a THexEditView window does not seem to work properly on the screen, and copying to the clipboard also does not seem to work.
    
     Easily seen if opening a hex file in the RichEditor example.
    
     

Log in to post a comment.