Padre-Plugin-Vi

 view release on metacpan or  search on metacpan

lib/Padre/Plugin/Vi/Editor.pm  view on Meta::CPAN


sub insert_mode {              # insert
	my ( $self, $count ) = @_; # use $count ?
	$self->{insert_mode} = 1;
	my $pos = $self->{editor}->GetCurrentPos;
	$self->{editor}->GotoPos( $pos - 1 );

	# change cursor
}

sub insert_at_first_non_blank {
	my ($self) = @_;

	$self->goto_first_non_blank;
	$self->insert_mode;
}

sub open_below {
	my ( $self, $count ) = @_; # TODO use $count ??
	$self->{insert_mode} = 1;
	my $line = $self->{editor}->GetCurrentLine;
	my $end  = $self->{editor}->GetLineEndPosition($line);

	# go to end of line, insert newline
	$self->{editor}->GotoPos($end);
	$self->{editor}->NewLine;

	# change cursor
}

sub open_above {
	my ( $self, $count ) = @_;
	$self->{insert_mode} = 1;
	my $line  = $self->{editor}->GetCurrentLine;
	my $start = $self->{editor}->PositionFromLine($line);

	# go to beginning of line, insert newline, go to previous line
	$self->{editor}->GotoPos($start);
	$self->{editor}->NewLine;
	$self->{editor}->GotoPos($start);

	# change cursor
}

sub delete_char {
	my ( $self, $count ) = @_;
	my $pos = $self->{editor}->GetCurrentPos;
	$self->{editor}->SetTargetStart($pos);
	$self->{editor}->SetTargetEnd( $pos + $count );
	$self->{buffer} = '';
	$self->{editor}->ReplaceTarget('');
}

sub undo {
	my ( $self, $count ) = @_;
	$self->{editor}->Undo;
}

sub paste_after {
	my ( $self, $count ) = @_;
	my $text = Padre::Wx::Editor::get_text_from_clipboard();
	if ( $text =~ /\n/ ) {
		my $line  = $self->{editor}->GetCurrentLine;
		my $start = $self->{editor}->PositionFromLine( $line + 1 );
		$self->{editor}->GotoPos($start);
	}
	$self->{editor}->Paste;
}

sub paste_before {
	my ( $self, $count ) = @_;
	my $text = Padre::Wx::Editor::get_text_from_clipboard();
	if ( $text =~ /\n/ ) {
		my $line  = $self->{editor}->GetCurrentLine;
		my $start = $self->{editor}->PositionFromLine($line);
		$self->{editor}->GotoPos($start);
	} else {
		my $pos = $self->{editor}->GetCurrentPos;
		$self->{editor}->GotoPos( $pos - 1 );
	}
	$self->{editor}->Paste;
}

sub join_lines {
	my ( $self, $count ) = @_;
	my $main = Padre->ide->wx->main;
	$main->on_join_lines;
}

sub goto_line {
	my ( $self, $count ) = @_; # TODO: special case for count !!
	$self->{editor}->GotoLine( $count - 1 );
	$self->{buffer} = '';
}

sub delete_lines {
	my ( $self, $count ) = @_;
	$self->select_rows($count);
	$self->{editor}->Cut;
}

sub delete_till_end_of_line {
	my ( $self, $count ) = @_;

	#$self->{editor}->DelLineRight; # would be nice, but it does not put the strin in the clipboard

	$self->select_till_end_of_line;
	$self->{editor}->Cut;
}

sub yank_till_end_of_line {
	my ( $self, $count ) = @_;

	$self->select_till_end_of_line;
	$self->{editor}->Copy;
}

sub select_till_end_of_line {
	my ($self) = @_;
	my $line   = $self->{editor}->GetCurrentLine;
	my $start  = $self->{editor}->GetCurrentPos;
	my $end    = $self->{editor}->GetLineEndPosition($line);

	$self->{editor}->SetTargetStart($start);
	$self->{editor}->SetTargetEnd($end);
	$self->{editor}->SetSelection( $start, $end );

	return;
}

sub delete_words {
	my ( $self, $count ) = @_;
	$self->{editor}->WordRightEndExtend for 1 .. $count;
	$self->{editor}->Cut;
	return;
}

sub yank_words {
	my ( $self, $count ) = @_;
	$self->{editor}->WordRightEndExtend for 1 .. $count;
	$self->{editor}->Copy;
	return;
}

sub yank_lines {
	my ( $self, $count ) = @_;
	$self->select_rows($count);
	$self->{editor}->Copy;
	$self->remove_selection;
}

sub remove_selection {
	my ($self) = @_;
	$self->{editor}->SetSelectionStart( $self->{editor}->GetSelectionEnd );
	return;
}

sub delete_selection {
	my ($self) = @_;
	$self->{editor}->Cut;
}

sub yank_selection {
	my ($self) = @_;
	$self->{editor}->Copy;



( run in 0.655 second using v1.01-cache-2.11-cpan-84e82930d8c )