Ctrl+Shift+End ?

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
avenger
Posts: 18
Joined: Wed Aug 03, 2016 11:56 am

Ctrl+Shift+End ?

Post by avenger » Tue Aug 23, 2016 4:08 pm

Using the latest release of Zeus to date (in Win 10), I've been looking through the list of keyboard functions in help and have "cut my teeth" a bit modifying keyboard templates for other purposes. Now, I want to enable [Ctrl]+[Shift]+[End] as a "select starting at the current cursor position through to the end of the doc" similar to default behaviors in Notepad, EditPad Pro, Notepad++, EmEditor, Visual Studio, etc. Can anyone suggest a good way to do this :?: Thank you in advance :!:

jussij
Site Admin
Posts: 2512
Joined: Fri Aug 13, 2004 5:10 pm

Re: Ctrl+Shift+End ?

Post by jussij » Wed Aug 24, 2016 1:33 am

The easiest way to do things like this is to just create a macro and bind it to the keybaord.

This is what you need to do:

1. Start macro recording

2. Replicate the steps required using the keyboard

3. Stop macro recording

4. Save the macro to file

5. Bind that macro to the keyboard

If I do this I get this macro:

Code: Select all

function key_macro()
    screen_update_disable()
    MarkBlockSet()
    MoveDocumentEndEx()
    MoveDocumentEndEx()
    screen_update_enable()
    screen_update()
end

key_macro() -- run the macro
NOTE: The macro that was actually recorded had MarkBlockToggle but I changed it to MarkBlockSet.

I would then clean up the macro and make it a little more robust as shown below:

Code: Select all

function key_macro()
    -- macro only works for documents
    local document = is_document()

    if (document == 0) then
        message("This macro only works for documents.");
        beep();
        return;
    end

    screen_update_disable()
    MarkBlockSet()
    MoveDocumentEndEx()
    MoveDocumentEndEx()
    screen_update_enable()
    screen_update()
end

key_macro() -- run the macro
Cheers Jussi

avenger
Posts: 18
Joined: Wed Aug 03, 2016 11:56 am

Re: Ctrl+Shift+End ?

Post by avenger » Wed Aug 24, 2016 11:46 am

Very cool. Thank you very kindly for both your time and example(s). I appreciate it. :)

avenger
Posts: 18
Joined: Wed Aug 03, 2016 11:56 am

Re: Ctrl+Shift+End ?

Post by avenger » Wed Aug 24, 2016 12:18 pm

I modified your second example slightly, using only one MoveDocumentEnd() - I found I had to use (3) MoveDocumentEndEx() calls in a COBOL file for whatever reason. Although I have the "Keypress removes mark" mapping option selected, up, down, right or left arrow (only) keypresses adjust the marked block rather than dispensing/removing the selection as I would have hoped.

avenger
Posts: 18
Joined: Wed Aug 03, 2016 11:56 am

Re: Ctrl+Shift+End ?

Post by avenger » Wed Aug 24, 2016 12:35 pm

I guess another thing that fails in this example is that, after I make a selection using a macro such as this, the moment I use my mouse to scroll the window, my selection disappears. So a selection made this way is different than other selections. For example, if I make a selection using my mouse by clicking (and holding) and dragging my mouse, release the button and then scroll, my selection remains highlighted. Similarly, if I press [Shift]+[End] to select a portion of a line and then scroll using my mouse, the selection remains highlighted. Using a macro such as the above, when I press [Ctrl]+[Shift]+[End], I see my selection but when I scroll with my mouse, viola! the selection is gone. :(

avenger
Posts: 18
Joined: Wed Aug 03, 2016 11:56 am

Re: Ctrl+Shift+End ?

Post by avenger » Wed Aug 24, 2016 12:43 pm

Regarding my reply:
"I modified your second example slightly, using only one MoveDocumentEnd() - I found I had to use (3) MoveDocumentEndEx() calls in a COBOL file for whatever reason. Although I have the "Keypress removes mark" mapping option selected, up, down, right or left arrow (only) keypresses adjust the marked block rather than dispensing/removing the selection as I would have hoped."

Sorry to be a PITA. I figured this out by adding a MarkBlockToggleEx() call so I now have:

Code: Select all

function SelectCursorToDocEnd()
    local document = is_document()
    if (document == 0) then
        return
    end
    
    screen_update_disable()
    MarkBlockSet()
    MoveDocumentEnd()
    screen_update_enable()
    screen_update()
    MarkBlockToggleEx()
end

SelectCursorToDocEnd() -- run the macro
The selection still disappears when I scroll using my mouse wheel, though.

jussij
Site Admin
Posts: 2512
Joined: Fri Aug 13, 2004 5:10 pm

Re: Ctrl+Shift+End ?

Post by jussij » Wed Aug 24, 2016 1:56 pm

I modified your second example slightly, using only one MoveDocumentEnd
The MoveDocumentEndEx function was in the macro I recorded because this is a Brief specific function and I run the Brief keyboard mapping.

Brief has a special way of handling the end key and that is defined by the MoveDocumentEndEx function.

So the MoveDocumentEnd is the better choice ;)
Although I have the "Keypress removes mark" mapping option selected, up, down, right or left arrow (only) keypresses adjust the marked block rather than dispensing/removing the selection as I would have hoped.
This is because the marked mode is still active.

The MarkBlockSet does nothing more than turn on block marking and when marking is on the area is always adjusted whenever the cursor is moved.

If you want to just set the marked area you will have to use the none keyboard macro functions with something like this:

Code: Select all

function SelectCursorToDocEnd()
    local document = is_document()
    if (document == 0) then
        return
    end

    screen_update_disable()

    -- differnet marking modes
    local MARK_COLUMN = 0
    local MARK_LINE   = 1
    local MARK_BLOCK  = 2
    local MARK_RAGGED = 3
    local MARK_CUA    = 4

    -- define the marked region
    local top    = get_line_pos()
    local left   = get_cursor_pos()
    local bottom = get_line_count() + 1
    local right  = 0  -- no marked area for the last line
    local mode   = MARK_BLOCK

    -- remove any active marked area
    MarkHide()

    -- move cursor to end of file
    set_line_pos(bottom, right + 1)

    -- apply the new marked region
    set_marked_area(mode, top, left, bottom, right)
    screen_update_enable()
    screen_update()
end

SelectCursorToDocEnd() -- run the macro
This macro macro just sets the marked area outright, meaning there will be no active marking mode.
I guess another thing that fails in this example is that, after I make a selection using a macro such as this, the moment I use my mouse to scroll the window, my selection disappears.
That is because, Zeus by design makes sure the cursor is always on the screen.

Now some might say this is in fact a Zeus bug, but it is most certainly a thing that has been coded into the editor ;)

What happens is when you do a scroll and it then moves the cursor for it to stay on the screen and that movement removes the marked area.
For example, if I make a selection using my mouse by clicking (and holding) and dragging my mouse, release the button and then scroll, my selection remains highlighted.
I can replicate this behaviour at this end and will look into why they are not consistent.

Cheers Jussi

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: SherryDruck and 3 guests