Пример #1
0
    def run(self, edit, line_range=CURRENT_LINE_RANGE, forced=False, address=''):
        address_parser = parsers.cmd_line.AddressParser(address)
        parsed_address = address_parser.parse()
        address = ex_range.calculate_address(self.view, parsed_address)
        if address is None:
            ex_error.display_error(ex_error.ERR_INVALID_ADDRESS)
            return

        line_block = []
        for r in get_region_by_range(self.view, line_range=line_range):
            ss = ensure_line_block(self.view, r)
            line_block.append(ss)

        text = ''.join(line_block)
        if address != 0:
            dest = self.view.line(self.view.text_point(address, 0)).end() + 1
        else:
            dest = address
        if dest > self.view.size():
            dest = self.view.size()
            text = '\n' + text[:-1]
        self.view.insert(edit, dest, text)

        self.view.sel().clear()
        cursor_dest = self.view.line(dest + len(text) - 1).begin()
        self.view.sel().add(sublime.Region(cursor_dest, cursor_dest))
Пример #2
0
    def run(self, edit, line_range=None, forced=False, address=''):
        # make sure we have a default range
        if not line_range['text_range']:
            line_range['text_range'] = '.'
        address_parser = parsers.cmd_line.AddressParser(address)
        parsed_address = address_parser.parse()
        address = ex_range.calculate_address(self.view, parsed_address)
        if address is None:
            ex_error.display_error(ex_error.ERR_INVALID_ADDRESS)
            return

        line_block = get_region_by_range(self.view, line_range=line_range)
        line_block = [self.view.substr(r) for r in line_block]

        text = '\n'.join(line_block) + '\n'
        if address != 0:
            dest = self.view.line(self.view.text_point(address, 0)).end() + 1
        else:
            dest = 0

        # Don't move lines onto themselves.
        for sel in self.view.sel():
            if sel.contains(dest):
                ex_error.display_error(ex_error.ERR_CANT_MOVE_LINES_ONTO_THEMSELVES)
                return

        if dest > self.view.size():
            dest = self.view.size()
            text = '\n' + text[:-1]
        self.view.insert(edit, dest, text)

        for r in reversed(get_region_by_range(self.view, line_range)):
            self.view.erase(edit, self.view.full_line(r))
Пример #3
0
    def run(self,
            edit,
            line_range=CURRENT_LINE_RANGE,
            forced=False,
            address=''):
        address_parser = parsers.cmd_line.AddressParser(address)
        parsed_address = address_parser.parse()
        address = ex_range.calculate_address(self.view, parsed_address)
        if address is None:
            ex_error.display_error(ex_error.ERR_INVALID_ADDRESS)
            return

        line_block = []
        for r in get_region_by_range(self.view, line_range=line_range):
            ss = ensure_line_block(self.view, r)
            line_block.append(ss)

        text = ''.join(line_block)
        if address != 0:
            dest = self.view.line(self.view.text_point(address, 0)).end() + 1
        else:
            dest = address
        if dest > self.view.size():
            dest = self.view.size()
            text = '\n' + text[:-1]
        self.view.insert(edit, dest, text)

        self.view.sel().clear()
        cursor_dest = self.view.line(dest + len(text) - 1).begin()
        self.view.sel().add(sublime.Region(cursor_dest, cursor_dest))
Пример #4
0
    def testCalculateAddressCorrectly(self):
        values = (
            (dict(ref='100', offset=None, search_offsets=[]), 99),
            (dict(ref='200', offset=None, search_offsets=[]), 199),
        )

        for v, expected in values:
            self.assertEquals(calculate_address(g_test_view, v), expected)
Пример #5
0
    def testCalculateAddressCorrectly(self):
        values = (
            (dict(ref='100', offset=None, search_offsets=[]), 99),
            (dict(ref='200', offset=None, search_offsets=[]), 199),
        )

        for v, expected in values:
            self.assertEquals(calculate_address(g_test_view, v), expected)
Пример #6
0
    def run(self, edit, line_range=None, forced=False, address=''):
        # make sure we have a default range
        if not line_range['text_range']:
            line_range['text_range'] = '.'
        address_parser = parsers.cmd_line.AddressParser(address)
        parsed_address = address_parser.parse()
        address = ex_range.calculate_address(self.view, parsed_address)
        if address is None:
            ex_error.display_error(ex_error.ERR_INVALID_ADDRESS)
            return

        line_block = []
        for r in get_region_by_range(self.view, line_range=line_range):
            ss = ensure_line_block(self.view, r)
            line_block.append(ss)

        offset = 0
        for r in reversed(
                get_region_by_range(self.view, line_range, split_visual=True)):
            if self.view.rowcol(r.begin())[0] + 1 < address:
                offset += 1
            self.view.erase(edit, self.view.full_line(r))

        text = ''.join(line_block)
        if address != 0:
            dest = self.view.line(self.view.text_point(address - offset,
                                                       0)).end() + 1
        else:
            dest = 0

        if dest > self.view.size():
            dest = self.view.size()
            text = '\n' + text[:-1]
        self.view.insert(edit, dest, text)

        self.view.sel().clear()
        cursor_dest = self.view.line(dest + len(text) - 1).begin()
        self.view.sel().add(sublime.Region(cursor_dest, cursor_dest))
Пример #7
0
    def run(self, edit, line_range=None, forced=False, address=''):
        # make sure we have a default range
        if not line_range['text_range']:
            line_range['text_range'] = '.'
        address_parser = parsers.cmd_line.AddressParser(address)
        parsed_address = address_parser.parse()
        address = ex_range.calculate_address(self.view, parsed_address)
        if address is None:
            ex_error.display_error(ex_error.ERR_INVALID_ADDRESS)
            return

        line_block = []
        for r in get_region_by_range(self.view, line_range=line_range):
            ss = ensure_line_block(self.view, r)
            line_block.append(ss)

        offset = 0
        for r in reversed(get_region_by_range(self.view, line_range, split_visual=True)):
            if self.view.rowcol(r.begin())[0] + 1 < address:
                offset +=  1
            self.view.erase(edit, self.view.full_line(r))

        text = ''.join(line_block)
        if address != 0:
            dest = self.view.line(self.view.text_point(
                                                address - offset, 0)).end() + 1
        else:
            dest = 0

        if dest > self.view.size():
            dest = self.view.size()
            text = '\n' + text[:-1]
        self.view.insert(edit, dest, text)

        self.view.sel().clear()
        cursor_dest = self.view.line(dest + len(text) - 1).begin()
        self.view.sel().add(sublime.Region(cursor_dest, cursor_dest))
Пример #8
0
 def testOutOfBoundsAddressShouldReturnNone(self):
     address = dict(ref='1000', offset=None, search_offsets=[])
     self.assertEquals(calculate_address(g_test_view, address), None)
Пример #9
0
 def testOutOfBoundsAddressShouldReturnNone(self):
     address = dict(ref='1000', offset=None, search_offsets=[])
     self.assertEquals(calculate_address(g_test_view, address), None)