Skip to content

Commit

Permalink
Allow backspace to delete a char when inside leftmost token (#1768)
Browse files Browse the repository at this point in the history
* Allow backspace to delete a char when inside a token

Regression in #1741

Fixes #1771

Fixes this the problem shown in this comment: #1745 (comment)

And this Slack thread:
https://clojurians.slack.com/archives/CBE668G4R/p1654897313506689

Co-authored-by: Peter Strömberg <pez@pezius.com>
  • Loading branch information
isaksky and PEZ authored Jun 11, 2022
1 parent a7c8394 commit d829fba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- Fix: [Paredit strict backspace in the leftmost symbol/keyword/thing inserts a space instead](https://github.com/BetterThanTomorrow/calva/pull/1771)

## [2.0.284] - 2022-06-11

- [Add a command to restart clojure-lsp](https://github.com/BetterThanTomorrow/calva/issues/1727)
Expand Down
2 changes: 2 additions & 0 deletions src/cursor-doc/paredit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ function onlyWhitespaceLeftOfCursor(doc: EditableDocument, cursor: LispTokenCurs
const token = cursor.getToken();
if (token.type === 'ws') {
return token.offset === 0;
} else if (doc.selection.anchor > cursor.offsetStart) {
return false;
}
const prevToken = cursor.getPrevToken();

Expand Down
7 changes: 7 additions & 0 deletions src/extension-test/unit/cursor-doc/paredit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,13 @@ describe('paredit', () => {
await paredit.backspace(a);
expect(textAndSelection(a)).toEqual(textAndSelection(b));
});

it('Deletes a character when inside a token on a blank line', async () => {
const a = docFromTextNotation('(if• :|foo)');
const b = docFromTextNotation('(if• |foo)');
await paredit.backspace(a);
expect(textAndSelection(a)).toEqual(textAndSelection(b));
});
});

describe('Kill character forwards (delete)', () => {
Expand Down

0 comments on commit d829fba

Please sign in to comment.