Skip to content

Commit

Permalink
Merge pull request #1716 from LeeLaffan/vi-fix-viq-freeze-editor
Browse files Browse the repository at this point in the history
vi-mode - Bug - Fix freeze when using _i"/_a" in escaped string
  • Loading branch information
cxxxr authored Dec 27, 2024
2 parents cc37f10 + 5f2f143 commit 8937771
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
17 changes: 13 additions & 4 deletions extensions/vi-mode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ Here's a list of all options currently implemented:
* Default: `nil` (don't show)
* Aliases: `nu`

## Unittests

```
## Unit Tests

### Command Line

```bash
qlot install
.qlot/bin/rove extensions/vi-mode/lem-vi-mode.asd
```
```

### In Lem

Use `C-c C-r` or:
```common-lisp Example Test
(rove:run-test 'lem-vi-mode/tests/text-objects::word-object)
```
18 changes: 17 additions & 1 deletion extensions/vi-mode/tests/text-objects.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,20 @@
(ok (buf= " \"foo\"< \"bar[\"]>")))
(with-vi-buffer (" \"foo\" \"bar[\"]")
(cmd "va\"")
(ok (buf= " \"foo\"< \"bar[\"]>")))))
(ok (buf= " \"foo\"< \"bar[\"]>")))

;; Escape Character
; v i
(with-vi-buffer (" \" f[o]o \\\" bar \"")
(cmd "vi\"")
(ok (buf= " \"< foo \\\" bar[ ]>\"")))
(with-vi-buffer (" \" foo \\\" b[a]r \"")
(cmd "vi\"")
(ok (buf= " \"< foo \\\" bar[ ]>\"")))
; v a
(with-vi-buffer (" \" f[o]o \\\" bar \"")
(cmd "va\"")
(ok (buf= " <\" foo \\\" bar [\"]>")))
(with-vi-buffer (" \" foo \\\" b[a]r \"")
(cmd "va\"")
(ok (buf= " <\" foo \\\" bar [\"]>")))))
20 changes: 14 additions & 6 deletions extensions/vi-mode/text-objects.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,14 @@
;; No quote-char found
((null prev-char)
(keyboard-quit))
;; Skip escaped quote-char
((and escape-char
(char= prev-char escape-char)))
;; Successfully found

;; Skip escape & quote-char
((and escape-char
(character-at point -2) ;; Bound check
(char= (character-at point -2) escape-char))
(character-offset point -2))

;; Successfully found unescaped quote
(t
(character-offset point -1)
(return))))))
Expand All @@ -304,9 +308,13 @@
;; No quote-char found
((null next-char)
(keyboard-quit))
;; Skip escaped quote-char

;; Skip escape & quote-char
((and escape-char
(char= (character-at point -1) escape-char)))
(character-at point 2) ;; Bound Check
(char= (character-at point -1) escape-char))
(character-offset point 2))

;; Successfully found
(t
(character-offset point 1)
Expand Down

0 comments on commit 8937771

Please sign in to comment.