Revert horizontal scroll implementation

This commit is contained in:
Guldoman
2021-09-08 07:11:50 +02:00
committed by Francesco
parent 474952645c
commit 0a52861129
4 changed files with 6 additions and 147 deletions
-76
View File
@@ -32,7 +32,6 @@ end
function Doc:reset()
self.lines = { "\n" }
self.long_lines = { line_numbers = { }, length = 0 }
self.selections = { 1, 1, 1, 1 }
self.cursor_clipboard = {}
self.undo_stack = { idx = 1 }
@@ -61,33 +60,19 @@ end
function Doc:load(filename)
local fp = assert( io.open(filename, "rb") )
local max_length = 0
local line_numbers = { }
self:reset()
self.lines = {}
local i = 1
for line in fp:lines() do
if line:byte(-1) == 13 then
line = line:sub(1, -2)
self.crlf = true
end
table.insert(self.lines, line .. "\n")
local line_len = #line + 1 -- account for newline
if line_len >= max_length then
max_length = line_len
line_numbers[i] = line_len
end
i = i + 1
end
for n, len in pairs(line_numbers) do
line_numbers[n] = len >= max_length and len or nil
end
if #self.lines == 0 then
table.insert(self.lines, "\n")
end
fp:close()
self.long_lines.line_numbers = line_numbers
self.long_lines.length = max_length
self:reset_syntax()
end
@@ -362,20 +347,6 @@ function Doc:raw_insert(line, col, text, undo_stack, time)
push_undo(undo_stack, time, "selection", unpack(self.selections))
push_undo(undo_stack, time, "remove", line, col, line2, col2)
if #lines > 1 then
-- Need to shift all the subsequent long lines
local line_numbers = { }
for n, len in pairs(self.long_lines.line_numbers) do
if n > line then
line_numbers[n + #lines - 1] = len
else
line_numbers[n] = len
end
end
self.long_lines.line_numbers = line_numbers
end
self:update_max_line_len_range(line, line2)
-- update highlighter and assure selection is in bounds
self.highlighter:invalidate(line)
self:sanitize_selection()
@@ -403,23 +374,6 @@ function Doc:raw_remove(line1, col1, line2, col2, undo_stack, time)
self:set_selections(idx, cline1 - line_removal, ccol1 - column_removal, cline2 - line_removal, ccol2 - column_removal)
end
local nlines = line2 - line1 + 1
if nlines > 1 then
-- Need to shift all the subsequent long lines
local line_numbers = { }
for n, len in pairs(self.long_lines.line_numbers) do
if n > line2 then
line_numbers[n - nlines + 1] = len
elseif n > line1 then
line_numbers[n] = nil -- invalidate any line that has been deleted
else
line_numbers[n] = len
end
end
self.long_lines.line_numbers = line_numbers
end
self:update_max_line_len_range(line1, line2)
-- update highlighter and assure selection is in bounds
self.highlighter:invalidate(line1)
self:sanitize_selection()
@@ -585,36 +539,6 @@ function Doc:indent_text(unindent, line1, col1, line2, col2)
return line1, col1 + #text, line1, col1 + #text
end
function Doc:update_max_line_len_range(start_line, end_line)
local line_numbers = self.long_lines.line_numbers
local max_length = self.long_lines.length
end_line = math.min(end_line, #self.lines)
for line=start_line,end_line do
local line_len = #self.lines[line]
if line_len >= max_length then
max_length = line_len
line_numbers[line] = line_len
else
if line_numbers[line] then line_numbers[line] = nil end
end
end
for n, len in pairs(line_numbers) do
line_numbers[n] = len >= max_length and len or nil
end
if not next(line_numbers) then
-- Recalc needed
self.long_lines.length = 0
self.long_lines.line_numbers = line_numbers
return self:update_max_line_len_range(1, #self.lines)
end
self.long_lines.line_numbers = line_numbers
self.long_lines.length = max_length
end
-- For plugins to add custom actions of document change
function Doc:on_text_change(type)
end