diff options
author | 2020-10-20 15:29:03 -0400 | |
---|---|---|
committer | 2020-10-20 15:29:03 -0400 | |
commit | 03c4016d07477781aa3adcc9edf340c0bec9c6c8 (patch) | |
tree | d3be089e9020807326a4e56562876ecb7bcf7892 /modules/textadept/history.lua | |
parent | b682fbd4a6e53185e2556686079532ad0e42be94 (diff) | |
download | textadept-03c4016d07477781aa3adcc9edf340c0bec9c6c8.tar.gz textadept-03c4016d07477781aa3adcc9edf340c0bec9c6c8.zip |
Code cleanup.
Of note:
* io.save_all_files() does not visit each buffer to save anymore. An unintended
side-effect was checking for outside modification (but only if the file itself
was modified), so outside changes will always be saved over now.
* The menu clicked handler uses assert_type(), so the 'Unknown command'
localization is no longer needed.
* When printing to a new buffer type would split the view, use an existing split
view when possible.
* Prefer 'goto continue' construct in loops over nested 'if's.
* Fixed clearing of ui.find.replace_entry_text on reset in the GUI version.
* Fixed lack of statusbar updating when setting options like buffer EOL mode,
indentation, and encoding.
* Renamed internal new_snippet() to new() and put it in the snippet metatable.
Diffstat (limited to 'modules/textadept/history.lua')
-rw-r--r-- | modules/textadept/history.lua | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/modules/textadept/history.lua b/modules/textadept/history.lua index 4729322c..d619363f 100644 --- a/modules/textadept/history.lua +++ b/modules/textadept/history.lua @@ -34,21 +34,19 @@ local view_history = setmetatable({}, {__index = function(t, view) end}) -- Listens for text insertion and deletion events and records their locations. -events.connect(events.MODIFIED, function(position, mod_type, text, length) +events.connect(events.MODIFIED, function(position, mod, text, length) local buffer = buffer -- Only interested in text insertion or deletion. - if mod_type & buffer.MOD_INSERTTEXT > 0 then + if mod & buffer.MOD_INSERTTEXT > 0 then if length == buffer.length then return end -- ignore file loading position = position + length - elseif mod_type & buffer.MOD_DELETETEXT > 0 then + elseif mod & buffer.MOD_DELETETEXT > 0 then if buffer.length == 0 then return end -- ignore replacing buffer contents else return end -- Ignore undo/redo. - if mod_type & (buffer.PERFORMED_UNDO | buffer.PERFORMED_REDO) > 0 then - return - end + if mod & (buffer.PERFORMED_UNDO | buffer.PERFORMED_REDO) > 0 then return end M.record(nil, buffer:line_from_position(position), buffer.column[position]) end) @@ -56,13 +54,11 @@ end) -- forwards. local jumping = false --- Jumps to the current position in the current view's history after adjusting --- that position backwards or forwards. -local function goto_record() +-- Jumps to the given record in the current view's history. +-- @param record History record to jump to. +local function jump(record) jumping = true - local history = view_history[view] - local record = history[history.pos] - local filename, line, column = record.filename, record.line, record.column + local filename = record.filename if lfs.attributes(filename) then io.open_file(filename) else @@ -75,7 +71,7 @@ local function goto_record() end end end - buffer:goto_pos(buffer:find_column(line, column)) + buffer:goto_pos(buffer:find_column(record.line, record.column)) jumping = false end @@ -91,13 +87,13 @@ function M.back() math.abs(record.line - line) > M.minimum_line_distance then -- When navigated away from the most recent record, and if that record is -- not a soft record, jump back to it first, then navigate backwards. - if not record.soft then goto_record() return end + if not record.soft then jump(record) return end -- Otherwise, update the soft record with the current position and -- immediately navigate backwards. M.record(record.filename, nil, nil, record.soft) end if history.pos > 1 then history.pos = history.pos - 1 end - goto_record() + jump(history[history.pos]) end --- @@ -109,7 +105,7 @@ function M.forward() local record = history[history.pos] if record.soft then M.record(record.filename, nil, nil, record.soft) end history.pos = history.pos + 1 - goto_record() + jump(history[history.pos]) end --- |