- commit
- 41bcbcb79f40d5810f74069c15dc69e8592c6df5
- parent
- 65a187f2624438b5bb58a84f3a1b766adeb695f6
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-05-29 15:44
move cursor on inserts before the cursor
Diffstat
M | python/pad/__init__.py | 32 | +++++++++++++++++++++++--------- |
1 files changed, 23 insertions, 9 deletions
diff --git a/python/pad/__init__.py b/python/pad/__init__.py
@@ -14,6 +14,23 @@ session = requests.Session() 14 14 pads = {} 15 15 16 16 -1 17 def get_selection(window): -1 18 row, col = window.cursor -1 19 pos = sum([len(line) + 1 for line in window.buffer[:(row - 1)]]) + col -1 20 return [pos, pos] -1 21 -1 22 -1 23 def set_selection(window, selection): -1 24 row, col = 0, selection[0] -1 25 for line in window.buffer: -1 26 if col > len(line): -1 27 col -= len(line) + 1 -1 28 row += 1 -1 29 else: -1 30 window.cursor = row + 1, col -1 31 break -1 32 -1 33 17 34 class Pad: 18 35 def __init__(self, buffer): 19 36 self.id = ''.join(random.sample(string.hexdigits, 6)) @@ -62,8 +79,10 @@ class Pad: 62 79 self.staged_changes = [] 63 80 64 81 def apply_changes(self, changes):65 -1 # var selection = [el.selectionStart, el.selectionEnd, el.selectionDirection];66 -1 selection = None # TODO-1 82 if vim.current.window.buffer == self.buffer: -1 83 selection = get_selection(vim.current.window) -1 84 else: -1 85 selection = None 67 86 text = self.get_text() 68 87 prior = text 69 88 my_changes = [*self.staged_changes, *self.local_changes] @@ -78,14 +97,9 @@ class Pad: 78 97 text = diff.apply(text, change, selection) 79 98 80 99 if text != prior:81 -1 # var scrollTop = el.scrollTop;82 100 self.buffer[:] = text.split('\n')83 -1 # el.selectionStart = selection[0];84 -1 # el.selectionEnd = selection[1];85 -1 # el.selectionDirection = selection[2];86 -1 # requestAnimationFrame(function() {87 -1 # el.scrollTop = scrollTop;88 -1 # });-1 101 if vim.current.window.buffer == self.buffer: -1 102 set_selection(vim.current.window, selection) 89 103 self.old = text 90 104 91 105 def reset_modified(self):