diff options
| author | Juri Linkov | 2023-11-20 19:57:57 +0200 |
|---|---|---|
| committer | Juri Linkov | 2023-11-20 19:57:57 +0200 |
| commit | 9d292262f55cd016a1a59f4d4ef31446bb2ba9c6 (patch) | |
| tree | f7def64147b0769a09687741c4df871e8d1a5a2f /test | |
| parent | 5024ee1ad18904bc0a0e7a8f740164157649af5e (diff) | |
| download | emacs-9d292262f55cd016a1a59f4d4ef31446bb2ba9c6.tar.gz emacs-9d292262f55cd016a1a59f4d4ef31446bb2ba9c6.zip | |
Improve invisibility handling in isearch-lazy-highlight (bug#40808)
* lisp/isearch.el (isearch-lazy-highlight-invisible): New variable.
(isearch-lazy-highlight-new-loop, isearch-lazy-highlight-search)
(isearch-lazy-highlight-match, isearch-lazy-highlight-buffer-update): Use it.
* lisp/replace.el (replace-highlight): Let-bind isearch-invisible
to search-invisible.
* test/lisp/isearch-tests.el (isearch--test-invisible): New test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/isearch-tests.el | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/test/lisp/isearch-tests.el b/test/lisp/isearch-tests.el index e71f0a5785f..693f15336f2 100644 --- a/test/lisp/isearch-tests.el +++ b/test/lisp/isearch-tests.el | |||
| @@ -39,6 +39,157 @@ | |||
| 39 | (isearch-done)) | 39 | (isearch-done)) |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | ;; Search invisible. | ||
| 43 | |||
| 44 | (declare-function outline-hide-sublevels "outline") | ||
| 45 | |||
| 46 | (ert-deftest isearch--test-invisible () | ||
| 47 | (require 'outline) | ||
| 48 | (with-temp-buffer | ||
| 49 | (set-window-buffer nil (current-buffer)) | ||
| 50 | (insert "\n1\n" | ||
| 51 | (propertize "2" 'invisible t) | ||
| 52 | (propertize "3" 'inhibit-isearch t) | ||
| 53 | "\n* h\n4\n\n") | ||
| 54 | (outline-mode) | ||
| 55 | (outline-hide-sublevels 1) | ||
| 56 | (goto-char (point-min)) | ||
| 57 | |||
| 58 | (let ((isearch-lazy-count nil) | ||
| 59 | (search-invisible t) | ||
| 60 | (inhibit-message t)) | ||
| 61 | |||
| 62 | (isearch-forward-regexp nil 1) | ||
| 63 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 64 | (should (eq (point) 3)) | ||
| 65 | |||
| 66 | (isearch-lazy-highlight-start) | ||
| 67 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 68 | '(2))) | ||
| 69 | |||
| 70 | (isearch-repeat-forward) | ||
| 71 | (should (eq (point) 5)) | ||
| 72 | (should (get-char-property 4 'invisible)) | ||
| 73 | (isearch-repeat-forward) | ||
| 74 | (should (eq (point) 12)) | ||
| 75 | (should (get-char-property 11 'invisible)) | ||
| 76 | |||
| 77 | (goto-char isearch-opoint) | ||
| 78 | (isearch-done t) | ||
| 79 | |||
| 80 | (isearch-forward-regexp nil 1) | ||
| 81 | (setq isearch-invisible nil) ;; isearch-toggle-invisible | ||
| 82 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 83 | |||
| 84 | (isearch-lazy-highlight-start) | ||
| 85 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 86 | '(2))) | ||
| 87 | |||
| 88 | (goto-char isearch-opoint) | ||
| 89 | (isearch-done t) | ||
| 90 | |||
| 91 | (isearch-forward-regexp nil 1) | ||
| 92 | (setq isearch-invisible 'open) ;; isearch-toggle-invisible | ||
| 93 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 94 | (should (eq (point) 3)) | ||
| 95 | |||
| 96 | (isearch-lazy-highlight-start) | ||
| 97 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 98 | '(2 11))) | ||
| 99 | |||
| 100 | (let ((isearch-hide-immediately t)) | ||
| 101 | (isearch-repeat-forward) | ||
| 102 | (should (eq (point) 12)) | ||
| 103 | (should-not (get-char-property 11 'invisible)) | ||
| 104 | (isearch-delete-char) | ||
| 105 | (should (get-char-property 11 'invisible))) | ||
| 106 | |||
| 107 | (let ((isearch-hide-immediately nil)) | ||
| 108 | (isearch-repeat-forward) | ||
| 109 | (should (eq (point) 12)) | ||
| 110 | (should-not (get-char-property 11 'invisible)) | ||
| 111 | (isearch-delete-char) | ||
| 112 | (should-not (get-char-property 11 'invisible))) | ||
| 113 | |||
| 114 | (goto-char isearch-opoint) | ||
| 115 | (isearch-done t) | ||
| 116 | (isearch-clean-overlays) | ||
| 117 | (should (get-char-property 11 'invisible))) | ||
| 118 | |||
| 119 | (let ((isearch-lazy-count t) | ||
| 120 | (search-invisible t) | ||
| 121 | (inhibit-message t)) | ||
| 122 | |||
| 123 | (isearch-forward-regexp nil 1) | ||
| 124 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 125 | (should (eq (point) 3)) | ||
| 126 | |||
| 127 | (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) | ||
| 128 | (isearch-lazy-highlight-start) | ||
| 129 | (isearch-lazy-highlight-buffer-update) | ||
| 130 | (should (eq isearch-lazy-count-invisible nil)) | ||
| 131 | (should (eq isearch-lazy-count-total 3)) | ||
| 132 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 133 | '(2))) | ||
| 134 | |||
| 135 | (isearch-repeat-forward) | ||
| 136 | (should (eq (point) 5)) | ||
| 137 | (should (get-char-property 4 'invisible)) | ||
| 138 | (isearch-repeat-forward) | ||
| 139 | (should (eq (point) 12)) | ||
| 140 | (should (get-char-property 11 'invisible)) | ||
| 141 | |||
| 142 | (goto-char isearch-opoint) | ||
| 143 | (isearch-done t) | ||
| 144 | |||
| 145 | (isearch-forward-regexp nil 1) | ||
| 146 | (setq isearch-invisible nil) ;; isearch-toggle-invisible | ||
| 147 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 148 | |||
| 149 | (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) | ||
| 150 | (isearch-lazy-highlight-start) | ||
| 151 | (isearch-lazy-highlight-buffer-update) | ||
| 152 | (should (eq isearch-lazy-count-invisible 2)) | ||
| 153 | (should (eq isearch-lazy-count-total 1)) | ||
| 154 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 155 | '(2))) | ||
| 156 | |||
| 157 | (goto-char isearch-opoint) | ||
| 158 | (isearch-done t) | ||
| 159 | |||
| 160 | (isearch-forward-regexp nil 1) | ||
| 161 | (setq isearch-invisible 'open) ;; isearch-toggle-invisible | ||
| 162 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 163 | (should (eq (point) 3)) | ||
| 164 | |||
| 165 | (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) | ||
| 166 | (isearch-lazy-highlight-start) | ||
| 167 | (isearch-lazy-highlight-buffer-update) | ||
| 168 | (should (eq isearch-lazy-count-invisible 1)) | ||
| 169 | (should (eq isearch-lazy-count-total 2)) | ||
| 170 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 171 | '(2 11))) | ||
| 172 | |||
| 173 | (let ((isearch-hide-immediately t)) | ||
| 174 | (isearch-repeat-forward) | ||
| 175 | (should (eq (point) 12)) | ||
| 176 | (should-not (get-char-property 11 'invisible)) | ||
| 177 | (isearch-delete-char) | ||
| 178 | (should (get-char-property 11 'invisible))) | ||
| 179 | |||
| 180 | (let ((isearch-hide-immediately nil)) | ||
| 181 | (isearch-repeat-forward) | ||
| 182 | (should (eq (point) 12)) | ||
| 183 | (should-not (get-char-property 11 'invisible)) | ||
| 184 | (isearch-delete-char) | ||
| 185 | (should-not (get-char-property 11 'invisible))) | ||
| 186 | |||
| 187 | (goto-char isearch-opoint) | ||
| 188 | (isearch-done t) | ||
| 189 | (isearch-clean-overlays) | ||
| 190 | (should (get-char-property 11 'invisible))))) | ||
| 191 | |||
| 192 | |||
| 42 | ;; Search functions. | 193 | ;; Search functions. |
| 43 | 194 | ||
| 44 | (defun isearch--test-search-within-boundaries (pairs) | 195 | (defun isearch--test-search-within-boundaries (pairs) |