--▽▽UTF-8▽▽ --Clipboard.lua --[[ copyleft by jinzhongjie(xjinzhongjie@hotmail.com).anyone who want change the code please tell writer. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. ]] --local buffers = {} local my_path = lua_LoadPath() local append = table.insert local len = string.len local clipTotal = 20 local clip_pos_start = -1 local clip_pos_end = -1 local clip_pos_cmd = -1 local clip_pos_list = -1 local clipLinestart = -1 local clip_table = {} --for check use time local clipStats_table = {} local active_num = nil local mark_num = nil local active_line = nil local mark_line = nil local function remove_clip() if active_line then output:MarkerDelete(clipLinestart+active_line, 12) active_line = nil end if mark_line then output:MarkerDelete(clipLinestart+mark_line, 11) mark_line = nil end outputRemove(output, clip_pos_start, clip_pos_end) clip_pos_start = -1 clip_pos_end = -1 end local function ClipAdjust(diff) clip_pos_start = clip_pos_start + diff clip_pos_end = clip_pos_end + diff clip_pos_cmd = clip_pos_cmd + diff clip_pos_list = clip_pos_list + diff --funcLinestart=output:LineFromPosition(func_pos_start) end local function clearClipParam() clip_pos_start = -1 clip_pos_end = -1 end scite_outputChange(function(pane, bPos, length) --print('start:'..output.SelectionStart..',end:'..output.SelectionEnd) if pane == output then --print("---"..keyval) RoutineAdjustChange(bPos, length, clip_pos_start, clip_pos_end, ClipAdjust, clearClipParam) end return false end) scite_OnInit(function(order1, order2) if order1 == 0 and order2 == 0 then local f = io.open(my_path.."/Clipboard.cnf", "r") if not f then return false end for line in f:lines()do local field, Value = line:match('^([^=]+)=(.*)$') if field == 'active_num' then active_num = tonumber(Value) elseif field == 'active_line' then active_line = tonumber(Value) elseif field == 'mark_num' then mark_num = tonumber(Value) elseif field == 'mark_line' then mark_line = tonumber(Value) elseif field == 'clip_pos_start' then clip_pos_start = tonumber(Value) elseif field == 'clip_pos_end' then clip_pos_end = tonumber(Value) elseif field == 'clip_pos_cmd' then clip_pos_cmd = tonumber(Value) elseif field == 'clip_pos_list' then clip_pos_list = tonumber(Value) else local pos = tonumber(field) local line = string.gsub(Value, "◎\\n◎", "\n") line = string.gsub(line, "◎\\r◎", "\r") clip_table[pos] = line clipStats_table[pos] = 1 end end f:close() end return false end) scite_OnFinalise(function(level1, level2) if level1 == 1 then local f = io.open(my_path.."/Clipboard.cnf", "w") if not f then return false end if not active_num then active_num = 0 end if not active_line then active_line = 0 end if not mark_num then mark_num = 0 end if not mark_line then mark_line = 0 end f:write('active_num='..active_num..'\n') f:write('active_line='..active_line..'\n') f:write('mark_num='..mark_num..'\n') f:write('mark_line='..mark_line..'\n') f:write('clip_pos_start='..clip_pos_start..'\n') f:write('clip_pos_end='..clip_pos_end..'\n') f:write('clip_pos_cmd='..clip_pos_cmd..'\n') f:write('clip_pos_list='..clip_pos_list..'\n') if clip_table then local pos = 1 while pos < (clipTotal+1)do if clip_table[pos] then local line = string.gsub(clip_table[pos], "\n", "◎\\n◎") line = string.gsub(line, "\r", "◎\\r◎") f:write(pos..'='..line..'\n') end pos = pos+1 end end f:close() end return false end) local cmd_del_tag = ' ' local cmd_clearAll_tag = '' local function updateClipContent() if clip_pos_start >0 and clip_pos_end>0 then remove_clip() end output.CurrentPos = output.Length clip_pos_start = output.CurrentPos print("----Clipboard--------------------") clip_pos_cmd = output.CurrentPos print(cmd_del_tag..cmd_clearAll_tag) print("---------------------------") clip_pos_list = output.CurrentPos clipLinestart = output:LineFromPosition(clip_pos_list) print("0:System Clipboard") local pos = 1 local countLine = 1 active_line = 0 mark_line = 0 while pos < (clipTotal+1)do if clip_table[pos] then local line = string.gsub(clip_table[pos], "\n", "\\n") line = string.gsub(line, "\r", "\\r") --line=string.gsub(clip_table[pos],"\r","\\r") if string.len(line)>100 then line = string.sub(line, 1, 100).." ... " end print(pos..":"..line) if active_num == pos then active_line = countLine end if mark_num == pos then mark_line = countLine end countLine = countLine+1 end pos = pos+1 end print("---------------------------") clip_pos_end = output.CurrentPos output:MarkerDefine(11, SC_MARK_FULLRECT) output:MarkerSetBack(11, colour_parse('vGreen')) output:MarkerAdd(clipLinestart+mark_line, 11) output:MarkerDefine(12, SC_MARK_FULLRECT) output:MarkerSetBack(12, colour_parse('vBlue')) output:MarkerAdd(clipLinestart+active_line, 12) end scite_OnKey(function(keyval, shift, ctl, atl) if editor.Focus and ctl then if keyval == 67 and editor.SelectionStart clipStats_table[pos] then delPos = pos end end pos = pos+1 end pos = delPos clip_table[pos] = nil clipStats_table[pos] = nil while pos < clipTotal do if clip_table[pos+1] then clip_table[pos] = clip_table[pos+1] clipStats_table[pos] = clipStats_table[pos+1] clip_table[pos+1] = nil clipStats_table[pos+1] = nil end pos = pos+1 end clip_table[pos] = copy_txt clipStats_table[pos] = 1 mark_num = pos end active_num = nil updateClipContent() return false elseif keyval == 86 and active_num then --V if active_num > 0 then clipStats_table[active_num] = clipStats_table[active_num]+1 else return false end if editor.SelectionStart= clip_pos_list and output.CurrentPos < clip_pos_end then -- ↑ ↓ if keyval == 38 or keyval == 40 then clipLinestart = output:LineFromPosition(clip_pos_list) local linePos = output:LineFromPosition(output.CurrentPos)-clipLinestart if active_line then output:MarkerDelete(clipLinestart+active_line, 12) active_line = nil end if keyval == 40 and(clipLinestart+linePos)< (output.LineCount-2)then linePos = linePos+1 elseif keyval == 38 then linePos = linePos-1 end local content = output:GetLine(clipLinestart+linePos):sub(1, -2) local num = tonumber(string.match(content, "^(%d+):.*$")) if num then active_line = linePos if num == 0 then active_num = nil else active_num = num editor:CopyText(clip_table[active_num]) end output:MarkerDefine(12, SC_MARK_FULLRECT) output:MarkerSetBack(12, colour_parse('vBlue')) output:MarkerAdd(clipLinestart+active_line, 12) end mark_num = active_num end end return false end) scite_OnDoubleClick(function() if output.Focus and output.CurrentPos >= clip_pos_start and output.CurrentPos < clip_pos_end then if output.CurrentPos