From c4b9759538288b624ac80b5a5eacd717a91a6e82 Mon Sep 17 00:00:00 2001 From: jgdhs27 Date: Sun, 7 Dec 2025 13:48:51 +0000 Subject: [PATCH] fix horizontal movement adjustment for Character SelectionBehavior --- src/commands/README.md | 60 +++++++++++++++---------------- src/commands/layouts/azerty.fr.md | 60 +++++++++++++++---------------- src/commands/layouts/qwerty.md | 60 +++++++++++++++---------------- src/commands/select.ts | 7 ++-- 4 files changed, 92 insertions(+), 95 deletions(-) diff --git a/src/commands/README.md b/src/commands/README.md index 05e38c4e..123acd89 100644 --- a/src/commands/README.md +++ b/src/commands/README.md @@ -156,31 +156,31 @@ selections are empty select.lineEndSelect to line endAlt+L (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'normal') select.lineStartSelect to line startAlt+H (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'normal') select.middleVisibleLineSelect to middle visible line -select.documentEnd.extendExtend to last character -select.documentEnd.jumpJump to last character +select.documentEnd.extendExtend to last character +select.documentEnd.jumpJump to last character select.down.extendExtend downShift+J (editorTextFocus && dance.mode == 'normal')Shift+Down (editorTextFocus && dance.mode == 'normal')J (editorTextFocus && dance.mode == 'select')Down (editorTextFocus && dance.mode == 'select') select.down.jumpJump downJ (editorTextFocus && dance.mode == 'normal')Down (editorTextFocus && dance.mode == 'normal') -select.firstLine.extendExtend to first line -select.firstLine.jumpJump to first line -select.firstVisibleLine.extendExtend to first visible line -select.firstVisibleLine.jumpJump to first visible line -select.lastLine.extendExtend to last line -select.lastLine.jumpJump to last line -select.lastVisibleLine.extendExtend to last visible line -select.lastVisibleLine.jumpJump to last visible line +select.firstLine.extendExtend to first line +select.firstLine.jumpJump to first line +select.firstVisibleLine.extendExtend to first visible line +select.firstVisibleLine.jumpJump to first visible line +select.lastLine.extendExtend to last line +select.lastLine.jumpJump to last line +select.lastVisibleLine.extendExtend to last visible line +select.lastVisibleLine.jumpJump to last visible line select.left.extendExtend leftShift+H (editorTextFocus && dance.mode == 'normal')Shift+Left (editorTextFocus && dance.mode == 'normal')H (editorTextFocus && dance.mode == 'select')Left (editorTextFocus && dance.mode == 'select') select.left.jumpJump leftH (editorTextFocus && dance.mode == 'normal')Left (editorTextFocus && dance.mode == 'normal') -select.lineEnd.extendExtend to line endShift+Alt+L (editorTextFocus && dance.mode == 'normal')Shift+End (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'select') -select.lineStart.extendExtend to line startShift+Alt+H (editorTextFocus && dance.mode == 'normal')Shift+Home (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'select') -select.lineStart.jumpJump to line start -select.lineStart.skipBlank.extendExtend to line start (skip blank) -select.lineStart.skipBlank.jumpJump to line start (skip blank) -select.middleVisibleLine.extendExtend to middle visible line -select.middleVisibleLine.jumpJump to middle visible line +select.lineEnd.extendExtend to line endShift+Alt+L (editorTextFocus && dance.mode == 'normal')Shift+End (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'select') +select.lineStart.extendExtend to line startShift+Alt+H (editorTextFocus && dance.mode == 'normal')Shift+Home (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'select') +select.lineStart.jumpJump to line start +select.lineStart.skipBlank.extendExtend to line start (skip blank) +select.lineStart.skipBlank.jumpJump to line start (skip blank) +select.middleVisibleLine.extendExtend to middle visible line +select.middleVisibleLine.jumpJump to middle visible line select.right.extendExtend rightShift+L (editorTextFocus && dance.mode == 'normal')Shift+Right (editorTextFocus && dance.mode == 'normal')L (editorTextFocus && dance.mode == 'select')Right (editorTextFocus && dance.mode == 'select') select.right.jumpJump rightL (editorTextFocus && dance.mode == 'normal')Right (editorTextFocus && dance.mode == 'normal') -select.to.extendExtend toShift+G (editorTextFocus && dance.mode == 'normal')G (editorTextFocus && dance.mode == 'select') -select.to.jumpGo toG (editorTextFocus && dance.mode == 'normal') +select.to.extendExtend toShift+G (editorTextFocus && dance.mode == 'normal')G (editorTextFocus && dance.mode == 'select') +select.to.jumpGo toG (editorTextFocus && dance.mode == 'normal') select.up.extendExtend upShift+K (editorTextFocus && dance.mode == 'normal')Shift+Up (editorTextFocus && dance.mode == 'normal')K (editorTextFocus && dance.mode == 'select')Up (editorTextFocus && dance.mode == 'select') select.up.jumpJump upK (editorTextFocus && dance.mode == 'normal')Up (editorTextFocus && dance.mode == 'normal') select.toSelect to @@ -1289,7 +1289,7 @@ This command: -### [`select.to`](./select.ts#L293-L311) +### [`select.to`](./select.ts#L290-L308) Select to. @@ -1309,7 +1309,7 @@ This command: -### [`select.line.below`](./select.ts#L321-L324) +### [`select.line.below`](./select.ts#L318-L321) Select line below. @@ -1318,7 +1318,7 @@ This command: -### [`select.line.below.extend`](./select.ts#L349-L354) +### [`select.line.below.extend`](./select.ts#L346-L351) Extend to line below. @@ -1330,7 +1330,7 @@ Default keybinding: `x` (helix: normal; helix: select) -### [`select.line.above`](./select.ts#L381-L384) +### [`select.line.above`](./select.ts#L378-L381) Select line above. @@ -1339,7 +1339,7 @@ This command: -### [`select.line.above.extend`](./select.ts#L408-L411) +### [`select.line.above.extend`](./select.ts#L405-L408) Extend to line above. @@ -1348,7 +1348,7 @@ This command: -### [`select.lineStart`](./select.ts#L457-L479) +### [`select.lineStart`](./select.ts#L454-L476) Select to line start. @@ -1373,7 +1373,7 @@ Default keybinding: `a-h` (kakoune: normal) -### [`select.lineEnd`](./select.ts#L504-L526) +### [`select.lineEnd`](./select.ts#L501-L523) Select to line end. @@ -1396,7 +1396,7 @@ Default keybinding: `a-l` (kakoune: normal) -### [`select.lastLine`](./select.ts#L554-L564) +### [`select.lastLine`](./select.ts#L551-L561) Select to last line. @@ -1409,7 +1409,7 @@ Select to last line. -### [`select.firstVisibleLine`](./select.ts#L575-L585) +### [`select.firstVisibleLine`](./select.ts#L572-L582) Select to first visible line. @@ -1422,7 +1422,7 @@ Select to first visible line. -### [`select.middleVisibleLine`](./select.ts#L592-L602) +### [`select.middleVisibleLine`](./select.ts#L589-L599) Select to middle visible line. @@ -1435,7 +1435,7 @@ Select to middle visible line. -### [`select.lastVisibleLine`](./select.ts#L609-L619) +### [`select.lastVisibleLine`](./select.ts#L606-L616) Select to last visible line. diff --git a/src/commands/layouts/azerty.fr.md b/src/commands/layouts/azerty.fr.md index c9ad209e..8f347646 100644 --- a/src/commands/layouts/azerty.fr.md +++ b/src/commands/layouts/azerty.fr.md @@ -141,31 +141,31 @@ selections are empty select.lineEndSelect to line endAlt+L (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'normal') select.lineStartSelect to line startAlt+H (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'normal') select.middleVisibleLineSelect to middle visible line -select.documentEnd.extendExtend to last character -select.documentEnd.jumpJump to last character +select.documentEnd.extendExtend to last character +select.documentEnd.jumpJump to last character select.down.extendExtend downShift+J (editorTextFocus && dance.mode == 'normal')Shift+Down (editorTextFocus && dance.mode == 'normal')J (editorTextFocus && dance.mode == 'select')Down (editorTextFocus && dance.mode == 'select') select.down.jumpJump downJ (editorTextFocus && dance.mode == 'normal')Down (editorTextFocus && dance.mode == 'normal') -select.firstLine.extendExtend to first line -select.firstLine.jumpJump to first line -select.firstVisibleLine.extendExtend to first visible line -select.firstVisibleLine.jumpJump to first visible line -select.lastLine.extendExtend to last line -select.lastLine.jumpJump to last line -select.lastVisibleLine.extendExtend to last visible line -select.lastVisibleLine.jumpJump to last visible line +select.firstLine.extendExtend to first line +select.firstLine.jumpJump to first line +select.firstVisibleLine.extendExtend to first visible line +select.firstVisibleLine.jumpJump to first visible line +select.lastLine.extendExtend to last line +select.lastLine.jumpJump to last line +select.lastVisibleLine.extendExtend to last visible line +select.lastVisibleLine.jumpJump to last visible line select.left.extendExtend leftShift+H (editorTextFocus && dance.mode == 'normal')Shift+Left (editorTextFocus && dance.mode == 'normal')H (editorTextFocus && dance.mode == 'select')Left (editorTextFocus && dance.mode == 'select') select.left.jumpJump leftH (editorTextFocus && dance.mode == 'normal')Left (editorTextFocus && dance.mode == 'normal') -select.lineEnd.extendExtend to line endShift+Alt+L (editorTextFocus && dance.mode == 'normal')Shift+End (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'select') -select.lineStart.extendExtend to line startShift+Alt+H (editorTextFocus && dance.mode == 'normal')Shift+Home (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'select') -select.lineStart.jumpJump to line start -select.lineStart.skipBlank.extendExtend to line start (skip blank) -select.lineStart.skipBlank.jumpJump to line start (skip blank) -select.middleVisibleLine.extendExtend to middle visible line -select.middleVisibleLine.jumpJump to middle visible line +select.lineEnd.extendExtend to line endShift+Alt+L (editorTextFocus && dance.mode == 'normal')Shift+End (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'select') +select.lineStart.extendExtend to line startShift+Alt+H (editorTextFocus && dance.mode == 'normal')Shift+Home (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'select') +select.lineStart.jumpJump to line start +select.lineStart.skipBlank.extendExtend to line start (skip blank) +select.lineStart.skipBlank.jumpJump to line start (skip blank) +select.middleVisibleLine.extendExtend to middle visible line +select.middleVisibleLine.jumpJump to middle visible line select.right.extendExtend rightShift+L (editorTextFocus && dance.mode == 'normal')Shift+Right (editorTextFocus && dance.mode == 'normal')L (editorTextFocus && dance.mode == 'select')Right (editorTextFocus && dance.mode == 'select') select.right.jumpJump rightL (editorTextFocus && dance.mode == 'normal')Right (editorTextFocus && dance.mode == 'normal') -select.to.extendExtend toShift+G (editorTextFocus && dance.mode == 'normal')G (editorTextFocus && dance.mode == 'select') -select.to.jumpGo toG (editorTextFocus && dance.mode == 'normal') +select.to.extendExtend toShift+G (editorTextFocus && dance.mode == 'normal')G (editorTextFocus && dance.mode == 'select') +select.to.jumpGo toG (editorTextFocus && dance.mode == 'normal') select.up.extendExtend upShift+K (editorTextFocus && dance.mode == 'normal')Shift+Up (editorTextFocus && dance.mode == 'normal')K (editorTextFocus && dance.mode == 'select')Up (editorTextFocus && dance.mode == 'select') select.up.jumpJump upK (editorTextFocus && dance.mode == 'normal')Up (editorTextFocus && dance.mode == 'normal') select.toSelect to @@ -1274,7 +1274,7 @@ This command: -### [`select.to`](../select.ts#L293-L311) +### [`select.to`](../select.ts#L290-L308) Select to. @@ -1294,7 +1294,7 @@ This command: -### [`select.line.below`](../select.ts#L321-L324) +### [`select.line.below`](../select.ts#L318-L321) Select line below. @@ -1303,7 +1303,7 @@ This command: -### [`select.line.below.extend`](../select.ts#L349-L354) +### [`select.line.below.extend`](../select.ts#L346-L351) Extend to line below. @@ -1315,7 +1315,7 @@ Default keybinding: `x` (helix: normal; helix: select) -### [`select.line.above`](../select.ts#L381-L384) +### [`select.line.above`](../select.ts#L378-L381) Select line above. @@ -1324,7 +1324,7 @@ This command: -### [`select.line.above.extend`](../select.ts#L408-L411) +### [`select.line.above.extend`](../select.ts#L405-L408) Extend to line above. @@ -1333,7 +1333,7 @@ This command: -### [`select.lineStart`](../select.ts#L457-L479) +### [`select.lineStart`](../select.ts#L454-L476) Select to line start. @@ -1358,7 +1358,7 @@ Default keybinding: `a-h` (kakoune: normal) -### [`select.lineEnd`](../select.ts#L504-L526) +### [`select.lineEnd`](../select.ts#L501-L523) Select to line end. @@ -1381,7 +1381,7 @@ Default keybinding: `a-l` (kakoune: normal) -### [`select.lastLine`](../select.ts#L554-L564) +### [`select.lastLine`](../select.ts#L551-L561) Select to last line. @@ -1394,7 +1394,7 @@ Select to last line. -### [`select.firstVisibleLine`](../select.ts#L575-L585) +### [`select.firstVisibleLine`](../select.ts#L572-L582) Select to first visible line. @@ -1407,7 +1407,7 @@ Select to first visible line. -### [`select.middleVisibleLine`](../select.ts#L592-L602) +### [`select.middleVisibleLine`](../select.ts#L589-L599) Select to middle visible line. @@ -1420,7 +1420,7 @@ Select to middle visible line. -### [`select.lastVisibleLine`](../select.ts#L609-L619) +### [`select.lastVisibleLine`](../select.ts#L606-L616) Select to last visible line. diff --git a/src/commands/layouts/qwerty.md b/src/commands/layouts/qwerty.md index f79f5744..496be1d6 100644 --- a/src/commands/layouts/qwerty.md +++ b/src/commands/layouts/qwerty.md @@ -141,31 +141,31 @@ selections are empty select.lineEndSelect to line endAlt+L (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'normal') select.lineStartSelect to line startAlt+H (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'normal') select.middleVisibleLineSelect to middle visible line -select.documentEnd.extendExtend to last character -select.documentEnd.jumpJump to last character +select.documentEnd.extendExtend to last character +select.documentEnd.jumpJump to last character select.down.extendExtend downShift+J (editorTextFocus && dance.mode == 'normal')Shift+Down (editorTextFocus && dance.mode == 'normal')J (editorTextFocus && dance.mode == 'select')Down (editorTextFocus && dance.mode == 'select') select.down.jumpJump downJ (editorTextFocus && dance.mode == 'normal')Down (editorTextFocus && dance.mode == 'normal') -select.firstLine.extendExtend to first line -select.firstLine.jumpJump to first line -select.firstVisibleLine.extendExtend to first visible line -select.firstVisibleLine.jumpJump to first visible line -select.lastLine.extendExtend to last line -select.lastLine.jumpJump to last line -select.lastVisibleLine.extendExtend to last visible line -select.lastVisibleLine.jumpJump to last visible line +select.firstLine.extendExtend to first line +select.firstLine.jumpJump to first line +select.firstVisibleLine.extendExtend to first visible line +select.firstVisibleLine.jumpJump to first visible line +select.lastLine.extendExtend to last line +select.lastLine.jumpJump to last line +select.lastVisibleLine.extendExtend to last visible line +select.lastVisibleLine.jumpJump to last visible line select.left.extendExtend leftShift+H (editorTextFocus && dance.mode == 'normal')Shift+Left (editorTextFocus && dance.mode == 'normal')H (editorTextFocus && dance.mode == 'select')Left (editorTextFocus && dance.mode == 'select') select.left.jumpJump leftH (editorTextFocus && dance.mode == 'normal')Left (editorTextFocus && dance.mode == 'normal') -select.lineEnd.extendExtend to line endShift+Alt+L (editorTextFocus && dance.mode == 'normal')Shift+End (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'select') -select.lineStart.extendExtend to line startShift+Alt+H (editorTextFocus && dance.mode == 'normal')Shift+Home (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'select') -select.lineStart.jumpJump to line start -select.lineStart.skipBlank.extendExtend to line start (skip blank) -select.lineStart.skipBlank.jumpJump to line start (skip blank) -select.middleVisibleLine.extendExtend to middle visible line -select.middleVisibleLine.jumpJump to middle visible line +select.lineEnd.extendExtend to line endShift+Alt+L (editorTextFocus && dance.mode == 'normal')Shift+End (editorTextFocus && dance.mode == 'normal')End (editorTextFocus && dance.mode == 'select') +select.lineStart.extendExtend to line startShift+Alt+H (editorTextFocus && dance.mode == 'normal')Shift+Home (editorTextFocus && dance.mode == 'normal')Home (editorTextFocus && dance.mode == 'select') +select.lineStart.jumpJump to line start +select.lineStart.skipBlank.extendExtend to line start (skip blank) +select.lineStart.skipBlank.jumpJump to line start (skip blank) +select.middleVisibleLine.extendExtend to middle visible line +select.middleVisibleLine.jumpJump to middle visible line select.right.extendExtend rightShift+L (editorTextFocus && dance.mode == 'normal')Shift+Right (editorTextFocus && dance.mode == 'normal')L (editorTextFocus && dance.mode == 'select')Right (editorTextFocus && dance.mode == 'select') select.right.jumpJump rightL (editorTextFocus && dance.mode == 'normal')Right (editorTextFocus && dance.mode == 'normal') -select.to.extendExtend toShift+G (editorTextFocus && dance.mode == 'normal')G (editorTextFocus && dance.mode == 'select') -select.to.jumpGo toG (editorTextFocus && dance.mode == 'normal') +select.to.extendExtend toShift+G (editorTextFocus && dance.mode == 'normal')G (editorTextFocus && dance.mode == 'select') +select.to.jumpGo toG (editorTextFocus && dance.mode == 'normal') select.up.extendExtend upShift+K (editorTextFocus && dance.mode == 'normal')Shift+Up (editorTextFocus && dance.mode == 'normal')K (editorTextFocus && dance.mode == 'select')Up (editorTextFocus && dance.mode == 'select') select.up.jumpJump upK (editorTextFocus && dance.mode == 'normal')Up (editorTextFocus && dance.mode == 'normal') select.toSelect to @@ -1274,7 +1274,7 @@ This command: -### [`select.to`](../select.ts#L293-L311) +### [`select.to`](../select.ts#L290-L308) Select to. @@ -1294,7 +1294,7 @@ This command: -### [`select.line.below`](../select.ts#L321-L324) +### [`select.line.below`](../select.ts#L318-L321) Select line below. @@ -1303,7 +1303,7 @@ This command: -### [`select.line.below.extend`](../select.ts#L349-L354) +### [`select.line.below.extend`](../select.ts#L346-L351) Extend to line below. @@ -1315,7 +1315,7 @@ Default keybinding: `x` (helix: normal; helix: select) -### [`select.line.above`](../select.ts#L381-L384) +### [`select.line.above`](../select.ts#L378-L381) Select line above. @@ -1324,7 +1324,7 @@ This command: -### [`select.line.above.extend`](../select.ts#L408-L411) +### [`select.line.above.extend`](../select.ts#L405-L408) Extend to line above. @@ -1333,7 +1333,7 @@ This command: -### [`select.lineStart`](../select.ts#L457-L479) +### [`select.lineStart`](../select.ts#L454-L476) Select to line start. @@ -1358,7 +1358,7 @@ Default keybinding: `a-h` (kakoune: normal) -### [`select.lineEnd`](../select.ts#L504-L526) +### [`select.lineEnd`](../select.ts#L501-L523) Select to line end. @@ -1381,7 +1381,7 @@ Default keybinding: `a-l` (kakoune: normal) -### [`select.lastLine`](../select.ts#L554-L564) +### [`select.lastLine`](../select.ts#L551-L561) Select to last line. @@ -1394,7 +1394,7 @@ Select to last line. -### [`select.firstVisibleLine`](../select.ts#L575-L585) +### [`select.firstVisibleLine`](../select.ts#L572-L582) Select to first visible line. @@ -1407,7 +1407,7 @@ Select to first visible line. -### [`select.middleVisibleLine`](../select.ts#L592-L602) +### [`select.middleVisibleLine`](../select.ts#L589-L599) Select to middle visible line. @@ -1420,7 +1420,7 @@ Select to middle visible line. -### [`select.lastVisibleLine`](../select.ts#L609-L619) +### [`select.lastVisibleLine`](../select.ts#L606-L616) Select to last visible line. diff --git a/src/commands/select.ts b/src/commands/select.ts index 6b57c5d4..e72c5e69 100644 --- a/src/commands/select.ts +++ b/src/commands/select.ts @@ -244,16 +244,13 @@ export function horizontally( direction = Direction.Forward, shift = Shift.Select, ) { - const mayNeedAdjustment = direction === Direction.Backward - && _.selectionBehavior === SelectionBehavior.Character; - const newSelections = Selections.mapByIndex((_i, selection, document) => { let active = selection.active === selection.start ? Selections.activeStart(selection, _) : Selections.activeEnd(selection, _); - if (mayNeedAdjustment) { - if (shift === Shift.Extend && Selections.isSingleCharacter(selection)) { + if (_.selectionBehavior === SelectionBehavior.Character) { + if (direction === Direction.Backward && shift === Shift.Extend && Selections.isSingleCharacter(selection)) { active = selection.start; } else if (shift === Shift.Jump && selection.active === selection.start) { active = Positions.next(active, _.document) ?? active;