Merge pull request #348 from prculley/undo
bug 9927; fix UndoableEntry for pygobject bug
This commit is contained in:
commit
b58ac2da8a
@ -51,7 +51,7 @@ from .undoablebuffer import Stack
|
|||||||
|
|
||||||
class UndoableInsertEntry:
|
class UndoableInsertEntry:
|
||||||
"""something that has been inserted into our Gtk.editable"""
|
"""something that has been inserted into our Gtk.editable"""
|
||||||
def __init__(self, text, length, position, editable):
|
def __init__(self, text, length, position):
|
||||||
self.offset = position
|
self.offset = position
|
||||||
self.text = text
|
self.text = text
|
||||||
#unicode char can have length > 1 as it points in the buffer
|
#unicode char can have length > 1 as it points in the buffer
|
||||||
@ -80,7 +80,7 @@ class UndoableDeleteEntry:
|
|||||||
else:
|
else:
|
||||||
self.mergeable = True
|
self.mergeable = True
|
||||||
|
|
||||||
class UndoableEntry(Gtk.Entry):
|
class UndoableEntry(Gtk.Entry, Gtk.Editable):
|
||||||
"""
|
"""
|
||||||
The UndoableEntry is an Entry subclass with additional features.
|
The UndoableEntry is an Entry subclass with additional features.
|
||||||
|
|
||||||
@ -102,7 +102,6 @@ class UndoableEntry(Gtk.Entry):
|
|||||||
self.not_undoable_action = False
|
self.not_undoable_action = False
|
||||||
self.undo_in_progress = False
|
self.undo_in_progress = False
|
||||||
|
|
||||||
self.connect('insert-text', self._on_insert_text)
|
|
||||||
self.connect('delete-text', self._on_delete_text)
|
self.connect('delete-text', self._on_delete_text)
|
||||||
self.connect('key-press-event', self._on_key_press_event)
|
self.connect('key-press-event', self._on_key_press_event)
|
||||||
|
|
||||||
@ -134,7 +133,7 @@ class UndoableEntry(Gtk.Entry):
|
|||||||
def __empty_redo_stack(self):
|
def __empty_redo_stack(self):
|
||||||
self.redo_stack = []
|
self.redo_stack = []
|
||||||
|
|
||||||
def _on_insert_text(self, editable, text, length, positionptr):
|
def do_insert_text(self, text, length, position):
|
||||||
def can_be_merged(prev, cur):
|
def can_be_merged(prev, cur):
|
||||||
"""
|
"""
|
||||||
see if we can merge multiple inserts here
|
see if we can merge multiple inserts here
|
||||||
@ -159,26 +158,27 @@ class UndoableEntry(Gtk.Entry):
|
|||||||
|
|
||||||
if not self.undo_in_progress:
|
if not self.undo_in_progress:
|
||||||
self.__empty_redo_stack()
|
self.__empty_redo_stack()
|
||||||
if self.not_undoable_action:
|
while not self.not_undoable_action:
|
||||||
return
|
undo_action = self.insertclass(text, length, self.get_position())
|
||||||
undo_action = self.insertclass(text, length, editable.get_position(),
|
try:
|
||||||
editable)
|
prev_insert = self.undo_stack.pop()
|
||||||
try:
|
except IndexError:
|
||||||
prev_insert = self.undo_stack.pop()
|
self.undo_stack.append(undo_action)
|
||||||
except IndexError:
|
break
|
||||||
self.undo_stack.append(undo_action)
|
if not isinstance(prev_insert, self.insertclass):
|
||||||
return
|
self.undo_stack.append(prev_insert)
|
||||||
if not isinstance(prev_insert, self.insertclass):
|
self.undo_stack.append(undo_action)
|
||||||
self.undo_stack.append(prev_insert)
|
break
|
||||||
self.undo_stack.append(undo_action)
|
if can_be_merged(prev_insert, undo_action):
|
||||||
return
|
prev_insert.length += undo_action.length
|
||||||
if can_be_merged(prev_insert, undo_action):
|
prev_insert.text += undo_action.text
|
||||||
prev_insert.length += undo_action.length
|
self.undo_stack.append(prev_insert)
|
||||||
prev_insert.text += undo_action.text
|
else:
|
||||||
self.undo_stack.append(prev_insert)
|
self.undo_stack.append(prev_insert)
|
||||||
else:
|
self.undo_stack.append(undo_action)
|
||||||
self.undo_stack.append(prev_insert)
|
break
|
||||||
self.undo_stack.append(undo_action)
|
self.get_buffer().insert_text(position, text, length)
|
||||||
|
return position + length
|
||||||
|
|
||||||
def _on_delete_text(self, editable, start, end):
|
def _on_delete_text(self, editable, start, end):
|
||||||
def can_be_merged(prev, cur):
|
def can_be_merged(prev, cur):
|
||||||
|
Loading…
Reference in New Issue
Block a user