emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/markdown-mode 18c4e04 1/2: Fixing table navigation bug. Ad


From: ELPA Syncer
Subject: [nongnu] elpa/markdown-mode 18c4e04 1/2: Fixing table navigation bug. Adding tests.
Date: Tue, 16 Feb 2021 03:57:10 -0500 (EST)

branch: elpa/markdown-mode
commit 18c4e04249802cd141ab68e5b750fb6d9688f7ef
Author: Jared Finder <jared@finder.org>
Commit: Jared Finder <jared@finder.org>

    Fixing table navigation bug.  Adding tests.
---
 CHANGES.md             |  1 +
 markdown-mode.el       | 16 ++++++++++++----
 tests/markdown-test.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 8ef39e4..34e2cf7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -41,6 +41,7 @@
     -   Fix creating imenu index issue when there is no level-1 header 
too[GH-571][]
     -   Fix highlighting consecutive HTML comments[GH-584][]
     -   Fix `markdown-follow-thing-at-point` failing on subdir search 
[GH-590][]
+    -   Fix `markdown-table-backward-cell' so it always goes back a single cell
 
   [gh-290]: https://github.com/jrblevin/markdown-mode/issues/290
   [gh-311]: https://github.com/jrblevin/markdown-mode/issues/311
diff --git a/markdown-mode.el b/markdown-mode.el
index e0eec96..9fd73b3 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -9247,15 +9247,23 @@ Create new table lines if required."
   (unless (markdown-table-at-point-p)
     (user-error "Not at a table"))
   (markdown-table-align)
-  (when (markdown-table-hline-at-point-p) (end-of-line 1))
+  (when (markdown-table-hline-at-point-p) (beginning-of-line 1))
   (condition-case nil
       (progn
         (re-search-backward "\\(?:^\\|[^\\]\\)|" (markdown-table-begin))
+        ;; When this function is called while in the first cell in a
+        ;; table, the point will now be at the beginning of a line. In
+        ;; this case, we need to move past one additional table
+        ;; boundary, the end of the table on the previous line.
+        (when (= (point) (line-beginning-position))
+          (re-search-backward "\\(?:^\\|[^\\]\\)|" (markdown-table-begin)))
         (re-search-backward "\\(?:^\\|[^\\]\\)|" (markdown-table-begin)))
     (error (user-error "Cannot move to previous table cell")))
-  (while (looking-at "|\\([-:]\\|[ \t]*$\\)")
-    (re-search-backward "\\(?:^\\|[^\\]\\)|" (markdown-table-begin)))
-  (when (looking-at "| ?") (goto-char (match-end 0))))
+  (when (looking-at "\\(?:^\\|[^\\]\\)| ?") (goto-char (match-end 0)))
+
+  ;; This may have dropped point on the hline.
+  (when (markdown-table-hline-at-point-p)
+    (markdown-table-backward-cell)))
 
 (defun markdown-table-transpose ()
   "Transpose table at point.
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index e32ebb6..7865f2c 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -6799,6 +6799,53 @@ title: asdasdasd
     (search-forward "title: ")
     (should (markdown-test-flyspell-incorrect-word-p))))
 
+(ert-deftest test-markdown-table/navigation-forward-cell ()
+  "Test table navigation."
+  (markdown-test-string "
+| 1  | 2  | 3  | 4  |
+|----|----|----|----|
+| 5  | 6  | 7  | 8  |
+| 9  | 10 | 11 | 12 |"
+    (search-forward "1 ")
+    (let ((index 2))
+      (while (<= index 12)
+        (markdown-table-forward-cell)
+        (should (looking-at (format "%d" index)))
+        (cl-incf index)))))
+
+(ert-deftest test-markdown-table/navigation-backward-cell ()
+  "Test table navigation."
+  (markdown-test-string "
+| 1  | 2  | 3  | 4  |
+|----|----|----|----|
+| 5  | 6  | 7  | 8  |
+| 9  | 10 | 11 | 12 |
+"
+    (search-forward "12")
+    (let ((index 11))
+      (while (>= index 1)
+        (markdown-table-backward-cell)
+        (should (looking-at (format "%d" index)))
+        (cl-decf index)))))
+
+(ert-deftest test-markdown-table/align ()
+  "Test table realignment."
+  (markdown-test-string "
+| Header 1 |Header 2|
+|------|----|
+| | |
+| A very very very long cell| |
+"
+    (search-forward "Header")
+    (markdown-table-align)
+    (message "\"%s\"" (buffer-string))
+    (should (string= (buffer-string) "
+| Header 1                   | Header 2 |
+|----------------------------|----------|
+|                            |          |
+| A very very very long cell |          |
+"))))
+
 (provide 'markdown-test)
 
 ;;; markdown-test.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]