diff options
author | Georgi Kirilov <> | 2020-11-22 15:10:49 +0200 |
---|---|---|
committer | Georgi Kirilov <> | 2023-10-04 18:24:59 +0800 |
commit | dff91d12cc11c317bdb3d28bf835b3a31653375d (patch) | |
tree | 3cf79df3d7280b1183d38b98c4950399dad36ae8 /pairs.lua | |
parent | 15e524a250a0cceadbfd9cdcaa163edef89b8791 (diff) | |
download | vis-pairs-dff91d12cc11c317bdb3d28bf835b3a31653375d.tar.gz |
Exclusive inner textobjects in VISUAL_LINE
First/last lines of a block are not included in the selection,
if they have only trailing whitespace after the opening,
and only leading whitespace before the closing, delimiter.
Diffstat (limited to 'pairs.lua')
-rw-r--r-- | pairs.lua | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -182,6 +182,25 @@ local function get_range(key, win, pos, file_data) return unpack(offsets) end +local function barf_indent(content, start, finish) + if vis.mode == vis.modes.VISUAL_LINE then + local block = content:sub(start + 1, finish) + local newlines = l.match(l.Ct((l.Cp() * l.P"\n" + 1)^0), block) + if #newlines > 1 then + local first_line = block:sub(1, newlines[1] - 1) + local last_line = block:sub(newlines[#newlines] + 1) + local space = l.S" \t"^0 + local trailing_space = l.match(space * -1, first_line) + local trailing_indent = l.match(space * -1, last_line) + if trailing_space and trailing_indent then + start = start + trailing_space + finish = finish - trailing_indent + 1 + end + end + end + return start, finish +end + local function get_delimiters(key, win, pos) local d = get_pair(key, win) if not d or type(d[1]) == "string" and type(d[2]) == "string" then return d end @@ -203,7 +222,7 @@ end local function inner(win, pos, content) local start, finish = get_range(M.key, win, pos, content) if not (start and finish) then return end - return start[2], finish[1] + return barf_indent(content, start[2], finish[1]) end local function opening(win, pos, content) |