feat: delete_line implemented
This commit is contained in:
		
							parent
							
								
									e76c47e1a6
								
							
						
					
					
						commit
						04c1ece3a8
					
				
					 1 changed files with 15 additions and 3 deletions
				
			
		|  | @ -2406,7 +2406,7 @@ pub const Editor = struct { | ||||||
|         primary.disable_selection(root, self.metrics); |         primary.disable_selection(root, self.metrics); | ||||||
|         self.selection_mode = .line; |         self.selection_mode = .line; | ||||||
|         primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return; |         primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return; | ||||||
|         try self.select_line_at_cursor(primary); |         try self.select_line_at_cursor(root, primary, false); | ||||||
|         self.selection_drag_initial = primary.selection; |         self.selection_drag_initial = primary.selection; | ||||||
|         self.clamp_mouse(); |         self.clamp_mouse(); | ||||||
|     } |     } | ||||||
|  | @ -3031,6 +3031,16 @@ pub const Editor = struct { | ||||||
|     } |     } | ||||||
|     pub const delete_to_end_meta: Meta = .{ .description = "Delete to end of line" }; |     pub const delete_to_end_meta: Meta = .{ .description = "Delete to end of line" }; | ||||||
| 
 | 
 | ||||||
|  |     pub fn delete_line(self: *Self, _: Context) Result { | ||||||
|  |         const b = try self.buf_for_update(); | ||||||
|  |         const primary = self.get_primary(); | ||||||
|  |         try self.select_line_at_cursor(b.root, primary, true); | ||||||
|  |         const root = try self.delete_selection(b.root, primary, b.allocator); | ||||||
|  |         try self.update_buf(root); | ||||||
|  |         self.clamp(); | ||||||
|  |     } | ||||||
|  |     pub const delete_line_meta: Meta = .{ .description = "Delete current line" }; | ||||||
|  | 
 | ||||||
|     pub fn cut_to_end_vim(self: *Self, _: Context) Result { |     pub fn cut_to_end_vim(self: *Self, _: Context) Result { | ||||||
|         const b = try self.buf_for_update(); |         const b = try self.buf_for_update(); | ||||||
|         const root = try self.cut_to(move_cursor_end_vim, b.root); |         const root = try self.cut_to(move_cursor_end_vim, b.root); | ||||||
|  | @ -4102,12 +4112,14 @@ pub const Editor = struct { | ||||||
|         return sel; |         return sel; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn select_line_at_cursor(self: *Self, cursel: *CurSel) !void { |     fn select_line_at_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, include_newline: bool) !void { | ||||||
|         const root = try self.buf_root(); |  | ||||||
|         const sel = try cursel.enable_selection(root, self.metrics); |         const sel = try cursel.enable_selection(root, self.metrics); | ||||||
|         sel.normalize(); |         sel.normalize(); | ||||||
|         try move_cursor_begin(root, &sel.begin, self.metrics); |         try move_cursor_begin(root, &sel.begin, self.metrics); | ||||||
|         move_cursor_end(root, &sel.end, self.metrics) catch {}; |         move_cursor_end(root, &sel.end, self.metrics) catch {}; | ||||||
|  |         if (include_newline) { | ||||||
|  |             move_cursor_right(root, &sel.end, self.metrics) catch {}; // catch{} because may be impossible to get eol (e.g., we're at eof) | ||||||
|  |         } | ||||||
|         cursel.cursor = sel.end; |         cursel.cursor = sel.end; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 jmcaine
						jmcaine