Skip to content
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

#605: Ctrl-V should not paste text twice #606

Merged
merged 2 commits into from
Jun 23, 2024
Merged

Conversation

lidaobing
Copy link
Member

@lidaobing lidaobing commented Jun 23, 2024

Summary by Sourcery

This pull request addresses a bug where using Ctrl-V to paste text would result in the text being pasted twice. The text pasting logic was refactored to use the 'paste-clipboard' signal, and a new test was added to ensure correct functionality.

  • Bug Fixes:
    • Fixed issue where pasting text using Ctrl-V would result in the text being pasted twice.
  • Enhancements:
    • Refactored text pasting logic to use the 'paste-clipboard' signal for better consistency.
  • Tests:
    • Added a test to verify that text is correctly pasted from the clipboard into the text buffer.

@lidaobing lidaobing linked an issue Jun 23, 2024 that may be closed by this pull request
Copy link

sourcery-ai bot commented Jun 23, 2024

Reviewer's Guide by Sourcery

This pull request addresses the issue where Ctrl-V would paste text twice. The main changes include the introduction of a new utility function igtk_text_buffer_get_text for retrieving text from a GtkTextBuffer, refactoring paste handling to use GTK's 'paste-clipboard' signal, and updating tests to verify the correct behavior.

File-Level Changes

Files Changes
src/iptux/UiHelper.cpp
src/iptux/UiHelper.h
Introduced a new utility function igtk_text_buffer_get_text to retrieve text from a GtkTextBuffer.
src/iptux/DialogBase.cpp
src/iptux/DialogPeer.cpp
Refactored paste handling to use GTK's 'paste-clipboard' signal and removed direct text paste handling from OnPasteClipboard.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@lidaobing lidaobing changed the title #605: Ctrl-V will paste text twice #605: Ctrl-V should not paste text twice Jun 23, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @lidaobing - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -376,4 +376,13 @@ GtkImage* igtk_image_new_with_size(const char* filename,
return GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
}

string igtk_text_buffer_get_text(GtkTextBuffer* buffer) {
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider using std::string instead of string.

To maintain consistency and avoid potential issues with ambiguous types, it's generally better to use std::string explicitly.

Suggested change
string igtk_text_buffer_get_text(GtkTextBuffer* buffer) {
std::string igtk_text_buffer_get_text(GtkTextBuffer* buffer) {

string igtk_text_buffer_get_text(GtkTextBuffer* buffer) {
GtkTextIter start, end;
gtk_text_buffer_get_bounds(buffer, &start, &end);
char* res1 = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Check for null pointer before using res1.

gtk_text_buffer_get_text can return NULL. It's safer to check if res1 is not NULL before using it to construct the string.

Copy link

codecov bot commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.37%. Comparing base (8653a31) to head (467944a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #606   +/-   ##
=======================================
  Coverage   51.36%   51.37%           
=======================================
  Files          64       64           
  Lines        8344     8345    +1     
=======================================
+ Hits         4286     4287    +1     
  Misses       4058     4058           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lidaobing lidaobing added this to the 0.9.2 milestone Jun 23, 2024
@lidaobing lidaobing merged commit 0b47207 into master Jun 23, 2024
15 checks passed
@lidaobing lidaobing deleted the 605-paste-text-twice branch June 23, 2024 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl+V will paste text twice after #593
1 participant