Text-Editor-Easy

 view release on metacpan or  search on metacpan

lib/Text/Editor/Easy/Key.pm  view on Meta::CPAN

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

# Si aucun nom n'existe pour l'éditeur courant, faire apparaître une fenêtre le demandant
# => accès à un gestionnaire de fichier
    return $self->save;
}

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

    my $screen = $self->screen;
    print "Screen number = ", $screen->number, "\n";
    my $display = $screen->first;
    while ($display) {
        print $display->number, "|", $display->text, "\n";
        $display = $display->next;
    }
}

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

    my $display = $self->cursor->display;
    print "\nT|", $display->ord - $display->height, "\n";
    print "H|", $display->height, "\n";
    print "O|", $display->ord,    "\n";

}

my $buffer;

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

    #Appel au thread manager à faire. Pour l'instant, méthode provisoire et très longue
    my $select_ref = set_start_selection_point($self, '+');
    return if ( ! defined $select_ref->{'stop_line'} );
    my ( $start_line, $start_pos, $stop_line, $stop_pos );
    if ( $select_ref->{'mode'} eq '+' ) {
        $start_line = $select_ref->{'start_line'};
        $start_pos = $select_ref->{'start_pos'};
        $stop_line = $select_ref->{'stop_line'};
        $stop_pos = $select_ref->{'stop_pos'};
    }
    else {
        $start_line = $select_ref->{'stop_line'};
        $start_pos = $select_ref->{'stop_pos'};
        $stop_line = $select_ref->{'start_line'};
        $stop_pos = $select_ref->{'start_pos'};
    }
    my $buffer;
    if ( $stop_line != $start_line ) {
        $buffer = substr ( $start_line->text, $start_pos );
        $buffer .= "\n";
    }
    else {
        # A gérer 
        $buffer = substr ( $start_line->text, $start_pos, $stop_pos - $start_pos );
        print "========Debut buffer\n$buffer\n==========Fin buffer\n";
        Text::Editor::Easy->clipboard_set($buffer);
        return;
    }
    my $line = $start_line->next;
    while ( defined $line and $line != $stop_line ) {
        $buffer .= $line->text . "\n";
        $line = $line->next;
    }
    return if ( ! defined $line ); # stop line suppressed
    $buffer .= substr ( $line->text, 0, $stop_pos );
    print "========Debut buffer\n$buffer\n==========Fin buffer\n";
    Text::Editor::Easy->clipboard_set($buffer);
    #$buffer = $self->cursor->line->text . "\n";
}

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

    my $cursor = $self->cursor;
    my $line   = $cursor->line;
    $buffer = $line->text;
    $cursor->set(0);
    $self->erase( length( $line->text ) + 1 );
}

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

    $self->insert(Text::Editor::Easy->clipboard_get());
}

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

    my $screen = $self->screen;
    if ( $screen->wrap ) {
        $screen->unset_wrap;
    }
    else {
        $screen->set_wrap;
    }
}

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

    if ( $self->insert_mode ) {
        $self->set_replace;
    }
    else {
        $self->set_insert;
    }
}

# SHIFT (sélection)

sub shift_left {
        my ( $self ) = @_;
        
        #print "Dans shift_left de Key\n";
        my $select_ref = set_start_selection_point($self, '-');
        
        my ( $line, $pos ) = left( $self, 'shift' );
        return if ( ! $line );
        #print "Line récupérée de left $line, ", $line->text, " |", $line->ref, "\n";
        #print "Start Line ", $select_ref->{'start_line'}, $select_ref->{'start_line'}->text, " |", $select_ref->{'start_line'}->ref, "\n";
        if ( $line == $select_ref->{'start_line'} ) {
                $line->deselect;
                my $start_pos = $select_ref->{'start_pos'};
                if ( $start_pos > $pos ) {
                    $line->select( $pos, $start_pos);                    
                    $select_ref->{'mode'} = '-';
                }
                else {
                    $line->select( $start_pos, $pos );
                    $select_ref->{'mode'} = '+';
                }
        }
        else {
            if ( $line == $select_ref->{'stop_line'} ) {
                $line->deselect;
            }
            if ( $select_ref->{'mode'} eq '+' ) {
                $line->select(0, $pos);
            }
            else {
                $line->select($pos);
            }
        }

lib/Text/Editor/Easy/Key.pm  view on Meta::CPAN

    #$options_ref = Text::Editor::Easy->data_get_search_options ( $self->id );
    my ( $line_init, $pos ) = $editor->cursor->get;
    my ( $line, $start, $end, $regexp ) = $editor->search($exp);
    Text::Editor::Easy::Async->data_set_search_options ( $editor->id, {
        'exp' => dump ($regexp),
        'line_init' => $line_init->ref,
        'pos_init' => $pos,
    } );
    #print "Référence pour save ", $editor->id, "\n";
    $editor->deselect;
    return if ( ! defined $line );
    my $text = $line->select($start, $end, {'force' => 'middle_top'} );
    $editor->cursor->set( $end, $line );
    $editor->focus;
    $editor->visual_search( $regexp, $line, $end);
}

sub f3_search {
    my $editor = Text::Editor::Easy->last_current;
    my $options_ref = Text::Editor::Easy->data_get_search_options ( $editor->id );
    #print "Référence pour load ", $editor->id, "\n";
    #print "EXP : $options_ref->{'exp'}\n";
    #print "LINE: $options_ref->{'line_init'}\n";
    #print "pos : $options_ref->{'pos_init'}\n";
    my ( $line, $start, $end, $regexp ) = $editor->search(eval $options_ref->{'exp'}, {
            'stop_line' => $options_ref->{'line_init'},
            'stop_pos' => $options_ref->{'pos_init'},
    } );
    $editor->deselect;
    if ( ! defined $line ) {
        # Positionnement à l'endroit initial
        my $line_init = Text::Editor::Easy::Line->new($editor, $options_ref->{'line_init'});
        $editor->cursor->set($options_ref->{'pos_init'},$line_init);
        return;
    }
    my $text = $line->select($start, $end, {'force' => 'middle_top'} );
    $editor->cursor->set( $end, $line );
    $editor->focus;
    $editor->visual_search( $regexp, $line, $end);
}

sub close {
    my ( $self ) = @_;
    
    print "Dans key close, avant kill\n";
    
    $self->kill;
}


=head1 FUNCTIONS

=head2 backspace

=head2 close

Should behave like a standard file close.

=head2 copy

Copy the selected text to the clipboard.

=head2 copy_line

=head2 cut_line

=head2 delete_start_selection_point

Delete from memory the start point of the selected text.

=head2 display_cursor_display

=head2 down

=head2 end

=head2 end_file

=head2 enter_search

Action to be done when the user press enter for the first time in the macro panel after a ctrl-f sequence (the search expression have been set, the cursor will be sent to the first found position).

=head2 f3_search

Next search and new cursor position change.

=head2 home

=head2 inser

=head2 jump_down

=head2 jump_left

=head2 jump_right

=head2 jump_up

=head2 left

=head2 list_display_positions

=head2 move_down

=head2 move_up

=head2 new_a

=head2 page_down

=head2 page_up

=head2 paste

=head2 print_screen_number

=head2 query_segments

=head2 right

=head2 save



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