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
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 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 Down Expand Up @@ -27,6 +28,7 @@ TEST(DialogPeer, Constructor) {
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) {
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) {

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.

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
Loading