##// END OF EJS Templates
refactor to improve cell switching in edit mode...
refactor to improve cell switching in edit mode This code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell. TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell prior to this, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above. The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

File last commit:

r13392:bace1f46
r15754:d60e793e
Show More
strdispatch.py
68 lines | 1.8 KiB | text/x-python | PythonLexer
Fernando Perez
Turn little test into proper doctest. Cleanup and document.
r1417 """String dispatch class to match regexps and dispatch commands.
"""
# Stdlib imports
import re
# Our own modules
Brian Granger
hooks.py => core/hooks.py and updated imports.
r2026 from IPython.core.hooks import CommandChainDispatcher
vivainio
merge all from 0.7.3 branch to trunk
r503
Fernando Perez
Turn little test into proper doctest. Cleanup and document.
r1417 # Code begins
vivainio
merge all from 0.7.3 branch to trunk
r503 class StrDispatch(object):
Fernando Perez
Turn little test into proper doctest. Cleanup and document.
r1417 """Dispatch (lookup) a set of strings / regexps for match.
Example:
>>> dis = StrDispatch()
>>> dis.add_s('hei',34, priority = 4)
>>> dis.add_s('hei',123, priority = 2)
>>> dis.add_re('h.i', 686)
Thomas Kluyver
Fix tests in IPython.utils
r13392 >>> print(list(dis.flat_matches('hei')))
Fernando Perez
Turn little test into proper doctest. Cleanup and document.
r1417 [123, 34, 686]
"""
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
merge all from 0.7.3 branch to trunk
r503 def __init__(self):
self.strs = {}
self.regexs = {}
Fernando Perez
Turn little test into proper doctest. Cleanup and document.
r1417
vivainio
merge all from 0.7.3 branch to trunk
r503 def add_s(self, s, obj, priority= 0 ):
""" Adds a target 'string' for dispatching """
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
merge all from 0.7.3 branch to trunk
r503 chain = self.strs.get(s, CommandChainDispatcher())
chain.add(obj,priority)
self.strs[s] = chain
def add_re(self, regex, obj, priority= 0 ):
""" Adds a target regexp for dispatching """
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
merge all from 0.7.3 branch to trunk
r503 chain = self.regexs.get(regex, CommandChainDispatcher())
chain.add(obj,priority)
self.regexs[regex] = chain
def dispatch(self, key):
""" Get a seq of Commandchain objects that match key """
if key in self.strs:
yield self.strs[key]
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
merge all from 0.7.3 branch to trunk
r503 for r, obj in self.regexs.items():
if re.match(r, key):
yield obj
Bernardo B. Marques
remove all trailling spaces
r4872 else:
Fernando Perez
Turn little test into proper doctest. Cleanup and document.
r1417 #print "nomatch",key # dbg
vivainio
merge all from 0.7.3 branch to trunk
r503 pass
def __repr__(self):
return "<Strdispatch %s, %s>" % (self.strs, self.regexs)
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
merge all from 0.7.3 branch to trunk
r503 def s_matches(self, key):
if key not in self.strs:
return
for el in self.strs[key]:
yield el[1]
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
merge all from 0.7.3 branch to trunk
r503 def flat_matches(self, key):
""" Yield all 'value' targets, without priority """
for val in self.dispatch(key):
for el in val:
yield el[1] # only value, no priority
return