add doc:get_selection_text()
This commit is contained in:
parent
1d9f04e7d6
commit
cf7ebdad1f
|
@ -124,9 +124,21 @@ function Doc:get_selection(sort)
|
||||||
return line1, col1, line2, col2, sort
|
return line1, col1, line2, col2, sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Doc:get_selection_text(limit)
|
||||||
|
limit = limit or math.huge
|
||||||
|
local result = {}
|
||||||
|
for idx, line1, col1, line2, col2 in self:get_selections() do
|
||||||
|
if idx > limit then break end
|
||||||
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
|
local text = self:get_text(line1, col1, line2, col2)
|
||||||
|
if text ~= "" then result[#result + 1] = text end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(result, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
function Doc:has_selection()
|
function Doc:has_selection()
|
||||||
local line1, col1, line2, col2 = self:get_selection(false)
|
local line1, col1, line2, col2 = self:get_selection(false) return line1 ~= line2 or col1 ~= col2
|
||||||
return line1 ~= line2 or col1 ~= col2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Doc:sanitize_selection()
|
function Doc:sanitize_selection()
|
||||||
|
|
Loading…
Reference in New Issue