plugins/line_tools/lib/line_tools.rb in redcar-0.11.0dev vs plugins/line_tools/lib/line_tools.rb in redcar-0.11
- old
+ new
@@ -161,11 +161,11 @@
end
doc.replace(doc.offset_at_line(first_line_ix-1), swap_text.split(//).length, new_text)
doc.cursor_offset = insert_idx + cursor_line_offset
if keep_selection
doc.set_selection_range(doc.offset_at_line(first_line_ix-1),
- doc.offset_at_line(last_line_ix-1) + doc.get_line(last_line_ix-1).length - 1)
+ doc.offset_at_inner_end_of_line(last_line_ix-1))
end
doc.scroll_to_line(top)
end
end
end
@@ -177,18 +177,18 @@
doc = tab.edit_view.document
cursor_line_offset = doc.cursor_line_offset
if doc.selection?
first_line_ix = doc.line_at_offset(doc.selection_range.begin)
last_line_ix = doc.line_at_offset(doc.selection_range.end)
-
+
if doc.selection_range.begin == doc.offset_at_inner_end_of_line(first_line_ix)
first_line_ix += 1
end
if doc.selection_range.end == doc.offset_at_line(last_line_ix)
last_line_ix -= 1
end
-
+
text = doc.get_slice(doc.offset_at_line(first_line_ix),
doc.offset_at_line_end(last_line_ix))
keep_selection = true
else
first_line_ix = doc.cursor_line
@@ -209,11 +209,12 @@
doc.controllers(Redcar::AutoIndenter::DocumentController).first.disable do
doc.compound do
doc.replace(doc.offset_at_line(first_line_ix), swap_text.split(//).length, new_text)
doc.cursor_offset = doc.offset_at_line(last_line_ix+1) + cursor_line_offset
if keep_selection
- doc.set_selection_range(doc.offset_at_line(first_line_ix+1),
- doc.offset_at_line(last_line_ix+1) + doc.get_line(last_line_ix+1).length - 1)
+ start_selection = doc.offset_at_line(first_line_ix+1)
+ end_selection = doc.offset_at_inner_end_of_line(last_line_ix+1)
+ doc.set_selection_range(start_selection, end_selection)
end
doc.scroll_to_line(last_line_ix+1)
end
end
end