Thank you for the quick response!
It works exactly as expected and it's even more robust than what I asked for. I was actually planning
to break multi-selection. (So why it hadn't occured to me that sel is an array?)
I've tinkered with it to make it center the cursor when selection is modified:
- Code: Select all
def on_selection_modified(self, view):
def center_cursor(self, view):
sel = view.sel()
region = sel if len(sel) == 1 else None
if region != None:
This may be a bit overkill. It's nice that now the cursor is always centered, but it's very difficult to select text with the mouse. (I think I won't mind if I am writing prose, but I have yet to try it out at length.)
I've had a couple ideas about this (but I haven't looked into them, yet):
- Differentiate between mouseclicks and keypresses. I know FocusWriter uses this strategy, but I don't quite like it. (I found myself having scrolled with the mouse to a location and then, when I started typing, the view reverted to where the cursor was.)
- Differentiate between regular and distraction-free mode, centering on_modified in the former case and on_selection_modified in the latter.
If anyone has used WriteRoom or iA's Writer or any other software which centers the cursor, could you please share strategies for keeping the cursor centered while not breaking (too much) the editor's functionality?
(And thanks again to facelessuser.)