Implement unicode character replacements
Useful to draw whitespaces with alternate characters and colors without slowing down the text rendering. A new API is implemented. A renderer.replacements object can be created to list the replacements. In turns the function renderer.draw_text and draw_text_subpixel now accept two optional arguments for replacements.
This commit is contained in:
@@ -59,7 +59,7 @@ end
|
||||
|
||||
|
||||
function command.add_defaults()
|
||||
local reg = { "core", "root", "command", "doc", "findreplace", "files" }
|
||||
local reg = { "core", "root", "command", "doc", "findreplace", "files", "drawwhitespace" }
|
||||
for _, name in ipairs(reg) do
|
||||
require("core.commands." .. name)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
local command = require "core.command"
|
||||
local config = require "core.config"
|
||||
|
||||
command.add(nil, {
|
||||
["draw-whitespace:toggle"] = function()
|
||||
config.draw_whitespace = not config.draw_whitespace
|
||||
end,
|
||||
|
||||
["draw-whitespace:disable"] = function()
|
||||
config.draw_whitespace = false
|
||||
end,
|
||||
|
||||
["draw-whitespace:enable"] = function()
|
||||
config.draw_whitespace = true
|
||||
end,
|
||||
})
|
||||
@@ -21,6 +21,7 @@ config.max_project_files = 2000
|
||||
config.transitions = true
|
||||
config.animation_rate = 1.0
|
||||
config.blink_period = 0.8
|
||||
config.draw_whitespace = false
|
||||
|
||||
-- Disable plugin loading setting to false the config entry
|
||||
-- of the same name.
|
||||
|
||||
@@ -314,7 +314,11 @@ function DocView:draw_line_text(idx, x, y)
|
||||
local tx, ty = subpixel_scale * x, y + self:get_line_text_y_offset()
|
||||
for _, type, text in self.doc.highlighter:each_token(idx) do
|
||||
local color = style.syntax[type]
|
||||
tx = renderer.draw_text_subpixel(font, text, tx, ty, color)
|
||||
if config.draw_whitespace then
|
||||
tx = renderer.draw_text_subpixel(font, text, tx, ty, color, core.replacements, style.syntax.comment)
|
||||
else
|
||||
tx = renderer.draw_text_subpixel(font, text, tx, ty, color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -345,6 +345,14 @@ function core.remove_project_directory(path)
|
||||
end
|
||||
|
||||
|
||||
local function whitespace_replacements()
|
||||
local r = renderer.replacements.new()
|
||||
r:add(" ", "·")
|
||||
r:add("\t", "»")
|
||||
return r
|
||||
end
|
||||
|
||||
|
||||
function core.init()
|
||||
command = require "core.command"
|
||||
keymap = require "core.keymap"
|
||||
@@ -416,6 +424,7 @@ function core.init()
|
||||
core.redraw = true
|
||||
core.visited_files = {}
|
||||
core.restart_request = false
|
||||
core.replacements = whitespace_replacements()
|
||||
|
||||
core.root_view = RootView()
|
||||
core.command_view = CommandView()
|
||||
|
||||
Reference in New Issue
Block a user