Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

Commit

Permalink
process visual selections as blocks withouth splitting always into li…
Browse files Browse the repository at this point in the history
…nes (GH #26 and #27)
  • Loading branch information
guillermooo committed Oct 16, 2012
1 parent e9f1140 commit 7c9129b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions ex_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ def get_region_by_range(view, line_range=None, split_visual=False):
GLOBAL_RANGES = []
return rv

regions = []
if line_range:
regions = ex_range.new_calculate_range(view, line_range)
regions, visual_regions = ex_range.new_calculate_range(view, line_range)
lines = []
for region in regions:
a, b = region
r = sublime.Region(view.text_point(a - 1, 0),
view.full_line(view.text_point(b - 1, 0)).end())
lines.extend(view.split_by_newlines(r))
view.line(view.text_point(b - 1, 0)).end())
if not visual_regions or split_visual:
lines.extend(view.split_by_newlines(r))
else:
if view.substr(r)[-1] == "\n":
if r.begin() != r.end():
r = sublime.Region(r.begin(), r.end() - 1)
lines.append(r)

return lines

Expand Down
2 changes: 1 addition & 1 deletion plat/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def filter_region(view, txt, command):
script.write('@echo off\ntype %s | %s' % (contents.name, command))
script.close()

p = subprocess.Popen(['cmd.exe', '/C', script.name],
p = subprocess.Popen([script.name],
stdout=subprocess.PIPE,
startupinfo=get_startup_info())

Expand Down
11 changes: 8 additions & 3 deletions vex/ex_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ def calculate_address(view, a):
# todo: 'text_range' key missing
)

a = new_calculate_range(view, fake_range)[0][0] or -1
a, _ = new_calculate_range(view, fake_range)[0][0] or -1
# FIXME: 0 should be a valid address?
if not (0 < a <= view.rowcol(view.size())[0] + 1):
return None
return a - 1


def new_calculate_range(view, r):
"""Calculates line-based ranges (begin_row, end_row) and returns
a tuple: a list of ranges and a boolean indicating whether the ranges
where calculated based on a visual selection.
"""

# FIXME: make sure this works with whitespace between markers, and doublecheck
# with Vim to see whether '<;>' is allowed.
# '<,>' returns all selected line blocks
Expand All @@ -56,7 +61,7 @@ def new_calculate_range(view, r):
start = view.rowcol(sel.begin())[0] + 1
end = view.rowcol(sel.end())[0] + 1
all_line_blocks.append((start, end))
return all_line_blocks
return all_line_blocks, True

# todo: '< and other marks
if r['left_ref'] and (r['left_ref'].startswith("'") or (r['right_ref'] and r['right_ref'].startswith("'"))):
Expand Down Expand Up @@ -104,7 +109,7 @@ def new_calculate_range(view, r):
left = right = calculate_relative_ref(view, '.')

# todo: reverse range automatically if needed
return [(left, right)]
return [(left, right)], False

# Avoid circular import.
from vex import ex_location

0 comments on commit 7c9129b

Please sign in to comment.