feat: add command to toggle syntax highlighting (S-F10)
This commit is contained in:
parent
f4dd30b1c2
commit
470967981b
6 changed files with 30 additions and 3 deletions
|
@ -58,8 +58,15 @@ pub fn destroy(self: *Self) void {
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset(self: *Self) void {
|
||||||
|
if (self.tree) |tree| {
|
||||||
|
tree.destroy();
|
||||||
|
self.tree = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn refresh_full(self: *Self, content: []const u8) !void {
|
pub fn refresh_full(self: *Self, content: []const u8) !void {
|
||||||
if (self.tree) |tree| tree.destroy();
|
self.reset();
|
||||||
self.tree = try self.parser.parseString(null, content);
|
self.tree = try self.parser.parseString(null, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3065,7 +3065,11 @@ pub const Editor = struct {
|
||||||
if (self.syntax_token == token)
|
if (self.syntax_token == token)
|
||||||
return;
|
return;
|
||||||
if (self.syntax) |syn| {
|
if (self.syntax) |syn| {
|
||||||
if (self.syntax_no_render) return;
|
if (self.syntax_no_render) {
|
||||||
|
syn.reset();
|
||||||
|
self.syntax_token = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!self.syntax_refresh_update)
|
if (!self.syntax_refresh_update)
|
||||||
self.syntax_refresh_full = true;
|
self.syntax_refresh_full = true;
|
||||||
if (self.syntax_refresh_full) {
|
if (self.syntax_refresh_full) {
|
||||||
|
@ -3081,7 +3085,6 @@ pub const Editor = struct {
|
||||||
} else {
|
} else {
|
||||||
try syn.refresh_from_buffer(root, self.metrics);
|
try syn.refresh_from_buffer(root, self.metrics);
|
||||||
}
|
}
|
||||||
self.syntax_token = token;
|
|
||||||
} else {
|
} else {
|
||||||
var content = std.ArrayList(u8).init(self.allocator);
|
var content = std.ArrayList(u8).init(self.allocator);
|
||||||
defer content.deinit();
|
defer content.deinit();
|
||||||
|
@ -3093,6 +3096,7 @@ pub const Editor = struct {
|
||||||
if (self.syntax_no_render) return;
|
if (self.syntax_no_render) return;
|
||||||
if (self.syntax) |syn| try syn.refresh_full(content.items);
|
if (self.syntax) |syn| try syn.refresh_full(content.items);
|
||||||
}
|
}
|
||||||
|
self.syntax_token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_syntax(self: *Self) void {
|
fn reset_syntax(self: *Self) void {
|
||||||
|
@ -3930,6 +3934,15 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub const toggle_eol_mode_meta = .{ .description = "Toggle end of line sequence" };
|
pub const toggle_eol_mode_meta = .{ .description = "Toggle end of line sequence" };
|
||||||
|
|
||||||
|
pub fn toggle_syntax_highlighting(self: *Self, _: Context) Result {
|
||||||
|
self.syntax_no_render = !self.syntax_no_render;
|
||||||
|
if (self.syntax_no_render) {
|
||||||
|
if (self.syntax) |syn| syn.reset();
|
||||||
|
self.syntax_token = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub const toggle_syntax_highlighting_meta = .{ .description = "Toggle syntax highlighting" };
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn create(allocator: Allocator, parent: Widget) !Widget {
|
pub fn create(allocator: Allocator, parent: Widget) !Widget {
|
||||||
|
|
|
@ -182,6 +182,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
|
||||||
},
|
},
|
||||||
mod.SHIFT => switch (keypress) {
|
mod.SHIFT => switch (keypress) {
|
||||||
key.F03 => self.cmd("goto_prev_match", .{}),
|
key.F03 => self.cmd("goto_prev_match", .{}),
|
||||||
|
key.F10 => self.cmd("toggle_syntax_highlighting", .{}),
|
||||||
key.F12 => self.cmd("references", .{}),
|
key.F12 => self.cmd("references", .{}),
|
||||||
key.LEFT => self.cmd("select_left", .{}),
|
key.LEFT => self.cmd("select_left", .{}),
|
||||||
key.RIGHT => self.cmd("select_right", .{}),
|
key.RIGHT => self.cmd("select_right", .{}),
|
||||||
|
@ -426,6 +427,7 @@ const hints = tui.KeybindHints.initComptime(.{
|
||||||
.{ "toggle_inspector_view", "F5, C-F5, C-S-i" },
|
.{ "toggle_inspector_view", "F5, C-F5, C-S-i" },
|
||||||
.{ "toggle_panel", "C-j, F11" },
|
.{ "toggle_panel", "C-j, F11" },
|
||||||
.{ "toggle_whitespace_mode", "C-F10" },
|
.{ "toggle_whitespace_mode", "C-F10" },
|
||||||
|
.{ "toggle_syntax_highlighting", "S-F10" },
|
||||||
.{ "to_lower", "A-l" },
|
.{ "to_lower", "A-l" },
|
||||||
.{ "to_upper", "A-u" },
|
.{ "to_upper", "A-u" },
|
||||||
.{ "undo", "C-z" },
|
.{ "undo", "C-z" },
|
||||||
|
|
|
@ -176,6 +176,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
|
||||||
},
|
},
|
||||||
mod.SHIFT => switch (keypress) {
|
mod.SHIFT => switch (keypress) {
|
||||||
key.F03 => self.cmd("goto_prev_match", .{}),
|
key.F03 => self.cmd("goto_prev_match", .{}),
|
||||||
|
key.F10 => self.cmd("toggle_syntax_highlighting", .{}),
|
||||||
key.LEFT => self.cmd("select_left", .{}),
|
key.LEFT => self.cmd("select_left", .{}),
|
||||||
key.RIGHT => self.cmd("select_right", .{}),
|
key.RIGHT => self.cmd("select_right", .{}),
|
||||||
key.UP => self.cmd("select_up", .{}),
|
key.UP => self.cmd("select_up", .{}),
|
||||||
|
|
|
@ -181,6 +181,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
|
||||||
},
|
},
|
||||||
mod.SHIFT => switch (keypress) {
|
mod.SHIFT => switch (keypress) {
|
||||||
key.F03 => self.cmd("goto_prev_match", .{}),
|
key.F03 => self.cmd("goto_prev_match", .{}),
|
||||||
|
key.F10 => self.cmd("toggle_syntax_highlighting", .{}),
|
||||||
key.LEFT => self.cmd("select_left", .{}),
|
key.LEFT => self.cmd("select_left", .{}),
|
||||||
key.RIGHT => self.cmd("select_right", .{}),
|
key.RIGHT => self.cmd("select_right", .{}),
|
||||||
key.UP => self.cmd("select_up", .{}),
|
key.UP => self.cmd("select_up", .{}),
|
||||||
|
@ -611,6 +612,7 @@ const hints = tui.KeybindHints.initComptime(.{
|
||||||
.{ "toggle_inspector_view", "F5, C-F5, C-S-i" },
|
.{ "toggle_inspector_view", "F5, C-F5, C-S-i" },
|
||||||
.{ "toggle_panel", "C-j, F11" },
|
.{ "toggle_panel", "C-j, F11" },
|
||||||
.{ "toggle_whitespace_mode", "C-F10" },
|
.{ "toggle_whitespace_mode", "C-F10" },
|
||||||
|
.{ "toggle_syntax_highlighting", "S-F10" },
|
||||||
.{ "to_lower", "A-l" },
|
.{ "to_lower", "A-l" },
|
||||||
.{ "to_upper", "A-u" },
|
.{ "to_upper", "A-u" },
|
||||||
.{ "undo", "C-z" },
|
.{ "undo", "C-z" },
|
||||||
|
|
|
@ -179,6 +179,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
|
||||||
},
|
},
|
||||||
mod.SHIFT => switch (keypress) {
|
mod.SHIFT => switch (keypress) {
|
||||||
key.F03 => self.cmd("goto_prev_match", .{}),
|
key.F03 => self.cmd("goto_prev_match", .{}),
|
||||||
|
key.F10 => self.cmd("toggle_syntax_highlighting", .{}),
|
||||||
key.LEFT => self.cmd("select_left", .{}),
|
key.LEFT => self.cmd("select_left", .{}),
|
||||||
key.RIGHT => self.cmd("select_right", .{}),
|
key.RIGHT => self.cmd("select_right", .{}),
|
||||||
key.UP => self.cmd("select_up", .{}),
|
key.UP => self.cmd("select_up", .{}),
|
||||||
|
@ -559,6 +560,7 @@ const hints = tui.KeybindHints.initComptime(.{
|
||||||
.{ "toggle_inspector_view", "F5, C-F5, C-S-i" },
|
.{ "toggle_inspector_view", "F5, C-F5, C-S-i" },
|
||||||
.{ "toggle_panel", "C-j, F11" },
|
.{ "toggle_panel", "C-j, F11" },
|
||||||
.{ "toggle_whitespace_mode", "C-F10" },
|
.{ "toggle_whitespace_mode", "C-F10" },
|
||||||
|
.{ "toggle_syntax_highlighting", "S-F10" },
|
||||||
.{ "to_lower", "A-l" },
|
.{ "to_lower", "A-l" },
|
||||||
.{ "to_upper", "A-u" },
|
.{ "to_upper", "A-u" },
|
||||||
.{ "undo", "C-z" },
|
.{ "undo", "C-z" },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue