diff options
| author | Adam <adamdharrison@gmail.com> | 2021-08-31 16:09:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-31 16:09:08 -0400 |
| commit | 49bee555facebdb8b569bde42d8380202b6c3009 (patch) | |
| tree | 45c65f61efcce60db5b96823617d2e6c76613bc7 | |
| parent | df8c1a98e43239ac8e5f0a782cdfb33b44d75032 (diff) | |
| parent | 1c4a4e763e34a8ffdb6d042ec96adef390bc749f (diff) | |
| download | lite-xl-49bee555facebdb8b569bde42d8380202b6c3009.tar.gz lite-xl-49bee555facebdb8b569bde42d8380202b6c3009.zip | |
Merge pull request #455 from adamharrison/fix-multicursor-commands
Fixed replace to make it multicursor-aware.
| -rw-r--r-- | data/core/doc/init.lua | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 65d2665c..2bb63ac4 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -464,12 +464,7 @@ function Doc:text_input(text, idx) end end - -function Doc:replace(fn) - local line1, col1, line2, col2 = self:get_selection(true) - if line1 == line2 and col1 == col2 then - line1, col1, line2, col2 = 1, 1, #self.lines, #self.lines[#self.lines] - end +function Doc:replace_cursor(idx, line1, col1, line2, col2, fn) local old_text = self:get_text(line1, col1, line2, col2) local new_text, n = fn(old_text) if old_text ~= new_text then @@ -477,12 +472,26 @@ function Doc:replace(fn) self:remove(line1, col1, line2, col2) if line1 == line2 and col1 == col2 then line2, col2 = self:position_offset(line1, col1, #new_text) - self:set_selection(line1, col1, line2, col2) + self:set_selections(idx, line1, col1, line2, col2) end end return n end +function Doc:replace(fn) + local has_selection = false + for idx, line1, col1, line2, col2 in self:get_selections(true) do + if line1 ~= line2 or col1 ~= col2 then + self:replace_cursor(idx, line1, col1, line2, col2, fn) + has_selection = true + end + end + if not has_selection then + self:set_selection(table.unpack(self.selections)) + self:replace_cursor(1, 1, 1, #self.lines, #self.lines[#self.lines], fn) + end +end + function Doc:delete_to_cursor(idx, ...) for sidx, line1, col1, line2, col2 in self:get_selections(true, idx) do |
