Commits

Herbert Breunung committed 8637852

got move selection finally right

  • Participants
  • Parent commits a3b1447

Comments (0)

Files changed (3)

File lib/Kephra.pm

 
 package Kephra;
 our $NAME     = __PACKAGE__;    # name of entire application
-our $VERSION  = '0.5.0.6';      # version of ..
+our $VERSION  = '0.4.5.6';      # version of ..
 
 our @external_dependencies = (
 	qw/Benchmark Encode Encode::Guess Cwd/,

File lib/Kephra/App/Editor.pm

 		my ($ed, $event) = @_;
 		my $key = Kephra::App::Util::keycode_from_event($event);
 		Kephra::App::Panel::IOUnit::output('log',"pressed key $key");
-		if    ($key ==  &Wx::WXK_LEFT  + 4000){$self->dedent() }
-		if    ($key ==  &Wx::WXK_RIGHT + 4000){$self->indent() }
-		elsif ($key ==  &Wx::WXK_UP    + 2000){$self->ParaUp() }
-		elsif ($key ==  &Wx::WXK_UP    + 3000){$self->ParaUpExtend() }
-		elsif ($key ==  &Wx::WXK_UP    + 4000){$self->move_sel_or_line_up() }
-		elsif ($key ==  &Wx::WXK_DOWN  + 2000){$self->ParaDown() }
-		elsif ($key ==  &Wx::WXK_DOWN  + 3000){$self->ParaDownExtend() }
-		elsif ($key ==  &Wx::WXK_DOWN  + 4000){$self->move_sel_or_line_down() }
+		if    ($key ==  &Wx::WXK_LEFT   + 4000){$self->dedent_level() }
+		elsif ($key ==  &Wx::WXK_LEFT   + 5000){$self->move_sel_or_word_left() }
+		elsif ($key ==  &Wx::WXK_RIGHT  + 4000){$self->indent_level() }
+		elsif ($key ==  &Wx::WXK_RIGHT  + 5000){$self->move_sel_or_word_right() }
+		elsif ($key ==  &Wx::WXK_UP     + 2000){$self->ParaUp() }
+		elsif ($key ==  &Wx::WXK_UP     + 3000){$self->ParaUpExtend() }
+		elsif ($key ==  &Wx::WXK_UP     + 4000){$self->move_sel_or_line_up() }
+		elsif ($key ==  &Wx::WXK_DOWN   + 2000){$self->ParaDown() }
+		elsif ($key ==  &Wx::WXK_DOWN   + 3000){$self->ParaDownExtend() }
+		elsif ($key ==  &Wx::WXK_DOWN   + 4000){$self->move_sel_or_line_down() }
 		elsif ($key ==  &Wx::WXK_PAGEUP + 2000){Kephra::App::Panel::Editor::select_tab_left()}
 		elsif ($key ==  &Wx::WXK_PAGEUP + 3000){Kephra::App::Panel::Editor::select_tab_leftmost()  }
 		elsif ($key ==  &Wx::WXK_PAGEUP + 4000){Kephra::App::Panel::Editor::move_tab_left()  }
 		elsif ($key ==  &Wx::WXK_PAGEDOWN+3000){Kephra::App::Panel::Editor::select_tab_rightmost()}
 		elsif ($key ==  &Wx::WXK_PAGEDOWN+4000){Kephra::App::Panel::Editor::move_tab_right()}
 		elsif ($key ==  &Wx::WXK_PAGEDOWN+5000){Kephra::App::Panel::Editor::move_tab_rightmost()}
+		elsif ($key ==  &Wx::WXK_HOME    +4000){ }
+		elsif ($key ==  &Wx::WXK_END     +4000){ }
 		elsif ($key ==  &Wx::WXK_F2)           {Kephra::App::Panel::FileBrowser::focus() } 
 		elsif ($key ==  &Wx::WXK_F11)          {Kephra::API::widget('win')->toggle_fullscreen() } 
-		elsif ($key ==  &Wx::WXK_ESCAPE)       { } 
+		elsif ($key ==  &Wx::WXK_ESCAPE)       {Kephra::App::Panel::IOUnit::focus() } 
 		elsif ($key ==  &Wx::WXK_TAB     +2000){Kephra::App::Panel::IOUnit::focus() }
+		elsif ($key ==  ord('G') + 3000)       {$self->goto_last_edit() }
 		elsif ($key ==  ord('K') + 2000)       {$self->comment() }
 		elsif ($key ==  ord('K') + 3000)       {$self->decomment() }
 		elsif ($key ==  ord('Q') + 2000)       {Kephra::File::close_active() }

File lib/Kephra/Edit.pm

 #package Kephra::Edit;
 package Kephra::App::Editor;
 
-sub move_sel_or_line_up   { $_[0]->move_sel_or_line(-1) }
-sub move_sel_or_line_down { $_[0]->move_sel_or_line(+1) }
+
+sub move_sel_or_word_left {
+}
+sub move_sel_or_word_right {
+}
+sub move_sel_or_line_up      { $_[0]->move_sel_or_line(-1) }
+sub move_sel_or_line_down    { $_[0]->move_sel_or_line(+1) }
 sub move_sel_or_line {
 	my ($self, $movement) = @_;
 	my ($start, $end) = $self->GetSelection;
 	my $line_sel = [ $self->LineFromPosition($start), $self->LineFromPosition($end) ];
 	my $last_line = $self->LineFromPosition( $self->GetLength );
-	$last_line-- if $self->PositionFromLine($last_line) == $self->GetLineEndPosition($last_line);
+	return if $line_sel->[0] == 0 and $movement < 0;
+#print "before move:$movement ",,"  mode: \n"; 
+	# move inside document borders
 	$movement = $line_sel->[0]              
 		if $movement < 0 and $line_sel->[0]+$movement < 0;
 	$movement = $last_line - $line_sel->[1]
 		if $movement > 0 and $line_sel->[1]+$movement > $last_line;
-	my $pos = $self->GetCurrentPos();
-	my $col = $self->GetColumn($pos);
 
 	$self->BeginUndoAction;
-	$self->SetSelection( 
-		$self->PositionFromLine($line_sel->[0]),
-		$self->PositionFromLine($line_sel->[1] + 1 )
-	);
-	my $selection = $self->GetSelectedText;
-	$self->DeleteBack();
-	$self->InsertText( $self->PositionFromLine($line_sel->[0] + $movement), $selection);
-
-	# keep selection on moving block or keep caret position in moving line
-	if ($start != $end){
+	if ($start != $end){     # move selection
+		$self->SetSelection( 
+			$self->PositionFromLine(  $line_sel->[0] ),
+			$self->GetLineEndPosition($line_sel->[1] )
+		);
+		my $selection = $self->GetSelectedText;
+		$self->ReplaceSelection('');
+		$self->GotoPos(1) if $self->GetCurrentPos == 0;
+		$self->DeleteBack() if $selection;
+		my $destination_line = $line_sel->[0] + $movement;
+		my $pos = $self->PositionFromLine( $destination_line );
+		$self->GotoPos($pos);
+		$self->NewLine;
+		$pos++ if $self->LineFromPosition( $self->GetLength ) <= $destination_line;
+		$self->GotoPos($pos);
+		$self->InsertText( $pos, $selection);
 		$self->select_whole_lines( $line_sel->[0]+$movement, $line_sel->[1]+$movement );
-	} else {
-		$pos = $self->PositionFromLine ($line_sel->[0] + $movement) + $col;
+	} else {                  # move one line
+		my $col = $self->GetColumn($self->GetCurrentPos());
+		if ($movement < 0){   # up
+			my $line = $line_sel->[0];
+			$self->GotoLine($line--), $self->LineTranspose for 1..abs $movement;
+		} else {              # down
+			my $line = $line_sel->[0]+1;
+			$self->GotoLine($line++), $self->LineTranspose for 1..    $movement;
+		}
+		my $pos = $self->PositionFromLine ($line_sel->[0] + $movement) + $col;
 		$self->SetSelection( $pos, $pos );
 	}
 	$self->EndUndoAction;
 	);
 }
 
-sub indent { $_[0]->dent(+1) }
-sub dedent { $_[0]->dent(-1) }
-sub   dent {
+sub indent_level { $_[0]->dent_level(+1) }
+sub dedent_level { $_[0]->dent_level(-1) }
+sub   dent_level {
 	my ($self, $change, $lines) = @_;
 	my ($start, $end) = $self->GetSelection;
 	if ($start != $end){
 sub decomment {}
 sub toggle_comment {}
 
+sub goto_last_edit{}
+
 1;