fix: convert column to byte position in inspector_view.inspect_location
fixes #54
This commit is contained in:
		
							parent
							
								
									a46c75da63
								
							
						
					
					
						commit
						6755eaab44
					
				
					 2 changed files with 21 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -553,6 +553,24 @@ const Node = union(enum) {
 | 
			
		|||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_line_width_to_pos(self: *const Node, line: usize, col: usize, metrics: Metrics) error{Stop}!usize {
 | 
			
		||||
        const Ctx = struct {
 | 
			
		||||
            col: usize,
 | 
			
		||||
            wcwidth: usize = 0,
 | 
			
		||||
            pos: usize = 0,
 | 
			
		||||
            fn walker(ctx_: *anyopaque, egc: []const u8, wcwidth: usize, _: Metrics) Walker {
 | 
			
		||||
                const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_)));
 | 
			
		||||
                if (ctx.wcwidth >= ctx.col) return Walker.stop;
 | 
			
		||||
                ctx.pos += egc.len;
 | 
			
		||||
                ctx.wcwidth += wcwidth;
 | 
			
		||||
                return if (egc[0] == '\n') Walker.stop else Walker.keep_walking;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        var ctx: Ctx = .{ .col = col };
 | 
			
		||||
        self.walk_egc_forward(line, Ctx.walker, &ctx, metrics) catch return error.Stop;
 | 
			
		||||
        return ctx.pos;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_range(self: *const Node, sel: Selection, copy_buf: ?[]u8, size: ?*usize, wcwidth_: ?*usize, metrics_: Metrics) error{ Stop, NoSpaceLeft }!?[]u8 {
 | 
			
		||||
        const Ctx = struct {
 | 
			
		||||
            col: usize = 0,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,7 +73,9 @@ fn clear(self: *Self) void {
 | 
			
		|||
 | 
			
		||||
fn inspect_location(self: *Self, row: usize, col: usize) void {
 | 
			
		||||
    const syn = self.editor.syntax orelse return;
 | 
			
		||||
    syn.highlights_at_point(self, dump_highlight, .{ .row = @intCast(row), .column = @intCast(col) });
 | 
			
		||||
    const root = (self.editor.buffer orelse return).root;
 | 
			
		||||
    const col_pos = root.get_line_width_to_pos(row, col,self.editor.metrics) catch return;
 | 
			
		||||
    syn.highlights_at_point(self, dump_highlight, .{ .row = @intCast(row), .column = @intCast(col_pos) });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn get_buffer_text(self: *Self, buf: []u8, sel: Buffer.Selection) ?[]const u8 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue