Skip to content

Commit

Permalink
CardNumberEntry: gtk4 prep (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Aug 23, 2023
1 parent 651ace0 commit e1471bc
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Widgets/CardNumberEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AppCenter.Widgets.CardNumberEntry : Gtk.Entry {
}

private CardType card_type = CardType.UNKNOWN;
private uint timeout = 0;
private bool insertion = true;

construct {
Expand All @@ -49,12 +48,10 @@ public class AppCenter.Widgets.CardNumberEntry : Gtk.Entry {
});

changed.connect (() => {
if (timeout > 0) {
GLib.Source.remove (timeout);
}
update_number ();
detect_card ();
change_card_icon ();

int[] pattern = get_card_pattern ();
var number_chars = card_number.to_utf8 ();
var builder = new GLib.StringBuilder ();
Expand All @@ -65,14 +62,16 @@ public class AppCenter.Widgets.CardNumberEntry : Gtk.Entry {
}
}

var end_offset = (text.char_count () - 1) - cursor_position;
text = builder.str;
var new_offset = (text.char_count () - 1) - cursor_position;
if (end_offset != new_offset) {
Idle.add (() => {
move_cursor (Gtk.MovementStep.LOGICAL_POSITIONS, new_offset - end_offset, false);
return false;
});
if (text != builder.str) {
var end_offset = (text.char_count () - 1) - cursor_position;
text = builder.str;
var new_offset = (text.char_count () - 1) - cursor_position;
if (end_offset != new_offset) {
Idle.add (() => {
set_position (new_offset + end_offset + 1);
return false;
});
}
}

max_length = get_card_max_length () + pattern.length;
Expand Down

0 comments on commit e1471bc

Please sign in to comment.