From 918eec9357b6374099d37aff40ebacfd1e615cd2 Mon Sep 17 00:00:00 2001 From: jgdhs27 Date: Sat, 27 Sep 2025 16:08:53 +0100 Subject: [PATCH] skip character when moving by paragraph --- src/api/selections.ts | 13 +++++++++++-- src/commands/README.md | 18 +++++++++--------- src/commands/layouts/azerty.fr.md | 18 +++++++++--------- src/commands/layouts/qwerty.md | 18 +++++++++--------- src/commands/seek.ts | 5 ++++- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/api/selections.ts b/src/api/selections.ts index 707175f6..49bd5597 100644 --- a/src/api/selections.ts +++ b/src/api/selections.ts @@ -1401,6 +1401,7 @@ export function shift( position: vscode.Position, shift: Shift, context = Context.current, + skipCharacter: boolean = false, ) { let anchor = shift === Shift.Jump ? position @@ -1408,9 +1409,17 @@ export function shift( ? selection.active : selection.anchor; - if (context.selectionBehavior === SelectionBehavior.Character && shift !== Shift.Jump) { - const direction = anchor.isAfter(position) ? Direction.Backward : Direction.Forward; + const direction = anchor.isAfter(position) ? Direction.Backward : Direction.Forward; + + if (skipCharacter) { + if (direction === Direction.Forward) { + anchor = Positions.next(anchor) ?? anchor; + } else { + anchor = Positions.previous(anchor) ?? anchor; + } + } + if (context.selectionBehavior === SelectionBehavior.Character && shift !== Shift.Jump) { anchor = seekFrom(selection, direction, anchor, context); } diff --git a/src/commands/README.md b/src/commands/README.md index ba3b9ace..7c7f13e2 100644 --- a/src/commands/README.md +++ b/src/commands/README.md @@ -124,11 +124,11 @@ selections are empty seek.included.backwardSelect to character (included, backward)Alt+F (editorTextFocus && dance.mode == 'normal')Shift+F (editorTextFocus && dance.mode == 'normal') seek.included.extendExtend to character (included)Shift+F (editorTextFocus && dance.mode == 'normal')F (editorTextFocus && dance.mode == 'select') seek.included.extend.backwardExtend to character (included, backward)Shift+Alt+F (editorTextFocus && dance.mode == 'normal')Shift+F (editorTextFocus && dance.mode == 'select') -seek.leap.backwardLeap backward -seek.syntax.child.experimentalSelect child syntax object -seek.syntax.next.experimentalSelect next syntax object -seek.syntax.parent.experimentalSelect parent syntax object -seek.syntax.previous.experimentalSelect previous syntax object +seek.leap.backwardLeap backward +seek.syntax.child.experimentalSelect child syntax object +seek.syntax.next.experimentalSelect next syntax object +seek.syntax.parent.experimentalSelect parent syntax object +seek.syntax.previous.experimentalSelect previous syntax object seek.word.backwardSelect to previous word startB (editorTextFocus && dance.mode == 'normal') seek.word.extendExtend to next word startShift+W (editorTextFocus && dance.mode == 'normal')W (editorTextFocus && dance.mode == 'select') seek.word.extend.backwardExtend to previous word startShift+B (editorTextFocus && dance.mode == 'normal')B (editorTextFocus && dance.mode == 'select') @@ -140,7 +140,7 @@ selections are empty seek.wordEnd.extendExtend to next word endShift+E (editorTextFocus && dance.mode == 'normal')E (editorTextFocus && dance.mode == 'select') seek.wordEnd.wsSelect to next non-whitespace word endAlt+E (editorTextFocus && dance.mode == 'normal')Shift+E (editorTextFocus && dance.mode == 'normal') seek.wordEnd.ws.extendExtend to next non-whitespace word endShift+Alt+E (editorTextFocus && dance.mode == 'normal')Shift+E (editorTextFocus && dance.mode == 'select') -seek.wordLabel.extendLeap to word (extend) +seek.wordLabel.extendLeap to word (extend) seek.syntax.experimentalSelect syntax object seek.wordSelect to next word startW (editorTextFocus && dance.mode == 'normal') seek.wordLabelLeap to word @@ -1166,7 +1166,7 @@ This command: -### [`seek.syntax.experimental`](./seek.ts#L583-L602) +### [`seek.syntax.experimental`](./seek.ts#L586-L605) Select syntax object. @@ -1184,7 +1184,7 @@ This command: -### [`seek.leap`](./seek.ts#L636-L652) +### [`seek.leap`](./seek.ts#L639-L655) Leap forward. @@ -1201,7 +1201,7 @@ This command: -### [`seek.wordLabel`](./seek.ts#L870-L886) +### [`seek.wordLabel`](./seek.ts#L873-L889) Leap to word. diff --git a/src/commands/layouts/azerty.fr.md b/src/commands/layouts/azerty.fr.md index cb63592c..c7a0f19a 100644 --- a/src/commands/layouts/azerty.fr.md +++ b/src/commands/layouts/azerty.fr.md @@ -109,11 +109,11 @@ selections are empty seek.included.backwardSelect to character (included, backward)Alt+F (editorTextFocus && dance.mode == 'normal')Shift+F (editorTextFocus && dance.mode == 'normal') seek.included.extendExtend to character (included)Shift+F (editorTextFocus && dance.mode == 'normal')F (editorTextFocus && dance.mode == 'select') seek.included.extend.backwardExtend to character (included, backward)Shift+Alt+F (editorTextFocus && dance.mode == 'normal')Shift+F (editorTextFocus && dance.mode == 'select') -seek.leap.backwardLeap backward -seek.syntax.child.experimentalSelect child syntax object -seek.syntax.next.experimentalSelect next syntax object -seek.syntax.parent.experimentalSelect parent syntax object -seek.syntax.previous.experimentalSelect previous syntax object +seek.leap.backwardLeap backward +seek.syntax.child.experimentalSelect child syntax object +seek.syntax.next.experimentalSelect next syntax object +seek.syntax.parent.experimentalSelect parent syntax object +seek.syntax.previous.experimentalSelect previous syntax object seek.word.backwardSelect to previous word startB (editorTextFocus && dance.mode == 'normal') seek.word.extendExtend to next word startShift+W (editorTextFocus && dance.mode == 'normal')W (editorTextFocus && dance.mode == 'select') seek.word.extend.backwardExtend to previous word startShift+B (editorTextFocus && dance.mode == 'normal')B (editorTextFocus && dance.mode == 'select') @@ -125,7 +125,7 @@ selections are empty seek.wordEnd.extendExtend to next word endShift+E (editorTextFocus && dance.mode == 'normal')E (editorTextFocus && dance.mode == 'select') seek.wordEnd.wsSelect to next non-whitespace word endAlt+E (editorTextFocus && dance.mode == 'normal')Shift+E (editorTextFocus && dance.mode == 'normal') seek.wordEnd.ws.extendExtend to next non-whitespace word endShift+Alt+E (editorTextFocus && dance.mode == 'normal')Shift+E (editorTextFocus && dance.mode == 'select') -seek.wordLabel.extendLeap to word (extend) +seek.wordLabel.extendLeap to word (extend) seek.syntax.experimentalSelect syntax object seek.wordSelect to next word startW (editorTextFocus && dance.mode == 'normal') seek.wordLabelLeap to word @@ -1151,7 +1151,7 @@ This command: -### [`seek.syntax.experimental`](../seek.ts#L583-L602) +### [`seek.syntax.experimental`](../seek.ts#L586-L605) Select syntax object. @@ -1169,7 +1169,7 @@ This command: -### [`seek.leap`](../seek.ts#L636-L652) +### [`seek.leap`](../seek.ts#L639-L655) Leap forward. @@ -1186,7 +1186,7 @@ This command: -### [`seek.wordLabel`](../seek.ts#L870-L886) +### [`seek.wordLabel`](../seek.ts#L873-L889) Leap to word. diff --git a/src/commands/layouts/qwerty.md b/src/commands/layouts/qwerty.md index 40a88876..3541225b 100644 --- a/src/commands/layouts/qwerty.md +++ b/src/commands/layouts/qwerty.md @@ -109,11 +109,11 @@ selections are empty seek.included.backwardSelect to character (included, backward)Alt+F (editorTextFocus && dance.mode == 'normal')Shift+F (editorTextFocus && dance.mode == 'normal') seek.included.extendExtend to character (included)Shift+F (editorTextFocus && dance.mode == 'normal')F (editorTextFocus && dance.mode == 'select') seek.included.extend.backwardExtend to character (included, backward)Shift+Alt+F (editorTextFocus && dance.mode == 'normal')Shift+F (editorTextFocus && dance.mode == 'select') -seek.leap.backwardLeap backward -seek.syntax.child.experimentalSelect child syntax object -seek.syntax.next.experimentalSelect next syntax object -seek.syntax.parent.experimentalSelect parent syntax object -seek.syntax.previous.experimentalSelect previous syntax object +seek.leap.backwardLeap backward +seek.syntax.child.experimentalSelect child syntax object +seek.syntax.next.experimentalSelect next syntax object +seek.syntax.parent.experimentalSelect parent syntax object +seek.syntax.previous.experimentalSelect previous syntax object seek.word.backwardSelect to previous word startB (editorTextFocus && dance.mode == 'normal') seek.word.extendExtend to next word startShift+W (editorTextFocus && dance.mode == 'normal')W (editorTextFocus && dance.mode == 'select') seek.word.extend.backwardExtend to previous word startShift+B (editorTextFocus && dance.mode == 'normal')B (editorTextFocus && dance.mode == 'select') @@ -125,7 +125,7 @@ selections are empty seek.wordEnd.extendExtend to next word endShift+E (editorTextFocus && dance.mode == 'normal')E (editorTextFocus && dance.mode == 'select') seek.wordEnd.wsSelect to next non-whitespace word endAlt+E (editorTextFocus && dance.mode == 'normal')Shift+E (editorTextFocus && dance.mode == 'normal') seek.wordEnd.ws.extendExtend to next non-whitespace word endShift+Alt+E (editorTextFocus && dance.mode == 'normal')Shift+E (editorTextFocus && dance.mode == 'select') -seek.wordLabel.extendLeap to word (extend) +seek.wordLabel.extendLeap to word (extend) seek.syntax.experimentalSelect syntax object seek.wordSelect to next word startW (editorTextFocus && dance.mode == 'normal') seek.wordLabelLeap to word @@ -1151,7 +1151,7 @@ This command: -### [`seek.syntax.experimental`](../seek.ts#L583-L602) +### [`seek.syntax.experimental`](../seek.ts#L586-L605) Select syntax object. @@ -1169,7 +1169,7 @@ This command: -### [`seek.leap`](../seek.ts#L636-L652) +### [`seek.leap`](../seek.ts#L639-L655) Leap forward. @@ -1186,7 +1186,7 @@ This command: -### [`seek.wordLabel`](../seek.ts#L870-L886) +### [`seek.wordLabel`](../seek.ts#L873-L889) Leap to word. diff --git a/src/commands/seek.ts b/src/commands/seek.ts index 8160814e..ee007610 100644 --- a/src/commands/seek.ts +++ b/src/commands/seek.ts @@ -480,16 +480,19 @@ export async function object( newSelections = Selections.mapByIndex((_i, selection, document) => { const activePosition = Selections.activePosition(selection, _.document); let shiftTo = f.start(activePosition, inner, document); + let skipCharacter = false; if (shiftTo.isEqual(activePosition)) { const activePositionBefore = Positions.previous(activePosition, document); + skipCharacter = _.selectionBehavior === SelectionBehavior.Character && !inner && shift === Shift.Select; + if (activePositionBefore !== undefined) { shiftTo = f.start(activePositionBefore, inner, document); } } - return Selections.shift(selection, shiftTo, shift, _); + return Selections.shift(selection, shiftTo, shift, _, skipCharacter); }); } else if (where === "end") { newSelections = Selections.mapByIndex((_i, selection, document) =>