Skip to content

Commit 1f054da

Browse files
committed
Added unit tests and fixed some synchronization issues.
1 parent 5cc3a18 commit 1f054da

File tree

3 files changed

+450
-9
lines changed

3 files changed

+450
-9
lines changed

.luacov

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include = {'file_diff'}
2+
exclude = {'_test'}

init.lua

+11-9
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
local M = {}
5050

5151
--- The marker for line additions.
52-
M.MARK_ADDITION = _SCINTILLA.new_marker_number()
52+
M.MARK_ADDITION = view.new_marker_number()
5353
--- The marker for line deletions.
54-
M.MARK_DELETION = _SCINTILLA.new_marker_number()
54+
M.MARK_DELETION = view.new_marker_number()
5555
--- The marker for line modifications.
56-
M.MARK_MODIFICATION = _SCINTILLA.new_marker_number()
56+
M.MARK_MODIFICATION = view.new_marker_number()
5757
--- The indicator number for text added within lines.
58-
M.INDIC_ADDITION = _SCINTILLA.new_indic_number()
58+
M.INDIC_ADDITION = view.new_indic_number()
5959
--- The indicator number for text deleted within lines.
60-
M.INDIC_DELETION = _SCINTILLA.new_indic_number()
60+
M.INDIC_DELETION = view.new_indic_number()
6161
local MARK_ADDITION = M.MARK_ADDITION
6262
local MARK_DELETION = M.MARK_DELETION
6363
local MARK_MODIFICATION = M.MARK_MODIFICATION
@@ -295,12 +295,12 @@ local starting_diff = false
295295
function M.start(file1, file2, horizontal)
296296
file1 = file1 or ui.dialogs.open{
297297
title = _L['Select the first file to compare'],
298-
dir = (buffer.filename or ''):match('^.+[/\\]') or lfs.currentdir()
298+
dir = (buffer.filename or ''):match('^(.+)[/\\]') or lfs.currentdir()
299299
}
300300
if not file1 then return end
301301
file2 = file2 or ui.dialogs.open{
302302
title = string.format('%s %s', _L['Select the file to compare to'], file1:match('[^/\\]+$')),
303-
dir = file1:match('^.+[/\\]') or lfs.currentdir()
303+
dir = file1:match('^(.+)[/\\]') or lfs.currentdir()
304304
}
305305
if not file2 then return end
306306
starting_diff = true
@@ -338,9 +338,11 @@ events.connect(events.BUFFER_DELETED, stop)
338338
-- @return line
339339
local function get_synchronized_line(line)
340340
local visible_line = view:visible_from_doc_line(line)
341+
local pos = buffer.current_pos
341342
ui.goto_view(view == view1 and view2 or view1)
342343
line = view:doc_line_from_visible(visible_line)
343344
ui.goto_view(view == view2 and view1 or view2)
345+
buffer:set_empty_selection(pos)
344346
return line
345347
end
346348

@@ -431,9 +433,10 @@ function M.merge(left)
431433
local line = get_synchronized_line(start_line) + 1
432434
if (view == view1 and buffer2 or buffer1):marker_get(line) & diff_marker > 0 then
433435
ui.goto_view(view == view1 and view2 or view1)
434-
buffer:line_down()
436+
buffer:set_empty_selection(buffer:position_from_line(line))
435437
M.merge(left)
436438
ui.goto_view(view == view2 and view1 or view2)
439+
buffer:set_empty_selection(buffer:position_from_line(start_line))
437440
end
438441
return
439442
end
@@ -466,7 +469,6 @@ function M.merge(left)
466469
start_line = get_synchronized_line(start_line)
467470
end_line = get_synchronized_line(end_line)
468471
ui.goto_view(view == view1 and view2 or view1)
469-
if buffer.annotation_text[end_line] ~= '' then end_line = end_line + 1 end
470472
buffer.target_start = buffer:position_from_line(start_line)
471473
buffer.target_end = buffer:position_from_line(end_line)
472474
if view == view2 and left or view == view1 and not left then

0 commit comments

Comments
 (0)