Giter VIP home page Giter VIP logo

Comments (8)

dmaluka avatar dmaluka commented on August 16, 2024

That is how Cut (Ctrl-x) already works: if there is a selection, it deletes the selection, otherwise it deletes the current line, like DeleteLine does.

BTW I don't quite like the way how it is implemented. The Cut action internally checks if there is a selection and either deletes the selection or the current line. I think it would be better if it only deleted the selection and Ctrl-x was bound by default not to Cut but to Cut|CutLine (so that if the user doesn't want Ctrl-x to delete the current line if there is no selection, the user can disable this behavior by binding Ctrl-x to Cut instead of Cut|CutLine).

from micro.

Neko-Box-Coder avatar Neko-Box-Coder commented on August 16, 2024

I think what you are saying is similar but a different issue, possibly an incorrect behavior from Cut. If Cut does what you described ( I haven't checked the code yet ), we can probably just remove the non selection logic and default ctrl-x to Cut|CutLine. That's in fact my current bindings funny enough.

But anyway, that's another issue as I said (which could potentially be changed together).
What I was saying is that DeleteLine function (or even CutLine, CopyLine) should respect selections and delete the lines where and when there's a selection. This is how it works on other editors and I am still struggling to get used to it 😅

I can probably raise a PR for this (and also the issue you mentioned) but that will be after I sorted out the other PRs I have since I am already spending quite a bit of time on other PRs.

from micro.

dmaluka avatar dmaluka commented on August 16, 2024

My point is that if we do what you suggest, i.e. make DeleteLine respect selections, then Ctrl-k will do the same thing as Ctrl-x, so then the question is why do we need Ctrl-k (and DeleteLine) at all.

Ah, I've just realized that DeleteLine is not the same thing as CutLine, since it doesn't copy the line to the clipboard. (I'm too used to using Ctrl-x for deleting lines, even when I don't need to copy them.)

So, yeah, it makes sense to make DeleteLine respect selections (like DuplicateLine does).

Question: if the selection does not fully cover its first and/or last line, should DeleteLine delete just the selection itself, or the rest of its first and last lines too? Which behavior is more useful?

From a pure aesthetics/consistency perspective it seems better if it will delete just the selection: 1. DuplicateLine also duplicates just the selection. 2. I've checked that in nano Ctrl-k also deletes just the selection (haven't checked other editors though).

from micro.

Neko-Box-Coder avatar Neko-Box-Coder commented on August 16, 2024

I understand it is good to have consistency but if DeleteLine just deletes the selection, then it is doing the same job as Delete, which I could have just used Delete.

My personal opinion would be it should also delete the first line and last line since that is doing what it says, deleting lines.

However, that's just my own opinion. But I think it should at least reacts to selection(s), the action is up for debate and I don't mind other people joining to vote/provide opinions on what they want.

from micro.

dmaluka avatar dmaluka commented on August 16, 2024

Yeah, good point. Now it seems more useful to me if it deletes the whole first and last lines. (DuplicateLine is a slightly different case.)

from micro.

Gavin-Holt avatar Gavin-Holt commented on August 16, 2024

Hi,

You can use Lua to achieve the required deletion. Bind the following to a keyboard shortcut of your choice:

    "YourKey": "lua:initlua.delsel,SelectLine,Delete",

I keep all my Lua in one file init.lua and the delsel function is very simple:

function delsel(Current)
-- This avoids deleting EOL when deleting partially selected lines
    if Current.Cursor:HasSelection() then
        Current.Cursor:DeleteSelection()
    end
end

This will delete all partly selected lines, or the current line if no selection.

Kind Regards Gavin Holt

PS I am struggling to achieve similar for duplicate line as my solution is now broken - see #3110.

from micro.

dmaluka avatar dmaluka commented on August 16, 2024

You can use Lua to achieve the required deletion. Bind the following to a keyboard shortcut of your choice:

    "YourKey": "lua:initlua.delsel,SelectLine,Delete",

This is a smart trick, but it doesn't always work correctly. If the last line of the selection contains the whole line, this will also wrongly remove the next line below the selection.

...I think the behavior of DeleteLine should be fixed in micro anyway. The existing behavior is, among other things, confusing: DeleteLine deletes just the "current line", but when there is a selection, the cursor is not displayed, so the user doesn't know what is the current line.

I'm gonna implement a fix, it should be trivial.

from micro.

dmaluka avatar dmaluka commented on August 16, 2024

Implemented #3335 which makes DeleteLine respect selections, among other things.

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.