Commits

Herbert Breunung  committed b11e339

added commenting and comment navigation

  • Participants
  • Parent commits 9934dcd

Comments (0)

Files changed (2)

File lib/Kephra/App/Editor.pm

 		elsif ($key ==  &Wx::WXK_F11)          {Kephra::API::widget('win')->toggle_fullscreen() } 
 		elsif ($key ==  &Wx::WXK_ESCAPE)       {Kephra::App::Panel::IOUnit::focus_on_input() } 
 		elsif ($key ==  &Wx::WXK_TAB    + 2000){ } # rotate focus
+		elsif ($key ==      ord('#')    + 2000){$self->next_comment() }
+		elsif ($key ==      ord('#')    + 3000){$self->prev_comment() }
+		elsif ($key ==      ord('#')    + 4000){$self->comment() }
+		elsif ($key ==      ord('#')    + 5000){$self->decomment() }
 		elsif ($key ==      ord('G')    + 3000){$self->goto_last_edit() } # last selection?
 		elsif ($key ==      ord('G')    + 5000){$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() }
 		elsif ($key ==      ord('Q')    + 4000){Kephra::API::app()->close_save }
 		elsif ($key ==      ord('Z')    + 3000){$self->redo() }

File lib/Kephra/Edit.pm

 	}
 	my $selection = $self->GetSelectedText;
 	$self->ReplaceSelection('');
-	if ($move_wordwise){
+	if ($move_wordwise) {
+		
+		$self->InsertText( $start, $selection);
 		
 	} else {
 		my $line = $self->LineFromPosition($start);
 	}
 }
 
-sub comment {}
-sub decomment {}
+sub comment {
+	my ($self) = @_;
+	my ($start, $end) = $self->GetSelection;
+	my $line_sel = [ $self->LineFromPosition($start), $self->LineFromPosition($end) ];
+
+	$self->BeginUndoAction;
+	for ($line_sel->[0] .. $line_sel->[1]) {
+		my $ipos = $self->GetLineIndentPosition($_);
+		next if $ipos == $self->GetLineEndPosition($_);
+		$self->InsertText($ipos, '#') unless $self->GetCharAt( $ipos ) == ord '#';
+	}
+	$self->SetSelection( 
+		$self->PositionFromLine(  $line_sel->[0] ),
+		$self->GetLineEndPosition($line_sel->[1] )
+	);
+	$self->EndUndoAction;
+}
+sub decomment {
+	my ($self) = @_;
+	my ($start, $end) = $self->GetSelection;
+	my $line_sel = [ $self->LineFromPosition($start), $self->LineFromPosition($end) ];
+
+	$self->BeginUndoAction;
+	for ($line_sel->[0] .. $line_sel->[1]) {
+		my $ipos = $self->GetLineIndentPosition($_);
+		if ($self->GetCharAt( $ipos ) eq ord '#') {
+			$self->SetTargetStart($ipos);
+			$self->SetTargetEnd($ipos+1);
+			$self->ReplaceTarget('');
+		}
+	}
+	$self->SetSelection( 
+		$self->PositionFromLine(  $line_sel->[0] ),
+		$self->GetLineEndPosition($line_sel->[1] )
+	);
+	$self->EndUndoAction;
+}
 sub toggle_comment {}
+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 goto_last_edit{}
 sub redo { $_[0]->Redo }