Giter Club home page Giter Club logo

Comments (4)

dmaluka avatar dmaluka commented on June 4, 2024

I'm using the following in my init.lua for lazy line selection:

function selectLineUp(bp)
    if not bp.Cursor:HasSelection() then
        bp:EndOfLine()
        bp:SelectToStartOfLine()
    else
        bp:SelectUp()
        bp:SelectToStartOfLine()
    end
end

function selectLineDown(bp)
    if not bp.Cursor:HasSelection() then
        bp:StartOfLine()
        bp:SelectDown()
    else
        bp:SelectDown()
    end
end

I have Ctrl-Shift-Up and Ctrl-Shift-Down bound to these functions:

    "CtrlShiftDown": "lua:initlua.selectLineDown",
    "CtrlShiftUp": "lua:initlua.selectLineUp",

So in particular you could use these to quickly select a few whole lines via Ctrl-Shift-Up or Ctrl-Shift-Down (i.e. in whatever direction you like) and then duplicate them via Ctrl-D.

from micro.

Gavin-Holt avatar Gavin-Holt commented on June 4, 2024

Hi,

Many thanks for sharing your functions - taking this as inspiration - and combining with #2583, I have written a SelectBlock function:

function editor_SelectBlock(Current)                  
-- Extend the selection to include the whole of any line selected
    if editor.HasSelection(Current)  then
        if Current.Cursor.CurSelection[1]:LessThan(-Current.Cursor.CurSelection[2]) then
            -- forward -> backward
            -- Extend selection to end
            Current:SelectToEndOfLine()
            -- Get EOL Character
            Current:SelectRight()
            -- Swap to end of selection
            editor_SwapAnchor(Current)
            -- Extend selection to begining of line
            Current:SelectToStartOfLine()
        else
            -- backward -> forward
            -- Extend selection to begining of line
            Current:SelectToStartOfLine()
            -- Swap to end of selection
            editor_SwapAnchor(Current)
            -- Extend selection to end
            Current:SelectToEndOfLine()
            -- Get EOL Character
            Current:SelectRight()
        end
    else
        Current.Cursor:SelectLine()
    end
    return true
end

This can be called before duplicateline to achieve block duplication:

    "CtrlD": "lua:initlua.editor_GetBlock, duplicateline"

Unfortunately these manipulations change the current selection (so you can't make multiple copies).

I will leave this open as I still feel duplicateline is an irregular command and better solution should be found.

Kind Regards Gavin Holt

from micro.

Gavin-Holt avatar Gavin-Holt commented on June 4, 2024

I guess we can close this now as there is a work-around.

Kind Regards Gavin Holt

from micro.

Gavin-Holt avatar Gavin-Holt commented on June 4, 2024

Hi,

After downloading the new binary today, my selectblock function no longer works. I suspect this is a result of Fix Deselect() after mouse selection 3f810c2 or Fix cursor moving down when selection exist #3091

This function is only used to extend the selection before using the DuplicateLine action, to cope with with partly selected lines and I have it bound to Ctrl+D:

    "CtrlD": "lua:initlua.selectblock,DuplicateLine,EndOfLine",

It fails only when the lazy selection if from the bottom upwards!

Generally Micro will act upon partly selected lines (top down or bottom up) for all the following :

  • MoveLinesDown
  • MoveLinesUp
  • IndentSelection
  • OutdentSelection
  • lua:comment.comment
  • Textfilter
  • SpawnMultiCursorSelect

DuplicateLine remains an outlier, and my work-around no longer works!

Not wanting to upset the current users of DuplicateLine could we have a DuplicateLines action which acts on all partly selected lines?

Kind Regards Gavin Holt

PS. Naming things is hard: given a free hand I would rename DuplicateLine action to Duplicate (a method to duplicate selection, or current line if no selection, without using the clipboard), and that would allow a more logical use for DuplicateLine (duplicate all partly selected lines or current line if no selection, without using the clipboard).

from micro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.