From 5f2f1436c1e04e20726ce8e056f3f065ffc3a9f0 Mon Sep 17 00:00:00 2001 From: LeeLaffan Date: Thu, 26 Dec 2024 04:39:25 +0000 Subject: [PATCH] bug: vi-mode - Fix editor freeze with _ i/a " --- extensions/vi-mode/README.md | 17 +++++++++++++---- extensions/vi-mode/tests/text-objects.lisp | 18 +++++++++++++++++- extensions/vi-mode/text-objects.lisp | 20 ++++++++++++++------ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/extensions/vi-mode/README.md b/extensions/vi-mode/README.md index b9c439178..9430de968 100644 --- a/extensions/vi-mode/README.md +++ b/extensions/vi-mode/README.md @@ -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 -``` \ No newline at end of file +``` + +### In Lem + +Use `C-c C-r` or: +```common-lisp Example Test + (rove:run-test 'lem-vi-mode/tests/text-objects::word-object) +``` diff --git a/extensions/vi-mode/tests/text-objects.lisp b/extensions/vi-mode/tests/text-objects.lisp index 8822a072e..c63190d30 100644 --- a/extensions/vi-mode/tests/text-objects.lisp +++ b/extensions/vi-mode/tests/text-objects.lisp @@ -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 [\"]>"))))) diff --git a/extensions/vi-mode/text-objects.lisp b/extensions/vi-mode/text-objects.lisp index 47f87060c..aab0ccc05 100644 --- a/extensions/vi-mode/text-objects.lisp +++ b/extensions/vi-mode/text-objects.lisp @@ -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)))))) @@ -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)