Commits

Herbert Breunung committed 4cb2e81

vertical movement works for nonewords, disambiguation needs some new techique

Comments (0)

Files changed (1)

lib/Kephra/Edit.pm

 sub move_sel_or_word {
 	my ($self, $movement) = @_;
 	my ($start, $end) = $self->GetSelection;
-	Kephra::API::log("$start, $end", 1);
+	return if $start == 0 and $movement < 0;
+	return if $end == $self->GetLength and $movement > 0;
+	my $move_wordwise;
+	$self->BeginUndoAction;
+	if ($start == $end) {
+		my $pos = $start;
+		$start = $self->WordStartPosition($pos, 1);
+		$end = $self->WordEndPosition($pos, 1);
+		$self->SetSelection($start, $end);
+		$move_wordwise = 1;
+	} else { # check if word is selected
+		$move_wordwise = 1 if $start == $self->WordStartPosition($start, 1)
+							and $end == $self->WordEndPosition($end, 1);
+	}
+	my $selection = $self->GetSelectedText;
+	$self->ReplaceSelection('');
+	if ($move_wordwise){
+		
+	} else {
+		my $line = $self->LineFromPosition($start);
+		my $pos;
+		if ($start == $self->PositionFromLine($line) and $movement == -1){ 
+			$pos = $self->GetLineEndPosition( $line-1 );
+		}
+		elsif ($start == $self->GetLineEndPosition($line) 
+		and $self->GetLineCount-1 > $line and $movement == 1){
+			$pos = $self->PositionFromLine( $line+1 );
+		}
+		else { $pos = $start + $movement }
+		$self->InsertText( $pos, $selection);
+		$self->SetSelection( $pos, $pos + length($selection) );
+	}
+	$self->EndUndoAction;
+	#Kephra::API::log("$start, $end", 1);
 }
 sub move_sel_or_line_up      { $_[0]->move_sel_or_line(-1) }
 sub move_sel_or_line_down    { $_[0]->move_sel_or_line(+1) }