diff --git a/lua/presser/utils.lua b/lua/presser/utils.lua index 13583c6..4a5bb93 100644 --- a/lua/presser/utils.lua +++ b/lua/presser/utils.lua @@ -31,8 +31,32 @@ M.clean_buf = function ( text ) return "" end - return escape_chars( text ) - :match( "^%s*(.-)%s*$" ) + return text:match( "^%s*(.-)%s*$" ) +end + + +M.get_selection = function() + local _, csrow, cscol, _ = unpack(vim.fn.getpos("'<")) + local _, cerow, cecol, _ = unpack(vim.fn.getpos("'>")) + if csrow < cerow or (csrow == cerow and cscol <= cecol) then + return csrow - 1, cscol - 1, cerow - 1, cecol + else + return cerow - 1, cecol - 1, csrow - 1, cscol + end +end + + +M.subslice = function(line, col) + local i = 0 + local j = 0 + while true do + j = string.find(line, " ", j+1) -- find 'next' newline + if j == nil then break end + if j > col then break end + i = j + end + + return { i, j } end