示例#1
0
    def move(self):
        view = self.view
        doc = view.document
        y, x = view.cursor_pos

        if y == doc.num_lines - 1:
           return

        y += 1
        line = doc.get_line(y)
        if tab_len(line, doc.tab_size) > view.last_x_pos:
            x = tab_pos_to_char_pos(line, view.last_x_pos, doc.tab_size)
        else:
            x = len(line)

        view.cursor_pos = (y, x)
示例#2
0
    def move(self):
        view = self.view
        doc = view.document
        y, x = self.newpos

        # we're explicitely setting x, so update last_x_pos
        view.last_x_pos = x

        # try and set where we clicked, otherwise set x to the end of the line
        line = doc.get_line(y)
        if tab_len(line, doc.tab_size) > view.last_x_pos:
            x = tab_pos_to_char_pos(line, view.last_x_pos, doc.tab_size)
        else:
            x = len(line)

        view.cursor_pos = (y, x)
示例#3
0
    def do(self):
        view = self.view
        doc = view.document

        # if there's a selection when the user types, it should be deleted
        # first so that we "override" it
        if view.selection:
            self.delete_selection()

        offset = doc.cursor_pos_to_offset(view.cursor_pos)
                
        d = InsertDelta(doc, offset, self.text)
        d.do()
        self.deltas.append(d)
        
        offset += tab_len(self.text, doc.tab_size)
        view.cursor_pos = doc.offset_to_cursor_pos(offset)        
示例#4
0
文件: editor.py 项目: lerouxb/ni
    def update_status(self):
        view = self.textarea.view
        doc = view.document

        if doc.tokenizer.lexer:
            mode = doc.tokenizer.lexer.name
        else:
            mode = "plain"

        y, x = view.cursor_pos

        line = doc.get_line(y)
        x = tab_len(line[:x], doc.tab_size)
        x += 1
        y += 1

        if doc.is_modified:
            modified = '*MODIFIED* '
            title = view.document.description+' (modified)'
        else:
            modified = ''
            title = view.document.description

        #if self.workspace and view.document.location:
        #    root_path = self.workspace.root_path
        #    if view.document.location[:len(root_path)] == root_path:
        #        title = "[workspace: %s] %s" % (self.workspace.name, title)

        # for now always put the workspace name in the titlebar (even if the
        # current file isn't part of the workspace)
        #if self.workspace:
        #    title = "%s | %s" % (title, self.workspace.name)

        self.window.set_title(title)

        # TODO: we have linesep_map variables all over the place... clean up.
        linesep_map = {'\n': 'UNIX', '\r\n': 'DOS/Windows', '\r': 'MacOS'}
        sep_type = linesep_map[doc.linesep or self.settings.linesep]

        self.status_modified.set_text(modified)
        self.status_position.set_text("Ln %s, Col %s" % (y, x))
        self.status_lexer.set_label(mode)
        self.status_linesep.set_text(sep_type)
        self.status_encoding.set_text(doc.encoding.upper())
示例#5
0
文件: test_text.py 项目: lerouxb/ni
def test_tab_len():
    assert tab_len('\t', 8) == 8