From 271af1166042bfa06de7c7fbe55d3fbfa2f39679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Str=C3=B6mberg?= Date: Mon, 22 Apr 2024 23:09:01 +0200 Subject: [PATCH] Fix find current form when squeezed between ignore and list --- src/cursor-doc/token-cursor.ts | 1 + .../unit/cursor-doc/token-cursor-test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/cursor-doc/token-cursor.ts b/src/cursor-doc/token-cursor.ts index f4e91b041..657697661 100644 --- a/src/cursor-doc/token-cursor.ts +++ b/src/cursor-doc/token-cursor.ts @@ -653,6 +653,7 @@ export class LispTokenCursor extends TokenCursor { cursor.getToken().type !== 'reader' && !cursor.tokenBeginsMetadata() && cursor.getPrevToken().type !== 'reader' && + cursor.getPrevToken().type !== 'ignore' && !cursor.prevTokenBeginsMetadata() ) { if (cursor.backwardSexp() && !cursor.tokenBeginsMetadata()) { diff --git a/src/extension-test/unit/cursor-doc/token-cursor-test.ts b/src/extension-test/unit/cursor-doc/token-cursor-test.ts index 9c2692180..6c210edb4 100644 --- a/src/extension-test/unit/cursor-doc/token-cursor-test.ts +++ b/src/extension-test/unit/cursor-doc/token-cursor-test.ts @@ -747,6 +747,18 @@ describe('Token Cursor', () => { const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].anchor); expect(cursor.rangeForCurrentForm(a.selections[0].anchor)).toBeUndefined(); }); + it('Selects atomic form to the right, when squeezed by an ignore marker', () => { + const a = docFromTextNotation('#_|a'); + const b = docFromTextNotation('#_|a|'); + const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].anchor); + expect(cursor.rangeForCurrentForm(a.selections[0].anchor)).toEqual(textAndSelection(b)[1]); + }); + it('Selects list form to the right, when squeezed by an ignore marker', () => { + const a = docFromTextNotation('#_|(a)'); + const b = docFromTextNotation('#_|(a)|'); + const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].anchor); + expect(cursor.rangeForCurrentForm(a.selections[0].anchor)).toEqual(textAndSelection(b)[1]); + }); }); describe('Top Level Form', () => {