Text-Editor-Vip
view release on metacpan or search on metacpan
lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm view on Meta::CPAN
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 0.01;
@ISA = qw (Exporter);
@EXPORT = qw ();
@EXPORT_OK = qw ();
%EXPORT_TAGS = ();
}
=head1 NAME
Text::Editor::Vip::Buffer::Plugins::Clipboard - Internal clipboard handling
=head1 SYNOPSIS
use Text::Editor::Vip::Buffer ;
$buffer = new Text::Editor::Vip::Buffer() ;
$buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Plugins::Clipboard') ;
=head1 DESCRIPTION
lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm view on Meta::CPAN
=cut
#-------------------------------------------------------------------------------------------------------------
sub SetClipboardContents
{
=head2 SetClipboardContents
Sets the content of the named clipboard.
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=item * text, a scalar, or an array ref (elements are joined to a single string)
=back
$buffer->SetClipboardContents(4, 'something') ;
$buffer->SetClipboardContents(4, ['something', "\n", 'hi']) ;
=cut
my ($buffer, $clipboard_name, $text_to_insert) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("SetClipboardContents: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 3)
{
$buffer->PrintError("SetClipboardContents: wrong number of arguments!") ;
return(0) ;
}
$text_to_insert ='' unless defined $text_to_insert ;
lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm view on Meta::CPAN
if(ref($text_to_insert) eq 'ARRAY')
{
@text_to_insert = @$text_to_insert ;
}
else
{
@text_to_insert = ($text_to_insert) ;
}
#~ $buffer->{CLIPBOARDS}{$clipboard_name} = join('', @text_to_insert) ;
$buffer->{CLIPBOARDS}{$clipboard_name} = [@text_to_insert] ;
}
#-------------------------------------------------------------------------------------------------------------
sub GetClipboardContents
{
=head2 GetClipboardContents
Returns the contents of the named clipboard.
B<Arguments:>
=over 2
=item * clipboard name
=back
$buffer->GetClipboardContents(4) ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("GetClipboardContents: Invalid clipboard name!") ;
return('') ;
}
if(@_ != 2)
{
$buffer->PrintError("GetClipboardContents: wrong number of arguments!") ;
return('') ;
}
#~ exists $buffer->{CLIPBOARDS}{$clipboard_name} ? $buffer->{CLIPBOARDS}{$clipboard_name} : '' ;
if(exists $buffer->{CLIPBOARDS}{$clipboard_name})
{
return
(
join('', @{$buffer->{CLIPBOARDS}{$clipboard_name}})
)
}
else
{
return('') ;
}
}
#-------------------------------------------------------------------------------------------------------------
sub CopySelectionToClipboard
{
=head2 CopySelectionToClipboard
Makes a copy of the selected text and copies it to the named clipboard.
B<Arguments:>
=over 2
=item * clipboard name
=back
$buffer->CopySelectionToClipboard('some_clipboard_name') ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("CopySelectionToClipboard: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("CopySelectionToClipboard: wrong number of arguments!") ;
return(0) ;
}
if($buffer->IsSelectionEmpty)
lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm view on Meta::CPAN
$buffer->RunSubOnSelection
(
sub
{
my ($text, $selection_line_index, $modification_character, $original_selection, $buffer) = @_;
my $add_newline = $selection_line_index != $original_selection->GetEndLine()
? "\n"
: '' ;
$buffer->AppendToClipboardContents($clipboard_name, $text . $add_newline) ;
# remember to not modify the line
$text ;
}
, sub
{
$buffer->PrintError("Please select text to copy to clipboard '$clipboard_name'.\n") ;
}
) ;
return(1) ;
}
}
#-------------------------------------------------------------------------------------------------------------
sub InsertClipboardContents
{
=head2 InsertClipboardContents
Inserts the Contents of the named clipboard into the buffer.
B<Arguments:>
=over 2
=item * clipboard name
=back
$buffer->InsertClipboardContents('my_clipboard') ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("InsertClipboardContents: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("InsertClipboardContents: wrong number of arguments!") ;
return(0) ;
}
#~ $buffer->Insert($buffer->{CLIPBOARDS}{$clipboard_name}) ;
$buffer->Insert($buffer->GetClipboardContents($clipboard_name)) ;
return(1) ;
}
#---------------------------------------------------------------------------------------------
sub ClearClipboardContents
{
=head2 ClearClipboardContents
B<Arguments:>
=over 2
=item * clipboard name
=back
$buffer->ClearClipboardContents('clipboard_1') ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("ClearClipboardContents: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("ClearClipboardContents: wrong number of arguments!") ;
return(0) ;
}
delete $buffer->{CLIPBOARDS}{$clipboard_name} ;
return(1) ;
}
#---------------------------------------------------------------------------------------------
sub AppendToClipboardContents
{
=head2 AppendToClipboardContents
Adds the text argument to the end of the clipboard.
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=item * text, a scalar, or an array ref (elements are joined to a single string)
=back
$buffer->AppendToClipboardContents('clipboard_2', "some string and a newline\n") ;
=cut
my ($buffer, $clipboard_name, $text_to_insert) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("AppendToClipboardContents: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 3)
{
$buffer->PrintError("AppendToClipboardContents: wrong number of arguments!") ;
return(0) ;
}
$text_to_insert = '' unless defined $text_to_insert ;
lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm view on Meta::CPAN
if(ref($text_to_insert) eq 'ARRAY')
{
@text_to_insert = @$text_to_insert ;
}
else
{
@text_to_insert = ($text_to_insert) ;
}
#~ $buffer->{CLIPBOARDS}{$clipboard_name} .= join('', @text_to_insert) ;
push @{$buffer->{CLIPBOARDS}{$clipboard_name}}, @text_to_insert ;
return(1) ;
}
#-------------------------------------------------------------------------------------------------------------
sub PopClipboard
{
=head2 PopClipboard
Removes the last entry of a clipboard and returnes it. An error is displayed if the clipboard is empty.
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=back
$buffer->PopClipboard(4) ;
=cut
my ($buffer, $clipboard_name, $text_to_insert) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("PopClipboard: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("PopClipboard: wrong number of arguments!") ;
return(0) ;
}
if(@{$buffer->{CLIPBOARDS}{$clipboard_name}})
{
return( pop @{$buffer->{CLIPBOARDS}{$clipboard_name}} ) ;
}
else
{
$buffer->PrintError("PopClipboard: clipboard '$clipboard_name' is empty!") ;
return('') ;
}
}
#-------------------------------------------------------------------------------------------------------------
sub GetNumberOfClipboardElements
{
=head2 GetNumberOfClipboardElements
Returns the number of elements in the clipboard, zero if the clipboard doesn't exist.
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=back
$buffer->GetNumberOfClipboardElements(4) ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("PopClipboard: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("PopClipboard: wrong number of arguments!") ;
return(0) ;
}
if(exists $buffer->{CLIPBOARDS}{$clipboard_name})
{
return(scalar (@{$buffer->{CLIPBOARDS}{$clipboard_name}})) ;
}
else
{
return(0) ;
}
}
#-------------------------------------------------------------------------------------------------------------
sub YankLineToClipboard
{
=head2 YankLineToClipboard
Removes a line from the buffer and adds it to a clipboard
B<Arguments:>
=over 2
=item * line number
=item * clipboard name, a scalar
=back
$buffer->YankLineToClipboard(4, 'clipboard') ;
=cut
my ($buffer, $line, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("YankLineToClipboard: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 3)
{
$buffer->PrintError("YankLineToClipboard: wrong number of arguments!") ;
return(0) ;
}
if(! defined $line || $line < 0 || $line > $buffer->GetLastLineIndex())
{
$buffer->PrintError("SetClipboardContents: Invalid line arguments!") ;
return(0) ;
}
$buffer->AppendToClipboardContents($clipboard_name, $buffer->GetLineTextWithNewline($line));
$buffer->DeleteLine($line) ;
return(1) ;
}
#-------------------------------------------------------------------------------------------------------------
sub YankSelectionToClipboard
{
=head2 YankSelectionToClipboard
Removes the current selection from the buffer and adds it to a clipboard
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=item * text, a scalar, or an array ref (elements are joined to a single string)
=back
$buffer->YankSelectionToClipboard('clipboard') ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("YankSelectionToClipboard: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("YankSelectionToClipboard: wrong number of arguments!") ;
return(0) ;
}
$buffer->RunSubOnSelection
(
sub
{
my ($text, $selection_line_index, $modification_character, $original_selection, $buffer) = @_;
#~ $buffer->AppendToClipboardContents($clipboard_name, $buffer->GetSelectionText($selection_line_index)) ;
my $add_newline = $selection_line_index != $original_selection->GetEndLine()
? "\n"
: '' ;
$buffer->AppendToClipboardContents($clipboard_name, $text . $add_newline) ;
# remove selection content from buffer
return(undef) ;
}
, sub
{
$buffer->PrintError("Please select text to yank to clipboard '$clipboard_name'.\n") ;
}
) ;
return(1) ;
}
#-------------------------------------------------------------------------------------------------------------
sub AppendCurrentLineToClipboardContents
{
=head2 AppendCurrentLineToClipboardContents
Adds the current line to a clipboars
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=back
$buffer->AppendCurrentLineToClipboardContents(4) ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("AppendCurrentLineToClipboardContents: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("AppendCurrentLineToClipboardContents: wrong number of arguments!") ;
return(0) ;
}
$buffer->AppendToClipboardContents($clipboard_name, $buffer->GetLineTextWithNewline()) ;
return(1) ;
}
#-------------------------------------------------------------------------------------------------------------
sub AppendSelectionToClipboardContents
{
=head2 AppendSelectionToClipboardContents
Adds the current selection to a clipboars
B<Arguments:>
=over 2
=item * clipboard name, a scalar
=back
$buffer->AppendSelectionToClipboardContents(4, 'clipboard') ;
=cut
my ($buffer, $clipboard_name) = @_ ;
if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
{
$buffer->PrintError("AppendSelectionToClipboardContents: Invalid clipboard name!") ;
return(0) ;
}
if(@_ != 2)
{
$buffer->PrintError("AppendSelectionToClipboardContents: wrong number of arguments!") ;
return(0) ;
}
unless($buffer->IsSelectionEmpty())
{
$buffer->AppendToClipboardContents($clipboard_name, $buffer->GetSelectionText()) ;
}
else
{
$buffer->PrintError("AppendSelectionToClipboardContents: no selection!") ;
}
return(1) ;
}
#-------------------------------------------------------------------------------------------------------------
lib/Text/Editor/Vip/Setup/Actions/default_actions.pl view on Meta::CPAN
, [ 'Extend selection left' , 'Left' , '00S' => sub {$_[BUFFER]->ExtendSelectionLeft() ;}]
, [ 'Extend selection right' , 'Right' , '00S' => sub {$_[BUFFER]->ExtendSelectionRight() ;}]
, [ 'Extend selection to next word' , 'Right' , 'C0S' => sub {$_[BUFFER]->ExtendSelectionToNextWord() ;}]
, [ 'Extend selection to previous word' , 'Left' , 'C0S' => sub {$_[BUFFER]->ExtendSelectionToPreviousWord() ;}]
, [ 'Extend selection up' , 'Up' , '00S' => sub {$_[BUFFER]->ExtendSelectionUp() ;}]
, [ 'Extend selection down' , 'Down' , '00S' => sub {$_[BUFFER]->ExtendSelectionDown() ;}]
#~ , [ 'Extend selection page up' , 'Prior' , '00S' => sub {$_[BUFFER]->ExtendSelectionPageUp() ;}]
#~ , [ 'Extend selection page down' , 'Next' , '00S' => sub {$_[BUFFER]->ExtendSelectionPageDown() ;}]
, [ 'Copy selection to systemclipboard' , 'Insert' , 'C00' => sub {$_[BUFFER]->PrintError("copy to main clipboard unimplemented!") ;}]
, [ 'Insert system clipboard contents' , 'Insert' , '00S' => sub {$_[BUFFER]->PrintError("paste from main clipboard unimplemented!") ;}]
, [ 'Copy selection to clipboard 1' , '&' , 'C00' => sub {$_[BUFFER]->CopySelectionToClipboard(1) ;}]
, [ 'Insert clipboard contents 1' , '1' , 'C0S' => sub {$_[BUFFER]->InsertClipboardContents(1) ;}]
, [ 'Copy selection to clipboard 2' , 'é' , 'C00' => sub {$_[BUFFER]->CopySelectionToClipboard(2) ;}]
, [ 'Insert clipboard contents 2' , '2' , 'C0S' => sub {$_[BUFFER]->InsertClipboardContents(2) ;}]
, [ 'Copy selection to clipboard 3' , '"' , 'C00' => sub {$_[BUFFER]->CopySelectionToClipboard(3) ;}]
, [ 'Insert clipboard contents 3' , '3' , 'C0S' => sub {$_[BUFFER]->InsertClipboardContents(3) ;}]
, [ 'Copy selection to clipboard 4' , "'" , 'C00' => sub {$_[BUFFER]->CopySelectionToClipboard(4) ;}]
, [ 'Insert clipboard contents 4' , '4' , 'C0S' => sub {$_[BUFFER]->InsertClipboardContents(5) ;}]
) ;
# display
$actions->RegisterActions
(
[ 'Center current line in display', 'C' , 'C0S' => sub {$_[VIEW]->CenterCurrentLineInDisplay() ;}]
, [ 'Flip display size' , 'Return' , 'C00' => sub {$_[VIEW]->FlipDisplaySize() ;}]
, [ 'Flip line number display' , 'L' , '0A0' => sub {$_[VIEW]->FlipLineNumberDisplay() ;}]
, [ 'display tab stops' , 'T' , '0A0' => sub {$_[VIEW]->DisplayTabStops() ;}]
t/023_Text_Editor_Vip_Buffer_Clipboard.t view on Meta::CPAN
$buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Test') ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
# SetClipboardContents, GetClipboardContents
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
is($buffer->GetClipboardContents('unexistant'), '', 'unexistant clipboard is empty') ;
$buffer->GetClipboardContents() ;
is_error_generated('undefined clipboard generates error') ;
$buffer->SetClipboardContents(undef, '') ;
is_error_generated('setting undef clipboard generates error') ;
$buffer->SetClipboardContents('', '') ;
is_error_generated('setting empty clipboard generates error') ;
$buffer->SetClipboardContents([], '') ;
is_error_generated('array clipboard name generates error') ;
$buffer->SetClipboardContents('name') ;
is_error_generated('wrong number of arguments generates error') ;
$buffer->SetClipboardContents('string', 'string') ;
is($buffer->GetClipboardContents('string'), 'string', 'getting clipboard named with string') ;
$buffer->SetClipboardContents(1, 1) ;
is($buffer->GetClipboardContents(1), 1, 'getting clipboard named with figure') ;
$buffer->SetClipboardContents('array', 'string') ;
is($buffer->GetClipboardContents('string'), 'string', 'getting clipboard named with string') ;
$buffer->SetClipboardContents('array_ref', ['string']) ;
is($buffer->GetClipboardContents('string'), 'string', 'getting clipboard named with string') ;
# clearing
$buffer->SetClipboardContents('string', 'string') ;
is($buffer->GetClipboardContents('string'), 'string', 'getting clipboard named with string') ;
$buffer->ClearClipboardContents('string') ;
is($buffer->GetClipboardContents('string'), '', 'cleared clipboard is empty') ;
$buffer->ClearClipboardContents('string', 'extra') ;
is_error_generated('extra arguments generates error') ;
$buffer->ClearClipboardContents() ;
is_error_generated('clearing to undef clipboard generates error') ;
$buffer->ClearClipboardContents('') ;
is_error_generated('clearing empty clipboard name generates error') ;
$buffer->ClearClipboardContents([]) ;
is_error_generated('array name generates error') ;
#AppendToClipboardContents
$buffer->AppendToClipboardContents('string', 'string') ;
is($buffer->GetClipboardContents('string'), 'string', 'getting clipboard named with string') ;
$buffer->AppendToClipboardContents('string', 'string2') ;
is($buffer->GetClipboardContents('string'), 'stringstring2', 'getting clipboard named with string') ;
$buffer->AppendToClipboardContents('test', ["test\n", "test"]) ;
is($buffer->GetClipboardContents('test'), "test\ntest", 'getting clipboard named with string') ;
$buffer->AppendToClipboardContents('string') ;
is_error_generated('wrong number of arguments generates error') ;
is($buffer->GetClipboardContents('string'), 'stringstring2', 'clipboard unchanged') ;
$buffer->AppendToClipboardContents(undef, 'something') ;
is_error_generated('appending to undef clipboard generates error') ;
$buffer->AppendToClipboardContents('', 'something') ;
is_error_generated('appending empty clipboard name generates error') ;
$buffer->ClearClipboardContents([], 'something') ;
is_error_generated('appending array name generates error') ;
# reset empties clipboards
$buffer->Reset() ;
is($buffer->GetClipboardContents('string'), '', 'getting clipboard named with string') ;
is($buffer->GetClipboardContents(1), '', 'getting clipboard named with figure') ;
$buffer->GetClipboardContents('valid', 'extra arguments') ;
is_error_generated('extra arguments generates error') ;
# CopySelectionToClipboard
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
$buffer->CopySelectionToClipboard(undef) ;
is_error_generated('copying selection to undef clipboard generates error') ;
$buffer->CopySelectionToClipboard('') ;
is_error_generated('copying to empty clipboard generates error') ;
$buffer->CopySelectionToClipboard([]) ;
is_error_generated('array name generates error') ;
$buffer->CopySelectionToClipboard('valid', 'extra arguments'), ;
is_error_generated('extra arguments generates error') ;
$buffer->SetClipboardContents('string', 'string') ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), 'string', 'copy empty selection changes nothing') ;
# set selection
$buffer->ClearClipboardContents('string') ;
$buffer->SetSelectionBoundaries(0, 1, 1, 2) ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), "ine 1 - 1\nli", 'getting clipboard named with string and from selection') ;
$buffer->ClearClipboardContents('string') ;
$buffer->CopySelectionToClipboard(1) ;
is($buffer->GetClipboardContents(1), "ine 1 - 1\nli", 'getting clipboard named with figure and from selection') ;
$buffer->ClearClipboardContents('string') ;
$buffer->SetSelectionBoundaries(0, 0, 1, 0) ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), "line 1 - 1\n", 'getting clipboard named with string and from selection') ;
$buffer->ClearClipboardContents('string') ;
$buffer->SetSelectionBoundaries(-10, 0, 2, 0) ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), "line 1 - 1\nline 2 - 2 2\n", 'getting clipboard named with string and from selection') ;
$buffer->ClearClipboardContents('string') ;
$buffer->SetSelectionBoundaries(0, 0, 3, 0) ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), "line 1 - 1\nline 2 - 2 2\n", 'getting clipboard named with string and from selection') ;
# InsertClipboardContents
$buffer->Reset() ;
$buffer->SetModificationPosition(0, 0) ;
$buffer->InsertClipboardContents('unexistant') ;
is($buffer->GetText(), '', 'Insert unexisting Clipboard changes nothing') ;
$buffer->InsertClipboardContents() ;
is_error_generated('inserting un-namedclipboard generates error') ;
is($buffer->GetText(), '', 'Inserting undef Clipboard changes nothing') ;
$buffer->InsertClipboardContents('') ;
is_error_generated('Inserting un-named clipboard generates error') ;
is($buffer->GetText(), '', 'Inserting un-named Clipboard changes nothing') ;
$buffer->InsertClipboardContents([]) ;
is_error_generated('Inserting un-named clipboard generates error') ;
is($buffer->GetText(), '', 'Inserting un-named Clipboard changes nothing') ;
$buffer->SetClipboardContents('string', $text) ;
$buffer->InsertClipboardContents('string') ;
is($buffer->GetText(), $text, 'Inserted Clipboard content == buffer content') ;
#YankLineToClipboard
#-------------------
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
$buffer->YankLineToClipboard(1, '') ;
is_error_generated('setting undef clipboard generates error') ;
$buffer->YankLineToClipboard(1, []) ;
is_error_generated('array clipboard name generates error') ;
$buffer->YankLineToClipboard(1, undef) ;
is_error_generated('array clipboard name generates error') ;
$buffer->YankLineToClipboard(1) ;
is_error_generated('wrong number of arguments generates error') ;
$buffer->YankLineToClipboard(undef, 1) ;
is_error_generated('undefined line generates error') ;
$buffer->YankLineToClipboard(-1 , 1) ;
is_error_generated('invalid line generates error') ;
$buffer->YankLineToClipboard(10 , 1) ;
is_error_generated('invalid line generates error') ;
# verify content
my $number_of_lines = $buffer->GetNumberOfLines() ;
my $line_0 = $buffer->GetLineTextWithNewline(0) ;
$buffer->YankLineToClipboard(0 , 1) ;
isnt_error_generated("valid yank doesn't generate an error") ;
is($buffer->GetClipboardContents(1), $line_0, 'right line yanked to clipboard') ;
is($number_of_lines, $buffer->GetNumberOfLines() + 1, "line removed from buffer") ;
my $line_1 = $buffer->GetLineTextWithNewline(0) ;
$buffer->YankLineToClipboard(0 , 1) ;
isnt_error_generated("valid yank doesn't generate an error") ;
is($buffer->GetClipboardContents(1), $line_0 . $line_1, 'right line yanked to clipboard') ;
is($number_of_lines, $buffer->GetNumberOfLines() + 2, "line removed from buffer") ;
#PopClipboard
#-------------------
is($buffer->PopClipboard(1), $line_1, 'line 1 poped from clipboard') ;
isnt_error_generated("valid pop doesn't generate an error") ;
is($buffer->PopClipboard(1), $line_0, 'line 0 poped to clipboard') ;
isnt_error_generated("valid pop doesn't generate an error") ;
is($buffer->PopClipboard(1), '', 'empty clipboard returns empty string') ;
is_error_generated("empty clipboard poping generate an error") ;
$buffer->PopClipboard(1, 2, 3) ;
is_error_generated("wrong number of arguments generate an error") ;
$buffer->PopClipboard('') ;
is_error_generated('empty clipboard name generates error') ;
$buffer->PopClipboard([]) ;
is_error_generated('array clipboard name generates error') ;
$buffer->PopClipboard(undef) ;
is_error_generated('undef clipboard name generates error') ;
# GetNumberOfClipboardElements
#------------------------------------------------
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
$buffer->YankLineToClipboard(0 , 1) ;
$buffer->YankLineToClipboard(0 , 1) ;
is($buffer->GetNumberOfClipboardElements(1), 2, 'clipboard has content') ;
is($buffer->GetNumberOfClipboardElements('new'), 0, 'accessing a non existant clipboard') ;
isnt_error_generated("no errors when accessing a non existant clipboard") ;
$buffer->GetNumberOfClipboardElements(1, 2, 3) ;
is_error_generated("wrong number of arguments generate an error") ;
$buffer->GetNumberOfClipboardElements('') ;
is_error_generated('empty clipboard name generates error') ;
$buffer->GetNumberOfClipboardElements([]) ;
is_error_generated('array clipboard name generates error') ;
$buffer->GetNumberOfClipboardElements(undef) ;
is_error_generated('undef clipboard name generates error') ;
# YankSelectionToClipboard
# ---------------------------
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
$buffer->YankSelectionToClipboard('') ;
is_error_generated('empty clipboard name generates error') ;
$buffer->YankSelectionToClipboard([]) ;
is_error_generated('array clipboard name generates error') ;
$buffer->YankSelectionToClipboard(undef) ;
is_error_generated('undef clipboard name generates error') ;
#~ selection error
$buffer->YankSelectionToClipboard('selection') ;
is_error_generated('no selection generates error') ;
$buffer->SetSelectionBoundaries(0, 0, 0, 0) ;
$buffer->YankSelectionToClipboard('selection') ;
is_error_generated('no selection generates error') ;
#~ weird selection
t/023_Text_Editor_Vip_Buffer_Clipboard.t view on Meta::CPAN
# ------------------------------------
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
$number_of_lines = $buffer->GetNumberOfLines() ;
my $buffer_text = $buffer->GetText() ;
$buffer->AppendCurrentLineToClipboardContents('string') ;
isnt_error_generated('AppendCurrentLineToClipboardContents generates no error') ;
is($buffer->GetClipboardContents('string'), "line 1 - 1\n", 'current line copied to clipboard') ;
is($buffer->GetNumberOfLines(), $number_of_lines, 'unmodified number of lines') ;
is($buffer->CompareText($buffer_text), '', "unmodified buffer contents") ;
$buffer->AppendCurrentLineToClipboardContents('string', 1, 2) ;
is_error_generated('wrong number of arguments generates error') ;
is($buffer->GetClipboardContents('string'), "line 1 - 1\n", 'clipboard unchanged') ;
$buffer->AppendCurrentLineToClipboardContents(undef) ;
is_error_generated('appending to undef clipboard generates error') ;
$buffer->AppendCurrentLineToClipboardContents('') ;
is_error_generated('appending empty clipboard name generates error') ;
$buffer->AppendCurrentLineToClipboardContents([]) ;
is_error_generated('appending array name generates error') ;
#~ line error
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(-10, -10) ; # doesn't modify position
$buffer->AppendCurrentLineToClipboardContents('string') ;
is_error_generated('AppendCurrentLineToClipboardContents with bad position generates error') ;
is($buffer->GetClipboardContents('string'), '', 'nothing copied to clipboard') ;
# AppendSelectionToClipboardContents
$buffer->Reset() ;
$buffer->Insert($text) ;
$buffer->SetModificationPosition(0, 0) ;
$buffer->SetSelectionBoundaries(0, 1, 1, 2) ;
$buffer->AppendSelectionToClipboardContents('string') ;
is($buffer->GetClipboardContents('string'), "ine 1 - 1\nli", 'getting clipboard named with string and from selection') ;
$buffer->ClearClipboardContents('string') ;
is($buffer->GetClipboardContents('string'), '', 'getting clipboard named with string and from selection') ;
# select all
my $number_of_lines2 = $buffer->GetNumberOfLines() ;
my $buffer_text2 = $buffer->GetText() ;
$buffer->SelectAll() ;
$buffer->AppendSelectionToClipboardContents('string') ;
isnt_error_generated('AppendSelectionToClipboardContents generates no error') ;
is($buffer->GetClipboardContents('string'), $buffer_text2, 'current line copied to clipboard') ;
is($buffer->GetNumberOfLines(), $number_of_lines2, 'unmodified number of lines') ;
is($buffer->CompareText($buffer_text2), '', "unmodified buffer contents") ;
#empty buffer, paste clipboard
$buffer->Delete() ;
$buffer->InsertClipboardContents('string') ;
is($buffer->GetClipboardContents('string'), $buffer_text2, 'current line copied to clipboard') ;
is($buffer->GetNumberOfLines(), $number_of_lines2, 'unmodified number of lines') ;
is($buffer->CompareText($buffer_text2), '', "unmodified buffer contents") ;
# arg errors
$buffer->AppendSelectionToClipboardContents('string', 1, 2) ;
is_error_generated('wrong number of arguments generates error') ;
is($buffer->GetClipboardContents('string'), $buffer_text2, 'clipboard unchanged') ;
$buffer->AppendSelectionToClipboardContents(undef) ;
is_error_generated('appending to undef clipboard generates error') ;
$buffer->AppendSelectionToClipboardContents('') ;
is_error_generated('appending empty clipboard name generates error') ;
$buffer->AppendSelectionToClipboardContents([]) ;
is_error_generated('appending array name generates error') ;
#~selection error
$buffer->Reset() ;
$buffer->Insert($text) ;
# no selection
$buffer->AppendSelectionToClipboardContents('string') ;
is_error_generated('AppendSelectionToClipboardContents with no selection generates error') ;
is($buffer->GetClipboardContents('string'), '', 'nothing copied to clipboard') ;
$buffer->ClearClipboardContents('string') ;
$buffer->SetSelectionBoundaries(-10, 0, 2, 0) ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), $text, 'getting clipboard named with string and from selection') ;
isnt_error_generated('selection is boxed') ;
$buffer->ClearClipboardContents('string') ;
$buffer->SetSelectionBoundaries(0, 0, 3, 0) ;
$buffer->CopySelectionToClipboard('string') ;
is($buffer->GetClipboardContents('string'), $text, 'getting clipboard named with string and from selection') ;
isnt_error_generated('selection is boxed') ;
( run in 2.383 seconds using v1.01-cache-2.11-cpan-84e82930d8c )