branch: elpa/subed commit 7d76a352af88dba3b350ddf86fbe4c46beddc26d Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
Simplify subed-srt-move-to-subtitle-text --- subed/subed-srt.el | 5 ++--- tests/test-subed-srt.el | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/subed/subed-srt.el b/subed/subed-srt.el index a4156d3..44b0add 100644 --- a/subed/subed-srt.el +++ b/subed/subed-srt.el @@ -191,9 +191,8 @@ Return point or nil if no stop time could be found." Return point." (interactive) (when (subed-srt-move-to-subtitle-id sub-id) - (save-match-data - (when (re-search-forward (concat subed-srt--regexp-duration "[[:blank:]]*\n") nil t) - (point))))) + (forward-line 2) + (point))) (defun subed-srt-move-to-subtitle-text-at-msecs (msecs) "Move point to the text of the subtitle that is playing at MSECS. diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el index ed197f6..5d9b02f 100644 --- a/tests/test-subed-srt.el +++ b/tests/test-subed-srt.el @@ -390,18 +390,29 @@ Baz. (it "returns point when there is a previous subtitle." (with-temp-buffer (insert mock-srt-data) - (subed-srt-move-to-subtitle-id 2) - (expect (thing-at-point 'word) :to-equal "2") + (subed-srt-move-to-subtitle-text 2) + (expect (thing-at-point 'word) :to-equal "Bar") (expect (subed-srt-backward-subtitle-id) :to-be 1) - (expect (thing-at-point 'word) :to-equal "1"))) + (expect (thing-at-point 'word) :to-equal "1") + (subed-srt-move-to-subtitle-time-stop 3) + (expect (thing-at-point 'word) :to-equal "00") + (expect (subed-srt-backward-subtitle-id) :to-be 39) + (expect (thing-at-point 'word) :to-equal "2"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-buffer - (goto-char (point-min)) - (insert (concat mock-srt-data "\n\n")) + (expect (subed-srt-backward-subtitle-id) :to-be nil)) + (with-temp-buffer + (insert (concat mock-srt-data)) (subed-srt-move-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt-backward-subtitle-id) :to-be nil) - (expect (thing-at-point 'word) :to-equal "1"))) + (expect (thing-at-point 'word) :to-equal "1")) + (with-temp-buffer + (insert (concat mock-srt-data)) + (subed-srt-move-to-subtitle-text 1) + (expect (thing-at-point 'word) :to-equal "Foo") + (expect (subed-srt-backward-subtitle-id) :to-be nil) + (expect (thing-at-point 'word) :to-equal "Foo"))) ) (describe "to next subtitle text" (it "returns point when there is a next subtitle."