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 #1

Open
wants to merge 2 commits into
base: base-sha/8653a31b23ca4b390fbada04782596bae42c38cf
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 1 addition & 7 deletions src/iptux/DialogBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,7 @@ void DialogBase::OnPasteClipboard(DialogBase*, GtkTextView* textview) {
buffer = gtk_text_view_get_buffer(textview);
gtk_text_buffer_get_iter_at_mark(buffer, &iter,
gtk_text_buffer_get_insert(buffer));
if (gtk_clipboard_wait_is_text_available(clipboard)) {
gchar* text = gtk_clipboard_wait_for_text(clipboard);
if (text) {
gtk_text_buffer_insert(buffer, &iter, text, -1);
g_free(text);
}
} else if (gtk_clipboard_wait_is_image_available(clipboard)) {
if (gtk_clipboard_wait_is_image_available(clipboard)) {
GdkPixbuf* pixbuf = gtk_clipboard_wait_for_image(clipboard);
if (pixbuf) {
gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
Expand Down
2 changes: 1 addition & 1 deletion src/iptux/DialogPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void DialogPeer::onRequestSharedResources(void*, void*, DialogPeer& self) {

void DialogPeer::onPaste(void*, void*, DialogPeer* self) {
GtkTextView* textview = GTK_TEXT_VIEW(self->inputTextviewWidget);
DialogBase::OnPasteClipboard(self, textview);
g_signal_emit_by_name(textview, "paste-clipboard");
}

void DialogPeer::insertPicture() {
Expand Down
3 changes: 3 additions & 0 deletions src/iptux/DialogPeerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Application.h"
#include "UiHelper.h"
#include "gtest/gtest.h"

#include "iptux-utils/TestHelper.h"
Expand All @@ -23,10 +24,12 @@ TEST(DialogPeer, Constructor) {
GroupInfo* grpinf = app->getCoreThread()->GetPalRegularItem(pal.get());
grpinf->buffer = gtk_text_buffer_new(NULL);
DialogPeer* dlgpr = new DialogPeer(app, grpinf);
ASSERT_EQ(igtk_text_buffer_get_text(grpinf->getInputBuffer()), "");

auto clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, "hello world", -1);
do_action(dlgpr, "paste");
ASSERT_EQ(igtk_text_buffer_get_text(grpinf->getInputBuffer()), "hello world");

GError* error = NULL;
auto pixbuf =
Expand Down
9 changes: 9 additions & 0 deletions src/iptux/UiHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

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 different string 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) {

Choose a reason for hiding this comment

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

Is this comment correct?

Choose a reason for hiding this comment

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

Is this comment helpful?

Choose a reason for hiding this comment

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

Is the comment type correct?

Choose a reason for hiding this comment

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

Is the comment area correct?

Choose a reason for hiding this comment

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

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

GtkTextIter start, end;
gtk_text_buffer_get_bounds(buffer, &start, &end);
char* res1 = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);

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.

If gtk_text_buffer_get_text returns a null pointer, it could lead to undefined behavior when constructing the std::string.

Choose a reason for hiding this comment

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

Is this comment correct?

Choose a reason for hiding this comment

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

Is this comment helpful?

Choose a reason for hiding this comment

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

Is the comment type correct?

Choose a reason for hiding this comment

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

Is the comment area correct?

Choose a reason for hiding this comment

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

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

string res(res1);
g_free(res1);
return res;
}

} // namespace iptux
1 change: 1 addition & 0 deletions src/iptux/UiHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GSList* selection_data_get_path(GtkSelectionData* data);
* @return GtkImage* null if failed
*/
GtkImage* igtk_image_new_with_size(const char* filename, int width, int height);
std::string igtk_text_buffer_get_text(GtkTextBuffer* buffer);

/**
* @brief only used for test, after call this, pop_info, pop_warning,
Expand Down