Merge branch 'master' into zig-0.14
This commit is contained in:
		
						commit
						a959563bc7
					
				
					 11 changed files with 253 additions and 75 deletions
				
			
		| 
						 | 
				
			
			@ -2774,6 +2774,49 @@ pub const Editor = struct {
 | 
			
		|||
    }
 | 
			
		||||
    pub const delete_backward_meta: Meta = .{ .description = "Delete previous character" };
 | 
			
		||||
 | 
			
		||||
    pub fn smart_delete_backward(self: *Self, _: Context) Result {
 | 
			
		||||
        const b = try self.buf_for_update();
 | 
			
		||||
        var all_stop = true;
 | 
			
		||||
        var root = b.root;
 | 
			
		||||
 | 
			
		||||
        for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
 | 
			
		||||
            if (cursel.selection) |_| {
 | 
			
		||||
                root = self.delete_selection(root, cursel, b.allocator) catch continue;
 | 
			
		||||
                all_stop = false;
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            with_selection_const(root, move_cursor_left, cursel, self.metrics) catch continue;
 | 
			
		||||
 | 
			
		||||
            if (cursel.selection) |*sel| {
 | 
			
		||||
                const egc_left, _, _ = sel.end.egc_at(root, self.metrics) catch {
 | 
			
		||||
                    root = self.delete_selection(root, cursel, b.allocator) catch continue;
 | 
			
		||||
                    all_stop = false;
 | 
			
		||||
                    continue;
 | 
			
		||||
                };
 | 
			
		||||
                const egc_right, _, _ = sel.begin.egc_at(root, self.metrics) catch {
 | 
			
		||||
                    root = self.delete_selection(root, cursel, b.allocator) catch continue;
 | 
			
		||||
                    all_stop = false;
 | 
			
		||||
                    continue;
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
                for (Buffer.unicode.char_pairs) |pair| if (std.mem.eql(u8, egc_left, pair[0]) and std.mem.eql(u8, egc_right, pair[1])) {
 | 
			
		||||
                    sel.begin.move_right(root, self.metrics) catch {};
 | 
			
		||||
                    break;
 | 
			
		||||
                };
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            root = self.delete_selection(root, cursel, b.allocator) catch continue;
 | 
			
		||||
            all_stop = false;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        if (all_stop)
 | 
			
		||||
            return error.Stop;
 | 
			
		||||
 | 
			
		||||
        try self.update_buf(root);
 | 
			
		||||
        self.clamp();
 | 
			
		||||
    }
 | 
			
		||||
    pub const smart_delete_backward_meta = .{ .description = "Delete previous character (smart)" };
 | 
			
		||||
 | 
			
		||||
    pub fn delete_word_left(self: *Self, _: Context) Result {
 | 
			
		||||
        const b = try self.buf_for_update();
 | 
			
		||||
        const root = try self.delete_to(move_cursor_word_left_space, b.root, b.allocator);
 | 
			
		||||
| 
						 | 
				
			
			@ -2995,7 +3038,7 @@ pub const Editor = struct {
 | 
			
		|||
            return error.Stop;
 | 
			
		||||
        try move_cursor_left(root, cursor, metrics);
 | 
			
		||||
        while (true) {
 | 
			
		||||
            const curr_egc, _, _ = root.ecg_at(cursor.row, cursor.col, metrics) catch return error.Stop;
 | 
			
		||||
            const curr_egc, _, _ = root.egc_at(cursor.row, cursor.col, metrics) catch return error.Stop;
 | 
			
		||||
            if (std.mem.eql(u8, curr_egc, egc))
 | 
			
		||||
                return;
 | 
			
		||||
            if (is_eol_left(root, cursor, metrics))
 | 
			
		||||
| 
						 | 
				
			
			@ -3010,7 +3053,7 @@ pub const Editor = struct {
 | 
			
		|||
            return error.Stop;
 | 
			
		||||
        try move_cursor_right(root, cursor, metrics);
 | 
			
		||||
        while (true) {
 | 
			
		||||
            const curr_egc, _, _ = root.ecg_at(cursor.row, cursor.col, metrics) catch return error.Stop;
 | 
			
		||||
            const curr_egc, _, _ = root.egc_at(cursor.row, cursor.col, metrics) catch return error.Stop;
 | 
			
		||||
            if (std.mem.eql(u8, curr_egc, egc))
 | 
			
		||||
                return;
 | 
			
		||||
            if (is_eol_right(root, cursor, metrics))
 | 
			
		||||
| 
						 | 
				
			
			@ -4070,6 +4113,7 @@ pub const Editor = struct {
 | 
			
		|||
        if (!try ctx.args.match(.{ tp.extract(&chars_left), tp.extract(&chars_right) }))
 | 
			
		||||
            return error.InvalidSmartInsertPairArguments;
 | 
			
		||||
        const b = try self.buf_for_update();
 | 
			
		||||
        var move: enum { left, right } = .left;
 | 
			
		||||
        var root = b.root;
 | 
			
		||||
        for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
 | 
			
		||||
            if (cursel.selection) |*sel| {
 | 
			
		||||
| 
						 | 
				
			
			@ -4078,16 +4122,60 @@ pub const Editor = struct {
 | 
			
		|||
                var end: CurSel = .{ .cursor = sel.end };
 | 
			
		||||
                root = try self.insert(root, &end, chars_right, b.allocator);
 | 
			
		||||
                sel.end.move_left(root, self.metrics) catch {};
 | 
			
		||||
            } else {
 | 
			
		||||
                root = try self.insert(root, cursel, chars_left, b.allocator);
 | 
			
		||||
                root = try self.insert(root, cursel, chars_right, b.allocator);
 | 
			
		||||
            } else blk: {
 | 
			
		||||
                const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
 | 
			
		||||
                    root = try self.insert(root, cursel, chars_left, b.allocator);
 | 
			
		||||
                    root = try self.insert(root, cursel, chars_right, b.allocator);
 | 
			
		||||
                    break :blk;
 | 
			
		||||
                };
 | 
			
		||||
                if (std.mem.eql(u8, egc, chars_left)) {
 | 
			
		||||
                    move = .right;
 | 
			
		||||
                } else {
 | 
			
		||||
                    root = try self.insert(root, cursel, chars_left, b.allocator);
 | 
			
		||||
                    root = try self.insert(root, cursel, chars_right, b.allocator);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            switch (move) {
 | 
			
		||||
                .left => cursel.cursor.move_left(root, self.metrics) catch {},
 | 
			
		||||
                .right => cursel.cursor.move_right(root, self.metrics) catch {},
 | 
			
		||||
            }
 | 
			
		||||
            cursel.cursor.move_left(root, self.metrics) catch {};
 | 
			
		||||
        };
 | 
			
		||||
        try self.update_buf(root);
 | 
			
		||||
        self.clamp();
 | 
			
		||||
    }
 | 
			
		||||
    pub const smart_insert_pair_meta: Meta = .{ .arguments = &.{.string} };
 | 
			
		||||
    pub const smart_insert_pair_meta: Meta = .{ .arguments = &.{ .string, .string } };
 | 
			
		||||
 | 
			
		||||
    pub fn smart_insert_pair_close(self: *Self, ctx: Context) Result {
 | 
			
		||||
        var chars_left: []const u8 = undefined;
 | 
			
		||||
        var chars_right: []const u8 = undefined;
 | 
			
		||||
        if (!try ctx.args.match(.{ tp.extract(&chars_left), tp.extract(&chars_right) }))
 | 
			
		||||
            return error.InvalidSmartInsertPairArguments;
 | 
			
		||||
        const b = try self.buf_for_update();
 | 
			
		||||
        var root = b.root;
 | 
			
		||||
        for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
 | 
			
		||||
            if (cursel.selection) |*sel| {
 | 
			
		||||
                var begin: CurSel = .{ .cursor = sel.begin };
 | 
			
		||||
                root = try self.insert(root, &begin, chars_left, b.allocator);
 | 
			
		||||
                var end: CurSel = .{ .cursor = sel.end };
 | 
			
		||||
                root = try self.insert(root, &end, chars_right, b.allocator);
 | 
			
		||||
                sel.begin.move_left(root, self.metrics) catch {};
 | 
			
		||||
                cursel.disable_selection(root, self.metrics);
 | 
			
		||||
            } else blk: {
 | 
			
		||||
                const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
 | 
			
		||||
                    root = try self.insert(root, cursel, chars_right, b.allocator);
 | 
			
		||||
                    break :blk;
 | 
			
		||||
                };
 | 
			
		||||
                if (std.mem.eql(u8, egc, chars_right)) {
 | 
			
		||||
                    cursel.cursor.move_right(root, self.metrics) catch {};
 | 
			
		||||
                } else {
 | 
			
		||||
                    root = try self.insert(root, cursel, chars_right, b.allocator);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        try self.update_buf(root);
 | 
			
		||||
        self.clamp();
 | 
			
		||||
    }
 | 
			
		||||
    pub const smart_insert_pair_close_meta = .{ .arguments = &.{ .string, .string } };
 | 
			
		||||
 | 
			
		||||
    pub fn enable_fast_scroll(self: *Self, _: Context) Result {
 | 
			
		||||
        self.fast_scroll = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -359,7 +359,7 @@ const cmds = struct {
 | 
			
		|||
        const same_file = if (self.get_active_file_path()) |fp| std.mem.eql(u8, fp, f) else false;
 | 
			
		||||
        const have_editor_metadata = if (self.buffer_manager.get_buffer_for_file(f)) |_| true else false;
 | 
			
		||||
 | 
			
		||||
        if (!same_file and !have_editor_metadata)
 | 
			
		||||
        if (!same_file and !have_editor_metadata and line == null)
 | 
			
		||||
            if (try project_manager.get_mru_position(self.allocator, f)) |pos| {
 | 
			
		||||
                line = @intCast(pos.row);
 | 
			
		||||
                column = @intCast(pos.col);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -133,6 +133,8 @@ fn init(allocator: Allocator) !*Self {
 | 
			
		|||
    self.rdr_.dispatch_event = dispatch_event;
 | 
			
		||||
    try self.rdr_.run();
 | 
			
		||||
 | 
			
		||||
    try project_manager.start();
 | 
			
		||||
 | 
			
		||||
    try frame_clock.start();
 | 
			
		||||
    try self.commands.init(self);
 | 
			
		||||
    errdefer self.deinit();
 | 
			
		||||
| 
						 | 
				
			
			@ -895,6 +897,15 @@ const cmds = struct {
 | 
			
		|||
    pub const move_to_char_meta: Meta = .{ .description = "Move cursor to matching character" };
 | 
			
		||||
 | 
			
		||||
    pub fn open_file(self: *Self, ctx: Ctx) Result {
 | 
			
		||||
        if (get_active_selection(self.allocator)) |text| {
 | 
			
		||||
            defer self.allocator.free(text);
 | 
			
		||||
            const link = try root.file_link.parse(text);
 | 
			
		||||
            switch (link) {
 | 
			
		||||
                .file => |file| if (file.exists)
 | 
			
		||||
                    return root.file_link.navigate(tp.self_pid(), &link),
 | 
			
		||||
                else => {},
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return enter_mini_mode(self, @import("mode/mini/open_file.zig"), ctx);
 | 
			
		||||
    }
 | 
			
		||||
    pub const open_file_meta: Meta = .{ .description = "Open file" };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue