mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-03-01 18:53:33 +01:00
De-activate snippet without needing an extra Ctrl+Tab if the last placeholder has no mirrors/transforms
This commit is contained in:
parent
a5a3ef3b02
commit
4e140ea27d
1 changed files with 16 additions and 0 deletions
|
|
@ -159,6 +159,8 @@ def __init__(self, left, tab_stops, editor):
|
|||
self.mirrors = tuple(EditorTabStop(left, [ts], editor) for ts in tab_stops[1:])
|
||||
self.ignore_position_update = False
|
||||
self.join_previous_edit = False
|
||||
self.transform = None
|
||||
self.has_transform = self.transform is not None
|
||||
|
||||
def __enter__(self):
|
||||
self.join_previous_edit = True
|
||||
|
|
@ -271,6 +273,8 @@ def jump_to_next(self, editor):
|
|||
return ts
|
||||
ts = self.active_tab_stop
|
||||
if not ts.is_deleted:
|
||||
if ts.has_transform:
|
||||
ts.text = ts.transform(ts.text)
|
||||
for m in ts.mirrors:
|
||||
if not m.is_deleted:
|
||||
m.text = ts.text
|
||||
|
|
@ -280,6 +284,15 @@ def jump_to_next(self, editor):
|
|||
x.set_editor_cursor(editor)
|
||||
return x
|
||||
|
||||
def remains_active(self):
|
||||
if self.active_tab_stop is None:
|
||||
return False
|
||||
ts = self.active_tab_stop
|
||||
for x in self:
|
||||
if x.num > ts.num and not x.is_deleted:
|
||||
return True
|
||||
return bool(ts.mirrors) or ts.has_transform
|
||||
|
||||
def find_closest_tab_stop(self, position):
|
||||
ans = dist = None
|
||||
for c in self:
|
||||
|
|
@ -346,6 +359,9 @@ def handle_key_press(self, ev):
|
|||
if at is not None:
|
||||
if at.jump_to_next(editor) is None:
|
||||
self.active_templates.remove(at)
|
||||
else:
|
||||
if not at.remains_active():
|
||||
self.active_templates.remove(at)
|
||||
ev.accept()
|
||||
return True
|
||||
lst, self.last_selected_text = self.last_selected_text, editor.selected_text
|
||||
|
|
|
|||
Loading…
Reference in a new issue