Anonymous avatar Anonymous committed 13542f5

implemented text inserting and deleting

Comments (0)

Files changed (1)

             values = list(values)
             values.remove(default)
             values.insert(0, default)
-        numbered = [prompt]
+        numbered = [str(prompt)]
         for index, value in enumerate(values):
-            numbered.append('%s. %s' % (index + 1, value))
+            numbered.append('%s. %s' % (index + 1, str(value)))
         result = int(call('inputlist(%s)' % numbered))
         if result != 0:
             return values[result - 1]
         vim.current.window.cursor = (lineno, 0)
 
     def insert_line(self, line, lineno):
-        vim.current.buffer[lineno:lineno] = line
+        vim.current.buffer[lineno - 1:lineno - 1] = [line]
 
     def insert(self, text):
-        pass
+        lineno, colno = vim.current.window.cursor
+        print lineno, colno
+        line = vim.current.buffer[lineno - 1]
+        vim.current.buffer[lineno - 1] = line[:colno] + text + line[colno:]
+        vim.current.window.cursor = (lineno, colno + len(text))
 
     def delete(self, start, end):
-        pass
+        lineno1, colno1 = self._get_position(start)
+        lineno2, colno2 = self._get_position(end)
+        lineno, colno = vim.current.window.cursor
+        if lineno1 == lineno2:
+            line = vim.current.buffer[lineno1 - 1]
+            vim.current.buffer[lineno1 - 1] = line[:colno1] + line[colno2:]
+            if lineno == lineno1 and colno >= colno1:
+                diff = colno2 - colno1
+                vim.current.window.cursor = (lineno, max(0, colno - diff))
+
+    def _get_position(self, offset):
+        text = self.get_text()
+        lineno = text.count('\n', 0, offset) + 1
+        try:
+            colno = offset - text.rindex('\n', 0, offset) - 2
+        except ValueError:
+            colno = offset
+        return lineno, colno
 
     def filenames(self):
         result = []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.