Make the Ctrl+C copy reliable, and say why it failed when it does - #6
Merged
Conversation
Reported: selecting a reference in Notepad++ and pressing the hotkey logged
"Clipboard: No text found after copy operation" and inserted nothing.
The log could not distinguish three different failures, all of which produced
that one message with an empty result:
1. modifier keys still physically held from the hotkey,
2. the clipboard could not be opened,
3. nothing was actually selected.
All three are now addressed and, more importantly, are now distinguishable.
Held modifiers. The copy is synthesised a fraction of a second after the hotkey
fires, and nobody releases Ctrl+Alt+L that fast. A physically held Alt combines
with the synthetic keystroke, so the target sees Ctrl+Alt+C rather than Ctrl+C
and copies nothing - which looked exactly like "no text was selected". SendKeys
now releases any held Alt, Shift or Win first. This is the most likely cause of
the report: the timestamps show Ctrl+C going out roughly 100-200 ms after the
hotkey.
Clipboard contention. OpenClipboard was called once and, on failure, returned an
empty string indistinguishable from an empty clipboard. Clipboard managers,
editors and browsers all hold the clipboard in short bursts, so this fails often
enough to matter. It now retries for up to 500 ms, and reads report whether they
found no text or could not open the clipboard at all.
Guessing at a delay. A fixed 300 ms sleep was both too short for slow
applications and wasted time for fast ones, and told us nothing. The clipboard
sequence number is now sampled before the copy and polled for up to 1.5 s: if it
never changes, nothing was copied, and the log says so ("Ctrl+C did not change
the clipboard - was any text selected?") rather than blaming the read.
Also demoted two expected fallback conditions from ERROR to ordinary log lines.
"No text selection found" and "Target window is not an edit control" happen on
every successful clipboard fallback - Notepad++ is Scintilla-based and exposes
no UIA TextPattern - and logging them as errors set m_last_error and buried real
failures in noise.
Version 1.1.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Selecting a reference in Notepad++ and pressing the hotkey logged
Clipboard: No text found after copy operationand inserted nothing.The real problem: one message, three causes
That single message was produced by three completely different failures, all of which returned an empty string:
All three are now fixed, and — more importantly — are now told apart in the log.
1. Held modifiers (most likely cause here)
The copy is synthesised a fraction of a second after the hotkey fires, and nobody releases
Ctrl+Alt+Lthat fast. A physically held Alt combines with the synthetic keystroke, so the target application receivesCtrl+Alt+Cinstead ofCtrl+Cand copies nothing — indistinguishable from "no text was selected".The timestamps in the report support this:
Hotkey pressed!at14:01:05.759, selection read at14:01:06.321— Ctrl+C went out roughly 100–200 ms after the hotkey.SendKeysnow releases any held Alt, Shift or Win before synthesising anything.2. Clipboard contention
OpenClipboardwas called once, and on failure returned an empty string indistinguishable from an empty clipboard. Clipboard managers, editors and browsers all hold the clipboard in short bursts, so this fails often enough to matter. It now retries for up to 500 ms, and reads report why they came back empty.3. Guessing at a delay
A fixed
Sleep(300)was both too short for slow applications and wasted time for fast ones, and told us nothing. The clipboard sequence number is now sampled before the copy and polled for up to 1.5 s. If it never changes, nothing was copied — and the log says exactly that rather than blaming the read:Log noise
Two expected fallback conditions were logged as
ERRORon every successful run — Notepad++ is Scintilla-based and exposes no UIA TextPattern, so both fire every time:Both are now ordinary log lines. They also set
m_last_error, which buried real failures.Honest status
I could not reproduce the failure interactively to prove which of the three it was — GUI automation of "hold Alt while another app has focus" was unreliable in my environment, and I'm not going to claim a diagnosis I didn't verify. What I've done instead is make all three causes non-failures where possible, and unambiguous in the log where not. If it recurs, the log will now name the cause outright.
Harness 1053 checks and self-test 242 checks still pass. Version bumped to 1.1.1.