-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace DuplicateLine with directional alternatives and adjust cursor positioning #3635
Conversation
2025-01-26.02-44-23-00.06.37.366-00.07.20.971.mp4 |
Given the above, the entire PR could be reduced to a change like this? --- a/internal/action/actions.go
+++ b/internal/action/actions.go
@@ -1438,10 +1438,11 @@ func (h *BufPane) Duplicate() bool {
// DuplicateLine duplicates the current line. If there is a selection, DuplicateLine
// duplicates all the lines that are (fully or partially) in the selection.
func (h *BufPane) DuplicateLine() bool {
+ origLoc := h.Cursor.Loc
+ origLastVisualX := h.Cursor.LastVisualX
+ origLastWrappedVisualX := h.Cursor.LastWrappedVisualX
+
if h.Cursor.HasSelection() {
- origLoc := h.Cursor.Loc
- origLastVisualX := h.Cursor.LastVisualX
- origLastWrappedVisualX := h.Cursor.LastWrappedVisualX
origSelection := h.Cursor.CurSelection
start := h.Cursor.CurSelection[0]
@@ -1460,9 +1461,6 @@ func (h *BufPane) DuplicateLine() bool {
h.Buf.Insert(h.Cursor.Loc, "\n"+string(h.Buf.LineBytes(y)))
}
- h.Cursor.Loc = origLoc
- h.Cursor.LastVisualX = origLastVisualX
- h.Cursor.LastWrappedVisualX = origLastWrappedVisualX
h.Cursor.CurSelection = origSelection
if start.Y < end.Y {
@@ -1475,6 +1473,11 @@ func (h *BufPane) DuplicateLine() bool {
h.Buf.Insert(h.Cursor.Loc, "\n"+string(h.Buf.LineBytes(h.Cursor.Y)))
InfoBar.Message("Duplicated line")
}
+
+ h.Cursor.Loc = origLoc
+ h.Cursor.LastVisualX = origLastVisualX
+ h.Cursor.LastWrappedVisualX = origLastWrappedVisualX
+
h.Relocate()
return true
} |
with selection, the
the {
"context": "Editor",
"bindings": {
...
"ctrl-alt-shift-up": "editor::DuplicateLineUp",
"ctrl-alt-shift-down": "editor::DuplicateLineDown",
...
}
i made sure to keep the original binding for
if you were to bind 2025-01-29.16-26-25.mp4
keeping the selection is important to align with other editors that handle selections properly. as already established in the above section, hope this clears things up! |
Sorry, I meant
Ah, ok. Yes, it was hard to notice, especially since you haven't mentioned it in the PR description or in the commit message but quite the opposite, you said you removed
Obviously I didn't mean
Aligning with other editors is not a goal in itself. Are you actually using |
oh i see now, i apologize for not realizing thats what you meant, this is probably a better option. this would give the user more choice in the specific behavior of it in addition, we would need a new action for moving the entire selection (or cursor if no selection) since im not aware of any action that does this is it a big backwards compatability issue to change the functionality of the
yes i do use this, i need to duplicate a code section multiple times on top of eachother sometimes. it's just something to help with my workflow |
Keeping the cursor position is a nice fix. Maybe other parts of this PR might be better suited as a plugin or Lua function rather than being part of the editor itself. |
It changes the behavior of So I'm still inclined to think we should just change the existing
Ok, we can probably add function duplicateLineDown(bp)
bp:DuplicateLine()
if bp.Cursor:HasSelection() then
local lines = bp.Cursor.CurSelection[2].Y - bp.Cursor.CurSelection[1].Y
if bp.Cursor.CurSelection[2].X > 0 then
lines = lines + 1
end
bp.Cursor.Loc.Y = bp.Cursor.Loc.Y + lines
bp.Cursor.CurSelection[1].Y = bp.Cursor.CurSelection[1].Y + lines
bp.Cursor.CurSelection[2].Y = bp.Cursor.CurSelection[2].Y + lines
bp.Cursor.OrigSelection[1].Y = bp.Cursor.OrigSelection[1].Y + lines
bp.Cursor.OrigSelection[2].Y = bp.Cursor.OrigSelection[2].Y + lines
else
bp.Cursor.Loc.Y = bp.Cursor.Loc.Y + 1
end
end |
BTW I've noticed a couple of issues with this PR (irregardless of the above discussions):
|
thanks for all the suggestions, I'll get to fixing this PR in around 3 or 4 hours |
DuplicateLine
withDuplicateLineUp
andDuplicateLineDown
Shift-Alt-Ctrl-Up
andShift-Alt-Ctrl-Down
keybindings set to useDuplicateLineUp
andDuplicateLineDown
respectively while keeping originalCtrl-d
keybindingDuplicateLineUp
: cursor will stay still instead of moving to the end of the lineDuplicateLineDown
: cursor will move with the duplicated line down at the same X position instead of moving to the end of the line2025-01-25.17-14-28-00.00.46.643-00.01.02.517.mp4
(works with selections aswell, forgot to show in the video)