Alt-Tickit-Widgets-ObjectPad
view release on metacpan or search on metacpan
lib/Tickit/Widget/Entry.pm view on Meta::CPAN
my ( $pos_ch ) = @_;
$pos_ch = 0 if $pos_ch < 0;
$pos_ch = length $_text if $pos_ch > length $_text;
$self->reposition_cursor( $pos_ch );
}
=head1 METHODS
=cut
=head2 $entry->bind_keys( $keystr => $value, ... )
Associate methods or CODE references with keypresses. On receipt of a the key
the method or CODE reference will be invoked, being passed the stringified key
representation and the underlying C<Term::TermKey::Key> structure.
$ret = $entry->method( $keystr, $key )
$ret = $coderef->( $entry, $keystr, $key )
This method takes a hash of keystring/value pairs. Binding a value of C<undef>
will remove it.
=cut
method bind_keys
{
while( @_ ) {
my $str = shift;
my $value = shift;
if( defined $value ) {
$_keybindings{$str} = $value;
}
else {
delete $_keybindings{$str};
}
}
}
=head1 TEXT MODEL METHODS
These methods operate on the text input buffer directly, updating the stored
text and changing the rendered display to reflect the changes. They can be
used by a program to directly manipulate the text.
=cut
=head2 $text = $entry->text
Returns the currently entered text.
=cut
method text { $_text }
=head2 $entry->set_text( $text )
Replace the text in the entry box. This completely redraws the widget's
window. It is largely provided for initialisation; for normal edits (such as
from keybindings), it is preferable to use C<text_insert>, C<text_delete> or
C<text_splice>.
=cut
method set_text
{
my ( $text ) = @_;
$_text = $text;
$_pos_ch = length $text if $_pos_ch > length $text;
$self->redraw;
}
=head2 $entry->text_insert( $text, $pos_ch )
Insert the given text at the given character position.
=cut
method text_insert
{
my ( $text, $pos_ch ) = @_;
$self->text_splice( $pos_ch, 0, $text );
}
=head2 $deleted = $entry->text_delete( $pos_ch, $len_ch )
Delete the given section of text. Returns the deleted text.
=cut
method text_delete
{
my ( $pos_ch, $len_ch ) = @_;
return $self->text_splice( $pos_ch, $len_ch, "" );
}
=head2 $deleted = $entry->text_splice( $pos_ch, $len_ch, $text )
Replace the given section of text with the given replacement. Returns the
text deleted from the section.
=cut
method text_splice
{
my ( $pos_ch, $len_ch, $text ) = @_;
my $textlen_ch = length($text);
my $delta_ch = $textlen_ch - $len_ch;
my $at_end = ( $pos_ch == length $_text );
my $deleted = substr( $_text, $pos_ch, $len_ch, $text );
( run in 0.627 second using v1.01-cache-2.11-cpan-13bb782fe5a )