-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Advanced Paste] Repeatedly pasting plain text as JSON produces inconsistent results #34151
base: main
Are you sure you want to change the base?
Conversation
… and re-writing it to the clipboard
@htcfreek
It doesn't do anything. Could you help me with it? Btw, issue is #33944 |
There is this |
@htcfreek
That doesn't explain why it pastes the original data. It shouldn't, right? Or that I think. I would love to hear from you regarding this. |
Hi @htcfreek, I added some log statements in between to see what was stored in different locations. And, I have attached the resulting image of the logs. internal void ToJsonFunction(bool pasteAlways = false)
{
try
{
Logger.LogTrace();
string tempText = ClipboardData.GetTextAsync().GetAwaiter().GetResult();
Logger.LogInfo("Temp text: " + tempText);
string jsonText = JsonHelper.ToJsonFromXmlOrCsv(ClipboardData);
Logger.LogInfo("JSON text: " + jsonText);
SetClipboardContentAndHideWindow(jsonText);
Logger.LogInfo("Copied JSON text to the clipboard");
if (pasteAlways || _userSettings.SendPasteKeyCombination)
{
Logger.LogInfo("Clipboard data: " + ClipboardData.GetTextAsync().GetAwaiter().GetResult());
Logger.LogInfo("Inside paste if");
ClipboardHelper.SendPasteKeyCombination();
Logger.LogInfo("End paste if");
}
SetClipboardContentAndHideWindow(tempText);
string temp = ClipboardData.GetTextAsync().GetAwaiter().GetResult();
Logger.LogInfo("Text in clipboard: " + temp);
}
catch
{
}
} One question, that I was having, how come the clipboard content on paste changes to some other value or am I missing something? Also, the last log statement has not been executed. I'm not sure about this behavior. Also, why I used the |
@GhostVaibhav |
This comment was marked as outdated.
This comment was marked as outdated.
@GhostVaibhav
Logs and investigation informationsCode changes are based on your public PR code. Changes on
|
Hi @htcfreek, thanks for the detailed research and the huge write-up. As per it, I re-implemented both files per your suggestions, but they are still not working for me. So now, when I copy the text and paste the JSON. The correct JSON is pasted, but the clipboard content is not updated. The clipboard contains the pasted JSON itself. Also, I thought that this could be a timing issue, so I increased the thread's sleep time from |
@GhostVaibhav |
The logging output is huge. Therefore, I have attached the whole log file. Fyi, it's filled with flush errors. Also, when I'm pasting, the first time it's working fine. But after the second time, it's getting problematic. Also, below is the output file for which the logs are attached.
|
@GhostVaibhav
|
@GhostVaibhav
|
Hi @htcfreek, it now works. I made some changes to your code.
try
{
Task.Run(() =>
{
try
{
Clipboard.Flush();
}
catch (Exception ex)
{
Logger.LogError("Clipboard.Flush() failed. Real reason:", ex.GetBaseException());
throw;
}
}).Wait();
flushed = true;
Logger.LogDebug("Clipboard flushed.");
}
catch (Exception ex)
{
Logger.LogError("Clipboard.Flush() failed", ex);
Thread.Sleep(50); // This
}
// Wait 50 ms in a loop until setting the clipboard content has finished.
while (!Clipboard.GetContent().GetTextAsync().GetAwaiter().GetResult().Contains(text))
{
Thread.Sleep(50);
} But there are still exceptions about flush in the log file. Should that be of any concern now? |
@GhostVaibhav |
The changes are done in |
@GhostVaibhav And aren't there different methods for html, text and image in clipboard helper? |
@htcfreek |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments. Didn't tested again yet.
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed