--▽▽UTF-8▽▽ --diff.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 append = table.insert local ext local diff_pos_start = -1 local diff_pos_end = -1 local diff_pos_up,diff_pos_down local diffLinestart = -1 local diff_list = {} local function remove_diff() outputRemove(output, diff_pos_start, diff_pos_end) diff_pos_start = -1 diff_pos_end = -1 end local active_now = nil local cur_line local function DiffAdjust(diff) diff_pos_start = diff_pos_start + diff diff_pos_end = diff_pos_end + diff diff_pos_up = diff_pos_up + diff diff_pos_down = diff_pos_down + diff --funcLinestart=output:LineFromPosition(func_pos_start) end local function clearDiffParam() diff_pos_start = -1 diff_pos_end = -1 end --[[ scite_outputInsert(function(pane,bPos,length) --print('start:'..output.SelectionStart..',end:'..output.SelectionEnd) if pane == output then --print("---"..keyval) RoutineAdjustAdd(bPos,length,diff_pos_start,diff_pos_end,DiffAdjust,clearDiffParam) end return false end) scite_outputRemove(function(pane,bPos,ePos) --print('start:'..output.SelectionStart..',end:'..output.SelectionEnd) if pane == output then --print("---"..keyval) RoutineAdjustDelete(bPos,ePos,diff_pos_start,diff_pos_end,DiffAdjust,clearDiffParam) end return false end) ]]-- scite_OnFinalise(function(level1, level2) if level1 == 1 then if diff_pos_start >0 and diff_pos_end>0 then remove_diff() end end return false end) scite_outputChange(function(pane, bPos, length) --print('start:'..output.SelectionStart..',end:'..output.SelectionEnd) if pane == output then --print("---"..keyval) RoutineAdjustChange(bPos, length, diff_pos_start, diff_pos_end, DiffAdjust, clearDiffParam) end return false end) scite_OnKey(function(keyval, shift, ctl, atl) if output.Focus and output.CurrentPos >= diff_pos_start and output.CurrentPos <= diff_pos_end then if keyval == 38 or keyval == 40 then diffLinestart = output:LineFromPosition(diff_pos_start) local linePos = output:LineFromPosition(output.CurrentPos)-diffLinestart if cur_line then editor:MarkerDelete(cur_line, 11) end if active_now then output:MarkerDelete(diffLinestart+active_now, 11) end if keyval == 40 then linePos = linePos+1 elseif keyval == 38 then linePos = linePos-1 end if diff_list[linePos] then cur_line = diff_list[linePos] editor:MarkerDefine(11, SC_MARK_BACKGROUND) editor:MarkerSetBack(11, colour_parse('vBlue')) editor:MarkerAdd(cur_line, 11) editor:GotoLine(cur_line) --ctags_center_pos(diff_list[linePos]) active_now = linePos end output:MarkerDefine(11, SC_MARK_FULLRECT) output:MarkerSetBack(11, colour_parse('vBlue')) output:MarkerAdd(diffLinestart+active_now, 11) end end return false end) scite_OnDoubleClick(function() if output.Focus and output.CurrentPos >= diff_pos_start and output.CurrentPos <= diff_pos_end then diffLinestart = output:LineFromPosition(diff_pos_start) if cur_line then editor:MarkerDelete(cur_line, 11) end if active_now then output:MarkerDelete(diffLinestart+active_now, 11) end if output.CurrentPos -1 do pos = editor:PositionFromLine(line) local style = editor.StyleAt[pos] if style == SCE_DIFF_DELETED or style == SCE_DIFF_ADDED then if status == 0 then editor:MarkerDefine(11, SC_MARK_BACKGROUND) editor:MarkerSetBack(11, colour_parse('vBlue')) editor:MarkerAdd(line, 11) cur_line = line editor:GotoLine(line) break end status = 1 else status = 0 end if output.CurrentPos 0 do if diff_list[linePos] and diff_list[linePos]<= cur_line then active_now = linePos break end linePos = linePos-1 end else local linePos = output:LineFromPosition(output.CurrentPos)-diffLinestart if diff_list[linePos] then editor:MarkerDefine(11, SC_MARK_BACKGROUND) editor:MarkerSetBack(11, colour_parse('vBlue')) editor:MarkerAdd(diff_list[linePos], 11) cur_line = diff_list[linePos] editor:GotoLine(diff_list[linePos]) --ctags_center_pos(diff_list[linePos]) active_now = linePos end end output:MarkerDefine(11, SC_MARK_FULLRECT) output:MarkerSetBack(11, colour_parse('vBlue')) output:MarkerAdd(diffLinestart+active_now, 11) return true else --[[ local var=editor.StyleBack[32] local remain0=var%0x10000 local var0=(var-remain0)/0x10000 local var2=remain0%0x100 local var1=(remain0-var2)/0x100 --local str=string.format("Back=%X",editor.StyleBack[32]) print("Back="..var0.."||"..var1.."||"..var2) --str=string.format("Fore=%X",editor.StyleFore[32]) var=editor.StyleFore[32] remain0=var%0x10000 var0=(var-remain0)/0x10000 var2=remain0%0x100 var1=(remain0-var2)/0x100 print("Fore="..var0.."||"..var1.."||"..var2) ]]-- end return false end) local function buffer_switch(f) ext = scite_GetProp('FileExt', 'txt') if SCLEX_DIFF == editor.Lexer or f == "diff" then if diff_pos_start >0 and diff_pos_end>0 then remove_diff() end editor:Colourise(0, -1) local status = 0 local line = 0 local pos = 0 diff_pos_start = output.Length diffLinestart = output:LineFromPosition(diff_pos_start) print("----diff--------------------") print("< up ↑>") diff_pos_up = output.CurrentPos print("< down↓>") diff_pos_down = output.CurrentPos print("---------------------------") while pos > -1 do pos = editor:PositionFromLine(line) local style = editor.StyleAt[pos] if style == SCE_DIFF_DELETED or style == SCE_DIFF_ADDED then if status == 0 then local linePos = output:LineFromPosition(output.CurrentPos)-diffLinestart diff_list[linePos] = line local content = editor:GetLine(line):sub(1, -2) print((line+1)..":"..content) end status = 1 else status = 0 end line = line+1 end diff_pos_end = output.CurrentPos else if diff_pos_start >0 and diff_pos_end>0 then remove_diff() end end end scite_OnOpen(buffer_switch) scite_OnSwitchFile(buffer_switch) scite_OnMenuCommand(function(cmd, pane) --print('cmd:'..cmd) if cmd == 1418 then buffer_switch("diff") end return false end)