Kephra / lib / Kephra / Edit / Search.pm

use strict;
use warnings;
use Kephra::API;

#package Kephra::Edit::Search;
package Kephra::App::Editor;

Kephra::API::Command::register({
 'edit-goto-char-left'   =>{sub=>'$ed->CharLeft',          label=>'Char Left',    keys=>'left' },
 'edit-goto-char-right'  =>{sub=>'$ed->CharRight',         label=>'Char Right',   keys=>'right' },
 'edit-select-char-left' =>{sub=>'$ed->CharLeftExtend',    label=>'Select Left',  keys=>'shift+left' },
 'edit-select-char-right'=>{sub=>'$ed->CharRightExtend',   label=>'Select Right', keys=>'shift+right' },
 'edit-goto-word-left'   =>{sub=>'$ed->WordLeft',          label=>'Word Left',    keys=>'ctrl+left' },
 'edit-goto-word-right'  =>{sub=>'$ed->WordRight',         label=>'Word Right',   keys=>'ctrl+right' },
 'edit-select-word-left' =>{sub=>'$ed->WordLeftExtend',    label=>'Word Left',    keys=>'ctrl+shift+left' },
 'edit-select-word-right'=>{sub=>'$ed->WordRightExtend',   label=>'Word Right',   keys=>'ctrl+shift+right' },
 'edit-goto-line-start'  =>{sub=>'$ed->Home',              label=>'Line Start',   keys=>'home'},
 'edit-goto-line-end'    =>{sub=>'$ed->LineEnd',           label=>'Line End',     keys=>'end' },
 'edit-select-line-start'=>{sub=>'$ed->HomeExtend',        label=>'Line Start',   keys=>'shift+home'},
 'edit-select-line-end'  =>{sub=>'$ed->LineEndExtend',     label=>'Line End',     keys=>'shift+end' },
 #'edit-goto-line-up'     =>{sub=>'$ed->LineUp',            label=>'Line Up',     keys =>'up' },
 #'edit-goto-line-down'   =>{sub=>'$ed->LineDown',          label=>'Line Down',   keys =>'down' },
 'edit-select-line-up'   =>{sub=>'$ed->LineUpExtend',      label=>'Line Up',      keys=>'shift+up' },
 'edit-select-line-down' =>{sub=>'$ed->LineDownExtend',    label=>'Line Down',    keys=>'shift+down' },
 'edit-goto-page-up'     =>{sub=>'$ed->PageUp',            label=>'Page Up',      keys=>'pageup' },
 'edit-goto-page-down'   =>{sub=>'$ed->PageDown',          label=>'Page Down',    keys=>'pagedown' },
 'edit-select-page-up'   =>{sub=>'$ed->PageUpExtend',      label=>'Page Up',      keys=>'shift+pageup' },
 'edit-select-page-down' =>{sub=>'$ed->PageDownExtend',    label=>'Page Down',    keys=>'shift+pagedown'},
 'edit-goto-doc-start'   =>{sub=>'$ed->DocumentStart',     label=>'Doc Start',    keys=>'ctrl+home'},
 'edit-goto-doc-end'     =>{sub=>'$ed->DocumentEnd',       label=>'Doc End',      keys=>'ctrl+end' },
 'edit-select-doc-start' =>{sub=>'$ed->DocumentStartExtend',label=>'Doc Start',   keys=>'ctrl+shift+home'},
 'edit-select-doc-end'   =>{sub=>'$ed->DocumentEndExtend', label=>'Doc End',      keys=>'ctrl+shift+end' },
 'edit-select-doc'       =>{sub=>'$ed->SelectAll',         label=>'All',          keys=>'ctrl+a' },
 'edit-goto-last-change' =>{sub=>'$ed->goto_last_change',  label=>'Last Change',  keys=>'ctrl+shift+g'},
 'edit-find-next-comment'=>{sub=>'$ed->next_comment',      label=>'Next Comment', keys=>'ctrl+#' },
 'edit-find-prev-comment'=>{sub=>'$ed->prev_comment',      label=>'Prev Comment', keys=>'ctrl+shift+#' },
});


#F3            $self->find_next
#F3+shift      $self->find_prev
#F3+ctrl       $self->search_for_selection
#F3+shift+ctrl $self->replace_with_selection
#F3+alt        $self->replace_next
#F3+shift+alt  $self->replace_prev

sub goto_last_change {
	my ($self) = @_;
	$self->GotoPos( $self->{'change_pos'} ) if exists $self->{'change_pos'};
}

sub prev_comment {
	my ($self) = @_;
	my ($start, $end) = $self->GetSelection;
	$self->GotoPos( $start );
	$self->SearchAnchor();
	my $found = $self->SearchPrev(0, '#');
	if( $found == -1) {
		$self->GotoPos( $self->GetLength );
		$self->SearchAnchor();
		$found = $self->SearchPrev(0, '#') 
	}
	$self->GotoPos( $found != -1 ? $found : $start );
}
sub next_comment {
	my ($self) = @_;
	my ($start, $end) = $self->GetSelection;
	$self->GotoPos( $start + 1 );
	$self->SearchAnchor();
	my $found = $self->SearchNext(0, '#');
	if( $found == -1) {
		$self->GotoPos( 0 );
		$self->SearchAnchor();
		$found = $self->SearchNext(0, '#') 
	}
	$self->GotoPos( $found != -1 ? $found : $start );
}

sub search_for_selection {} 
sub replace_with_selection {} 
sub find_next {}
sub find_prev {} 
sub replace_next {}
sub replace_prev {}


1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.