feat: simplify the implementation of switch_case and add a flow mode keybind
This commit is contained in:
		
							parent
							
								
									9c448b14e5
								
							
						
					
					
						commit
						252ad3c269
					
				
					 4 changed files with 10 additions and 21 deletions
				
			
		|  | @ -210,7 +210,6 @@ pub fn build(b: *std.Build) void { | ||||||
|             .{ .name = "diff", .module = diff_mod }, |             .{ .name = "diff", .module = diff_mod }, | ||||||
|             .{ .name = "help.md", .module = help_mod }, |             .{ .name = "help.md", .module = help_mod }, | ||||||
|             .{ .name = "CaseData", .module = zg_dep.module("CaseData") }, |             .{ .name = "CaseData", .module = zg_dep.module("CaseData") }, | ||||||
|             .{ .name = "code_point", .module = zg_dep.module("code_point") }, |  | ||||||
|             .{ .name = "fuzzig", .module = fuzzig_dep.module("fuzzig") }, |             .{ .name = "fuzzig", .module = fuzzig_dep.module("fuzzig") }, | ||||||
|             .{ .name = "zeit", .module = zeit_mod }, |             .{ .name = "zeit", .module = zeit_mod }, | ||||||
|         }, |         }, | ||||||
|  |  | ||||||
|  | @ -10,7 +10,6 @@ const text_manip = @import("text_manip"); | ||||||
| const syntax = @import("syntax"); | const syntax = @import("syntax"); | ||||||
| const project_manager = @import("project_manager"); | const project_manager = @import("project_manager"); | ||||||
| const CaseData = @import("CaseData"); | const CaseData = @import("CaseData"); | ||||||
| const code_point = @import("code_point"); |  | ||||||
| const root_mod = @import("root"); | const root_mod = @import("root"); | ||||||
| 
 | 
 | ||||||
| const Plane = @import("renderer").Plane; | const Plane = @import("renderer").Plane; | ||||||
|  | @ -3927,10 +3926,11 @@ pub const Editor = struct { | ||||||
| 
 | 
 | ||||||
|     fn switch_case_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { |     fn switch_case_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { | ||||||
|         var root = root_; |         var root = root_; | ||||||
|         const saved = cursel.*; |         var saved = cursel.*; | ||||||
|         const sel = if (cursel.selection) |*sel| sel else ret: { |         const sel = if (cursel.selection) |*sel| sel else ret: { | ||||||
|             var sel = cursel.enable_selection(); |             var sel = cursel.enable_selection(); | ||||||
|             move_cursor_right(root, &sel.begin, self.metrics) catch return error.Stop; |             move_cursor_right(root, &sel.end, self.metrics) catch return error.Stop; | ||||||
|  |             saved.cursor = sel.end; | ||||||
|             break :ret sel; |             break :ret sel; | ||||||
|         }; |         }; | ||||||
|         var sfa = std.heap.stackFallback(4096, self.allocator); |         var sfa = std.heap.stackFallback(4096, self.allocator); | ||||||
|  | @ -3938,21 +3938,10 @@ pub const Editor = struct { | ||||||
|         defer allocator.free(cut_text); |         defer allocator.free(cut_text); | ||||||
|         const cd = CaseData.init(allocator) catch return error.Stop; |         const cd = CaseData.init(allocator) catch return error.Stop; | ||||||
|         defer cd.deinit(); |         defer cd.deinit(); | ||||||
|         const flipped = blk: { |         const flipped = (if (cd.isLowerStr(cut_text)) | ||||||
|             var bytes = std.ArrayList(u8).initCapacity(allocator, cut_text.len) catch return error.Stop; |             cd.toUpperStr(allocator, cut_text) | ||||||
|             defer bytes.deinit(); |         else | ||||||
| 
 |             cd.toLowerStr(allocator, cut_text)) catch return error.Stop; | ||||||
|             var iter = code_point.Iterator{ .bytes = cut_text }; |  | ||||||
|             var buf: [4]u8 = undefined; |  | ||||||
| 
 |  | ||||||
|             while (iter.next()) |cp| { |  | ||||||
|                 const code = if (cd.isLower(cp.code)) cd.toUpper(cp.code) else cd.toLower(cp.code); |  | ||||||
|                 const len = std.unicode.utf8Encode(code, &buf) catch return error.Stop; |  | ||||||
|                 bytes.appendSliceAssumeCapacity(buf[0..len]); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             break :blk bytes.toOwnedSlice() catch return error.Stop; |  | ||||||
|         }; |  | ||||||
|         defer allocator.free(flipped); |         defer allocator.free(flipped); | ||||||
|         root = try self.delete_selection(root, cursel, allocator); |         root = try self.delete_selection(root, cursel, allocator); | ||||||
|         root = self.insert(root, cursel, flipped, allocator) catch return error.Stop; |         root = self.insert(root, cursel, flipped, allocator) catch return error.Stop; | ||||||
|  | @ -3966,7 +3955,7 @@ pub const Editor = struct { | ||||||
|         try self.update_buf(root); |         try self.update_buf(root); | ||||||
|         self.clamp(); |         self.clamp(); | ||||||
|     } |     } | ||||||
|     pub const switch_case_meta = .{ .description = "Switch the casing of selection or cell" }; |     pub const switch_case_meta = .{ .description = "Switch the case of selection or character at cursor" }; | ||||||
| 
 | 
 | ||||||
|     pub fn toggle_eol_mode(self: *Self, _: Context) Result { |     pub fn toggle_eol_mode(self: *Self, _: Context) Result { | ||||||
|         if (self.buffer) |b| { |         if (self.buffer) |b| { | ||||||
|  |  | ||||||
|  | @ -148,6 +148,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { | ||||||
|             'P' => self.cmd("goto_prev_file_or_diagnostic", .{}), |             'P' => self.cmd("goto_prev_file_or_diagnostic", .{}), | ||||||
|             'U' => self.cmd("to_upper", .{}), |             'U' => self.cmd("to_upper", .{}), | ||||||
|             'L' => self.cmd("to_lower", .{}), |             'L' => self.cmd("to_lower", .{}), | ||||||
|  |             'C' => self.cmd("switch_case", .{}), | ||||||
|             'I' => self.cmd("toggle_inputview", .{}), |             'I' => self.cmd("toggle_inputview", .{}), | ||||||
|             'B' => self.cmd("move_word_left", .{}), |             'B' => self.cmd("move_word_left", .{}), | ||||||
|             'F' => self.cmd("move_word_right", .{}), |             'F' => self.cmd("move_word_right", .{}), | ||||||
|  |  | ||||||
|  | @ -212,7 +212,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { | ||||||
|             'o' => self.seq(.{ "smart_insert_line_before", "enter_mode" }, command.fmt(.{"vim/insert"})), |             'o' => self.seq(.{ "smart_insert_line_before", "enter_mode" }, command.fmt(.{"vim/insert"})), | ||||||
|             'k' => self.cmd("hover", .{}), |             'k' => self.cmd("hover", .{}), | ||||||
| 
 | 
 | ||||||
|             '`' => self.seq(.{ "switch_case", "move_right_vim" }, .{}), |             '`' => self.cmd("switch_case", .{}), | ||||||
|             else => {}, |             else => {}, | ||||||
|         }, |         }, | ||||||
|         0 => switch (keypress) { |         0 => switch (keypress) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue