cut/copy selected text to clipboard
[?]
May 29, 2022, 10:33 PM
KWOJ6XHEE7ERLFJ6FBXCL73DE6OFJQ7LXNXAN44G5P5EXFDH5HIACDependencies
- [2]
CG3264MMmove - [*]
BULPIBEGbeginnings of a module for the text editor - [*]
5DOC2CBMextract a function
Change contents
- edit in text.lua at line 167[5.101][5.101]
function Text.selection()if Selection1.line == nil then return end-- min,max = sorted(Selection1,Cursor1)local minl,minp = Selection1.line,Selection1.poslocal maxl,maxp = Cursor1.line,Cursor1.posif minl > maxl thenminl,maxl = maxl,minlminp,maxp = maxp,minpelseif minl == maxl thenif minp > maxp thenminp,maxp = maxp,minpendendlocal min_offset = utf8.offset(Lines[minl].data, minp)local max_offset = utf8.offset(Lines[maxl].data, maxp)if minl == maxl thenreturn Lines[minl].data:sub(min_offset, max_offset-1)endassert(minl < maxl)local result = Lines[minl].data:sub(min_offset)..'\n'for i=minl+1,maxl-1 doif Lines[i].mode == 'text' thenresult = result..Lines[i].data..'\n'endendresult = result..Lines[maxl].data:sub(1, max_offset-1)return resultendfunction Text.cut_selection()local result = Text.selection()Text.delete_selection()return resultend - edit in text.lua at line 1215
elseif chord == 'M-c' thenlocal s = Text.selection()if s thenlove.system.setClipboardText(s)endelseif chord == 'M-x' thenlocal s = Text.cut_selection()if s thenlove.system.setClipboardText(s)end