From a0de3315e7354811a5ea7be5f4cff9f7590027f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Str=C3=B6mberg?= Date: Mon, 22 Apr 2024 23:07:55 +0200 Subject: [PATCH 1/4] Add tests for drag-backwards past ignore --- .../unit/cursor-doc/paredit-test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/extension-test/unit/cursor-doc/paredit-test.ts b/src/extension-test/unit/cursor-doc/paredit-test.ts index ccfbfeb04..7af754b69 100644 --- a/src/extension-test/unit/cursor-doc/paredit-test.ts +++ b/src/extension-test/unit/cursor-doc/paredit-test.ts @@ -1464,6 +1464,33 @@ describe('paredit', () => { await paredit.dragSexprBackward(a, ['b']); expect(textAndSelection(a)).toEqual(textAndSelection(b)); }); + + describe('Ignore markers', () => { + it('Drags past symbol', async () => { + const a = docFromTextNotation('#_a (:b c)|'); + const b = docFromTextNotation('#_(:b c)| a'); + await paredit.dragSexprBackward(a); + expect(textAndSelection(a)).toEqual(textAndSelection(b)); + }); + it('Drags past map', async () => { + const a = docFromTextNotation('#_{:a b} (:c d)|'); + const b = docFromTextNotation('#_(:c d)| {:a b}'); + await paredit.dragSexprBackward(a); + expect(textAndSelection(a)).toEqual(textAndSelection(b)); + }); + it('Drags past ignore after newline', async () => { + const a = docFromTextNotation('(:a b)•#_{:c d}|'); + const b = docFromTextNotation('(:a b)•{:c d}|#_'); + await paredit.dragSexprBackward(a); + expect(textAndSelection(a)).toEqual(textAndSelection(b)); + }); + it('Drags past ignore after space', async () => { + const a = docFromTextNotation('(:a b) #_{:c d}|'); + const b = docFromTextNotation('(:a b) {:c d}|#_'); + await paredit.dragSexprBackward(a); + expect(textAndSelection(a)).toEqual(textAndSelection(b)); + }); + }); }); describe('backwardUp - one line', () => { From 594d7f0748f28589ed8506685138bbf70d8a9548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Str=C3=B6mberg?= Date: Mon, 22 Apr 2024 23:08:21 +0200 Subject: [PATCH 2/4] Add some tests for currentSexpRange --- .../unit/cursor-doc/paredit-test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/extension-test/unit/cursor-doc/paredit-test.ts b/src/extension-test/unit/cursor-doc/paredit-test.ts index 7af754b69..5d1126dd3 100644 --- a/src/extension-test/unit/cursor-doc/paredit-test.ts +++ b/src/extension-test/unit/cursor-doc/paredit-test.ts @@ -1493,6 +1493,35 @@ describe('paredit', () => { }); }); + describe('currentSexpsRange', () => { + const docSelectionCursorPosition = (positionNotation: string, rangeNotation: string) => { + const positionDoc = docFromTextNotation(positionNotation); + const rangeDoc = docFromTextNotation(rangeNotation); + const [_text1, positionSelection] = textAndSelection(positionDoc); + const position = positionSelection[0]; + const [_text2, selection] = textAndSelection(rangeDoc); + const cursor = positionDoc.getTokenCursor(position); + return { doc: positionDoc, selection: selection, cursor, position }; + }; + + it('Finds range with cursor between ignore marker and form, separated by whitespace before', () => { + const { doc, selection, cursor, position } = docSelectionCursorPosition( + '#_ |(:a b)', + '#_ |(:a b)|' + ); + const range = paredit.currentSexpsRange(doc, cursor, position, false); + expect(range).toStrictEqual(selection); + }); + it('Finds range with cursor between ignore marker and form, no whitespace', () => { + const { doc, selection, cursor, position } = docSelectionCursorPosition( + '#_|(:a b)', + '#_|(:a b)|' + ); + const range = paredit.currentSexpsRange(doc, cursor, position, false); + expect(range).toStrictEqual(selection); + }); + }); + describe('backwardUp - one line', () => { it('Drags up from start of vector', async () => { const b = docFromTextNotation(`(def foo [:|foo :bar :baz])`); 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 3/4] 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', () => { From b2c966f8b9ee1eba4d3f0c39cd4860ed84e03cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Str=C3=B6mberg?= Date: Tue, 23 Apr 2024 09:35:08 +0200 Subject: [PATCH 4/4] Experiment, treat ignores as reader tags more --- src/cursor-doc/token-cursor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cursor-doc/token-cursor.ts b/src/cursor-doc/token-cursor.ts index 657697661..741d12c23 100644 --- a/src/cursor-doc/token-cursor.ts +++ b/src/cursor-doc/token-cursor.ts @@ -405,7 +405,7 @@ export class LispTokenCursor extends TokenCursor { let hasReader = false; while (true) { cursor.backwardWhitespace(); - if (cursor.getPrevToken().type === 'reader') { + if (['reader', 'ignore'].includes(cursor.getPrevToken().type)) { cursor.previous(); this.set(cursor); hasReader = true; @@ -425,7 +425,7 @@ export class LispTokenCursor extends TokenCursor { let hasReader = false; while (true) { cursor.forwardWhitespace(); - if (cursor.getToken().type === 'reader') { + if (['reader', 'ignore'].includes(cursor.getToken().type)) { cursor.next(); this.set(cursor); hasReader = true;