When moving down a text editor line-by-line, I rely on the common behavior
of automatically moving to the end of the line when trying to scroll down
past the last line. Similar for when scrolling up past the first line. Leo
doesn't have this behavior, so I wrote the below script. Thought I'd share
in case anyone else finds it useful.

@settings->@shortcuts:
previous-or-beginning-of-line ! text = Up
next-or-end-of-line ! text = Down
previous-or-beginning-of-line-extend-selection ! text = Shift-Up
next-or-end-of-line-extend-selection ! text = Shift-Down


@script

def lineScrollHelper(c, prefix1, prefix2, suffix):
    w = c.frame.body.wrapper
    ins = w.getInsertPoint()
    c.inCommand = False
    c.executeMinibufferCommand(prefix1 + 'line' + suffix)
    ins2 = w.getInsertPoint()

    # If the cursor didn't change, then go to beginning/end of line

    if ins == ins2:
        c.executeMinibufferCommand(prefix2 + 'of-line' + suffix)

@g.command('next-or-end-of-line')
def nextOrEndOfLine(event):
    lineScrollHelper(event['c'], 'next-', 'end-', '')

@g.command('previous-or-beginning-of-line')
def previousOrBeginningOfLine(event):
    lineScrollHelper(event['c'], 'previous-', 'beginning-', '')

@g.command('next-or-end-of-line-extend-selection')
def nextOrEndOfLineExtendSelection(event):
    lineScrollHelper(event['c'], 'next-', 'end-', '-extend-selection')

@g.command('previous-or-beginning-of-line-extend-selection')
def previousOrBeginningOfLineExtendSelection(event):
    lineScrollHelper(event['c'], 'previous-', 'beginning-',
'-extend-selection')

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAO5X8CyVRMJ%2BO0tU%3D-7MAm6qhsELhj3kV4N8X33YOh2EL%3DuhEg%40mail.gmail.com.

Reply via email to