示例#1
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            if text.endswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).a, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).a, text, count)
            else:
                self.paste_all(edit, s, s.b + offset, text, count)
                offset += len(text) * count
 def f(view, s):
     if (s.a > s.b and utils.is_at_eol(self.view, s) and not s.b == 0):
             return utils.forward_end_one_char(s)
     elif (s.a < s.b and utils.is_at_hard_eol(self.view, s)):
             return sublime.Region(s.a, s.b + 1)
     else:
         return s
示例#3
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            text = self.prepare_fragment(text)
            if text.startswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).b, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).b, text, count)
            else:
                # XXX: Refactor this whole class. It's getting out of hand.
                if self.view.substr(s.b) == '\n':
                    self.paste_all(edit, s, s.b + offset, text, count)
                else:
                    self.paste_all(edit, s, s.b + offset + 1, text, count)
                offset += len(text) * count
示例#4
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)
        register = register or '"'
        fragments = state.registers[register]
        if not fragments:
            print("Vintageous: Nothing in register \".")
            return

        sels = list(self.view.sel())
        # If we have the same number of pastes and selections, map 1:1. Otherwise paste paste[0]
        # to all target selections.
        if len(sels) == len(fragments):
            sel_to_frag_mapped = zip(sels, fragments)
        else:
            sel_to_frag_mapped = zip(sels, [fragments[0],] * len(sels))

        # FIXME: Fix this mess. Separate linewise from charwise pasting.
        pasting_linewise = True
        offset = 0
        paste_locations = []
        for selection, fragment in reversed(list(sel_to_frag_mapped)):
            fragment = self.prepare_fragment(fragment)
            if fragment.startswith('\n'):
                # Pasting linewise...
                # If pasting at EOL or BOL, make sure we paste before the newline character.
                if (utils.is_at_eol(self.view, selection) or
                    utils.is_at_bol(self.view, selection)):
                    l = self.paste_all(edit, selection,
                                       self.view.line(selection.b).b,
                                       fragment,
                                       count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, selection,
                                   self.view.line(selection.b - 1).b,
                                   fragment,
                                   count)
                    paste_locations.append(l)
            else:
                pasting_linewise = False
                # Pasting charwise...
                # If pasting at EOL, make sure we don't paste after the newline character.
                if self.view.substr(selection.b) == '\n':
                    l = self.paste_all(edit, selection, selection.b + offset,
                                   fragment, count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, selection, selection.b + offset + 1,
                                   fragment, count)
                    paste_locations.append(l)
                offset += len(fragment) * count

        if pasting_linewise:
            self.reset_carets_linewise()
        else:
            self.reset_carets_charwise(paste_locations, len(fragment))
示例#5
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if state.mode == MODE_VISUAL:
            # force register population. We have to do it here
            vi_cmd_data = {
                "synthetize_new_line_at_eof": True,
                "yanks_linewise": False,
            }
            prev_text = state.registers.get_selected_text(vi_cmd_data)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        if state.mode == MODE_VISUAL:
            # Populate registers with the text we're about to paste.
            state.registers['"'] = prev_text

        sels = list(self.view.sel())
        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        pasting_linewise = True
        offset = 0
        paste_locations = []
        for s, text in sel_frag:
            row = self.view.rowcol(s.begin())[0]
            row = max(0, row - 1)
            if text.endswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    l = self.paste_all(edit, s, self.view.line(s.b).a, text, count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, s, self.view.line(s.b - 1).a, text, count)
                    paste_locations.append(l)
            else:
                pasting_linewise = False
                l = self.paste_all(edit, s, s.b + offset, text, count)
                paste_locations.append(l)
                offset += len(text) * count

        if pasting_linewise:
            self.reset_carets_linewise()
        else:
            self.reset_carets_charwise(paste_locations, len(text))
示例#6
0
    def run(self, edit, extend=False):
        state = VintageState(self.view)
        state.enter_insert_mode()

        visual = self.view.has_non_empty_selection_region()

        sels = list(self.view.sel())
        self.view.sel().clear()

        new_sels = []
        for s in sels:
            if visual:
                new_sels.append(sublime.Region(s.end(), s.end()))
            else:
                if not utils.is_at_eol(self.view, s):
                    new_sels.append(sublime.Region(s.end() + 1, s.end() + 1))
                else:
                    new_sels.append(sublime.Region(s.end(), s.end()))

        for s in new_sels:
            self.view.sel().add(s)
示例#7
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']
            if not fragments:
                print("Vintageous: Nothing in register \".")
                # XXX: This won't ever be printed because it will be overwritten by other status
                # messages printed right after this one.
                sublime.status_message("Vintageous: Nothing in register \".")
                return

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            text = self.prepare_fragment(text)
            if text.startswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).b, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).b, text, count)
            else:
                # XXX: Refactor this whole class. It's getting out of hand.
                if self.view.substr(s.b) == '\n':
                    self.paste_all(edit, s, s.b + offset, text, count)
                else:
                    self.paste_all(edit, s, s.b + offset + 1, text, count)
                offset += len(text) * count
示例#8
0
 def f(view, s):
     if view.size() > 0 and is_at_eol(self.view, s):
         return forward_one_char(s)
     else:
         return s
示例#9
0
 def f(view, s):
     if is_at_eol(self.view, s) and not self.view.line(s.b).empty():
         s = back_one_char(s)
     # s = next_non_white_space_char(self.view, s.b)
     return s
示例#10
0
 def f(view, s):
     if is_at_eol(self.view, s) and not self.view.line(s.b).empty():
         return back_one_char(s)
     else:
         return s
示例#11
0
 def f(view, s):
     if is_at_eol(self.view, s):
         return forward_one_char(s)
     else:
         return s
示例#12
0
 def f(view, s):
     if not is_on_empty_line(self.view, s) and is_at_eol(self.view, s):
         return back_one_char(s)
     else:
         return s