diff --git a/src/cursor-doc/token-cursor.ts b/src/cursor-doc/token-cursor.ts index f4e91b041..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; @@ -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/paredit-test.ts b/src/extension-test/unit/cursor-doc/paredit-test.ts index ccfbfeb04..5d1126dd3 100644 --- a/src/extension-test/unit/cursor-doc/paredit-test.ts +++ b/src/extension-test/unit/cursor-doc/paredit-test.ts @@ -1464,6 +1464,62 @@ 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('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', () => { 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', () => {