Skip to content

Commit 4412580

Browse files
authored
Merge pull request #2 from bordaigorl/master
More useful handling of multiple selection
2 parents fc07e55 + 22de3c1 commit 4412580

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

Alignment.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,32 @@ def align_lines(line_nums):
248248

249249
# This handles aligning multiple selections
250250
else:
251-
max_col = max([normed_rowcol(view, region.b)[1] for region in sel])
252-
253-
for region in sel:
254-
length = max_col - normed_rowcol(view, region.b)[1]
255-
view.insert(edit, region.b, ' ' * length)
251+
# BORDAIGORL: handle multiple regions by independently aligning the n-th cursor of each line
252+
# Example (| is cursor position):
253+
# a|bbb|cc
254+
# AA|B|C
255+
# turns into
256+
# a |bbb|c
257+
# AA|B |C
258+
col = {}
259+
curline = view.rowcol(sel[0].begin())[0]
260+
j=0
261+
for i in range(0,len(sel)):
262+
ln = view.rowcol(sel[i].begin())[0]
263+
if ln != curline:
264+
j=0
265+
curline = ln
266+
if j in col.keys():
267+
col[j].append(i)
268+
else:
269+
col[j] = [i]
270+
j+=1
271+
for j in col.keys():
272+
max_col = max([normed_rowcol(view, sel[i].b)[1] for i in col[j]])
273+
for i in col[j]:
274+
region = sel[i]
275+
length = max_col - normed_rowcol(view, region.begin())[1]
276+
view.insert(edit, region.begin(), ' ' * length)
256277
if settings.get('mid_line_tabs') and not use_spaces:
257-
convert_to_mid_line_tabs(view, edit, tab_size, region.b,
258-
length)
278+
convert_to_mid_line_tabs(view, edit, tab_size, region.begin(), length)
279+

0 commit comments

Comments
 (0)