Place the test inside the text control

j_arun_mani,
I just tested this on Windows, where this “works natively”.

I set the linit to be 20 and the control initially empty.

Start typing you can’t emter more than 20 symbols and the cursor keeps the end position.
Trying to enter text in the middle - new text will not be entered and the cursor will keep its position.

Delete everything. Control is empty.
Try to paste a long string - the paste will be truncated and the cursor will be at the position 20.
Enter some text, move the cursor in the middle and try to paste - paste will be partially allowed and the cursor will keep its relative position.

So I guess you are right - paste will be partially allowed.

I will see if I can convert my code to C - should be straightforward…

Thank you and sorry for the confusion.

1 Like

j_arun_mani,

I’m trying to use following code:

gint count = gtk_text_buffer_get_char_count( buffer );
unsigned long maxlen = 20;
if ( count > maxlen )
{
    GtkTextIter offset, end;
    int posEnd;
    g_object_get( G_OBJECT( buffer ), "cursor-position", &posEnd, NULL );
    gtk_text_buffer_get_iter_at_offset( buffer, &offset, maxlen - 1 );
    gtk_text_buffer_get_iter_at_offset( buffer, &end, posEnd - 1 );
    gtk_text_buffer_delete( buffer, &offset, &end );
}

, but I’m getting a crash.

Is there a better way to get an iterator for the cursor position?

TIA!

BTW, what do you use to format the code? I tried to click on the “Preformatted text” icon and it didn’t work…

P.S.: Please ignore. This is my old code crashing. Sorry for the noise. Will keep testing. Will let you know if it works correctly.

Hey there !

Please tag usernames using @. For example I can tag you by @oneeyeman1. By tagging a person, the person gets a notification. It helps :sweat_smile:

Sorry, I’m not so fluent in C, but as far as I know, converting GI (GObject Introspection) based code should be pretty straight forward.

I think you are referring to syntax highlighting as “code format”. To wrap code in our message, you can enclose them in triple back ticks. To get syntax highlighting of a specific language, specify the language after the first triple back ticks.

python
print(“hello”)

Coming back to the topic, I will also try my best in finding an appropriate solution for your case.
Cheers :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.