Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions trpad.asm
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ EXTERN _imp__PageSetupDlgA@4 :PTR ; common Page Setup dialog
EXTERN _imp__DialogBoxIndirectParamA@20 :PTR ; in-memory Go To dialog
EXTERN _imp__GetDlgItemInt@16 :PTR ; read Go To line number
EXTERN _imp__EndDialog@8 :PTR ; close Go To dialog
EXTERN _imp__DragQueryFileA@16 :PTR ; query drag file
EXTERN _imp__DragFinish@4 :PTR ; finish drag
EXTERN _imp__SetFocus@4 :PTR ; focus edit control after commands
EXTERN _imp__ExitProcess@4 :PTR ; terminate process cleanly

Expand Down Expand Up @@ -1847,7 +1849,7 @@ MainEntry proc NEAR
push WS_OVERLAPPEDWINDOW or WS_VISIBLE
push OFFSET ClassName
push OFFSET ClassName
push 0
push WS_EX_ACCEPTFILES
call [_imp__CreateWindowExA@48]

; if create window ok, save hwnd / else exit
Expand Down Expand Up @@ -2662,8 +2664,32 @@ ENDIF
xor eax, eax
ret

; check for WM_DESTROY
; check for WM_DROPFILES
NotWMSize:
cmp uMsg, WM_DROPFILES
jne NotWMDropFiles
call MaybeSaveChanges
test eax, eax
je DropDone
push MAX_CMD_PATH
push OFFSET CmdFile
push 0
push wParam
call [_imp__DragQueryFileA@16]
test eax, eax
je DropDone
call LoadStartupFile
xor eax, eax
mov fDirty, eax
call ApplyTitle
Comment on lines +2681 to +2684

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve state when a dropped path cannot load

When DragQueryFileA returns a path that LoadStartupFile cannot open/read (for example a dropped directory, an unreadable file, or a path truncated by MAX_CMD_PATH), LoadStartupFile simply returns without replacing the editor contents, but this new path still clears fDirty and applies the dropped name as the title. In that scenario the previous buffer remains visible but is now marked clean/renamed, so closing afterward can skip the save prompt for edits that were not actually replaced by the drop.

Useful? React with 👍 / 👎.

@RatinCN RatinCN Jun 20, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a valid edge case, but I am going to keep the current behavior for this PR because it matches the existing File > Open path and avoids adding more code size. The existing open flow has the same tradeoff:
(1) CmdFileOpen calls LoadStartupFile and then unconditionally clears fDirty and applies the title
(2) LoadStartupFile does not currently report success or failure
(3) PickOpenFile writes directly into CmdFile, even clearing CmdFile before showing the dialog.

Drag/drop can reach a few more bad inputs, such as directories or truncated paths, but fixing that properly would require extra state preservation or a success return path. Since this project prioritizes final binary size over edge-case polish, I prefer to keep this behavior consistent with the existing open logic.

DropDone:
push wParam
call [_imp__DragFinish@4]
xor eax, eax
ret

; check for WM_DESTROY
NotWMDropFiles:
cmp uMsg, WM_DESTROY
jne NotWMDestroy

Expand Down