@@ -10,7 +10,7 @@ class History:
1010 history_next - Bound to <<history-next>> event (default Alt-N).
1111 history_prev - Bound to <<history-prev>> event (default Alt-P).
1212 '''
13- def __init__ (self , text , output_sep = " \n " ):
13+ def __init__ (self , text ):
1414 '''Initialize data attributes and bind event methods.
1515
1616 .text - Idle wrapper of tk Text widget, with .bell().
@@ -23,7 +23,6 @@ def __init__(self, text, output_sep = "\n"):
2323 self .history = []
2424 self .prefix = None
2525 self .pointer = None
26- self .output_sep = output_sep
2726 self .cyclic = idleConf .GetOption ("main" , "History" , "cyclic" , 1 , "bool" )
2827 text .bind ("<<history-previous>>" , self .history_prev )
2928 text .bind ("<<history-next>>" , self .history_next )
@@ -38,16 +37,6 @@ def history_prev(self, event):
3837 self .fetch (reverse = True )
3938 return "break"
4039
41- def _get_source (self , start , end ):
42- # Get source code from start index to end index. Lines in the
43- # text control may be separated by sys.ps2 .
44- lines = self .text .get (start , end ).split (self .output_sep )
45- return "\n " .join (lines )
46-
47- def _put_source (self , where , source ):
48- output = self .output_sep .join (source .split ("\n " ))
49- self .text .insert (where , output )
50-
5140 def fetch (self , reverse ):
5241 '''Fetch statememt and replace current line in text widget.
5342
@@ -61,10 +50,11 @@ def fetch(self, reverse):
6150 prefix = self .prefix
6251 if pointer is not None and prefix is not None :
6352 if self .text .compare ("insert" , "!=" , "end-1c" ) or \
64- self ._get_source ("iomark" , "end-1c" ) != self .history [pointer ]:
53+ self .text . get ("iomark" , "end-1c" ) != self .history [pointer ]:
6554 pointer = prefix = None
55+ self .text .mark_set ("insert" , "end-1c" ) # != after cursor move
6656 if pointer is None or prefix is None :
67- prefix = self ._get_source ("iomark" , "end-1c" )
57+ prefix = self .text . get ("iomark" , "end-1c" )
6858 if reverse :
6959 pointer = nhist # will be decremented
7060 else :
@@ -75,26 +65,22 @@ def fetch(self, reverse):
7565 return
7666 nprefix = len (prefix )
7767 while 1 :
78- if reverse :
79- pointer = pointer - 1
80- else :
81- pointer = pointer + 1
68+ pointer += - 1 if reverse else 1
8269 if pointer < 0 or pointer >= nhist :
8370 self .text .bell ()
8471 if not self .cyclic and pointer < 0 : # abort history_prev
8572 return
8673 else :
87- if self ._get_source ("iomark" , "end-1c" ) != prefix :
74+ if self .text . get ("iomark" , "end-1c" ) != prefix :
8875 self .text .delete ("iomark" , "end-1c" )
89- self ._put_source ("iomark" , prefix )
76+ self .text . insert ("iomark" , prefix )
9077 pointer = prefix = None
9178 break
9279 item = self .history [pointer ]
9380 if item [:nprefix ] == prefix and len (item ) > nprefix :
9481 self .text .delete ("iomark" , "end-1c" )
95- self ._put_source ("iomark" , item )
82+ self .text . insert ("iomark" , item )
9683 break
97- self .text .mark_set ("insert" , "end-1c" )
9884 self .text .see ("insert" )
9985 self .text .tag_remove ("sel" , "1.0" , "end" )
10086 self .pointer = pointer
0 commit comments