[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 14ebbbb 293/389: subed-srt--subtitle-id-at-msecs: Re
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 14ebbbb 293/389: subed-srt--subtitle-id-at-msecs: Return nil if no matching subtitle |
Date: |
Fri, 3 Dec 2021 11:00:44 -0500 (EST) |
branch: elpa/subed
commit 14ebbbb34909a980800f96f2010c9429b126a88b
Author: Random User <rndusr@posteo.de>
Commit: Random User <rndusr@posteo.de>
subed-srt--subtitle-id-at-msecs: Return nil if no matching subtitle
This fixes a bug which made point jump to the previous subtitle when
adjusting
times.
---
subed/subed-srt.el | 19 ++++++++-----------
tests/test-subed-srt.el | 16 ++++++++--------
2 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index ca98899..83bd2d4 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -77,9 +77,7 @@ Return nil if TIME-STRING doesn't match the pattern."
(defun subed-srt--subtitle-id-at-msecs (msecs)
"Return the ID of the subtitle at MSECS milliseconds.
-If MSECS is between subtitles, return the subtitle that starts
-after MSECS if there is one and its start time is >= MSECS +
-1000. Otherwise return the closest subtitle before MSECS."
+Return nil if there is no subtitle at MSECS."
(save-match-data
(save-excursion
(goto-char (point-min))
@@ -90,17 +88,16 @@ after MSECS if there is one and its start time is >= MSECS +
(when (re-search-forward (format "\\(%s\\|\\`\\)[0-9]+\n%02d:"
subed-srt--regexp-separator only-hours) nil t)
(beginning-of-line)
;; Move to first subtitle in the relevant hour and minute
- (re-search-forward (format "\\(\n\n\\|\\`\\)[0-9]+\n%02d:%02d"
only-hours only-mins) nil t)))
+ (re-search-forward (format "\\(\n\n\\|\\`\\)[0-9]+\n%02d:%02d"
only-hours only-mins) nil t))
;; Move to first subtitle that starts at or after MSECS
- (catch 'last-subtitle-reached
+ (catch 'subtitle-id
(while (<= (or (subed-srt--subtitle-msecs-start) -1) msecs)
+ ;; If stop time is >= MSECS, we found a match
+ (let ((cur-sub-end (subed-srt--subtitle-msecs-stop)))
+ (when (and cur-sub-end (>= cur-sub-end msecs))
+ (throw 'subtitle-id (subed-srt--subtitle-id))))
(unless (subed-srt--forward-subtitle-id)
- (throw 'last-subtitle-reached nil))))
- ;; Move back to previous subtitle if start of current subtitle is in the
- ;; future (i.e. MSECS is between subtitles)
- (when (> (or (subed-srt--subtitle-msecs-start) -1) msecs)
- (subed-srt--backward-subtitle-id))
- (subed-srt--subtitle-id))))
+ (throw 'subtitle-id nil))))))))
(defun subed-srt--subtitle-msecs-start (&optional sub-id)
"Subtitle start time in milliseconds or nil if it can't be found.
diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el
index 8585c3a..2ae1832 100644
--- a/tests/test-subed-srt.el
+++ b/tests/test-subed-srt.el
@@ -61,7 +61,7 @@ Baz.
(progn
(subed-srt--jump-to-subtitle-id outset-id)
(expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
- (it "returns first subtitle ID if time is before the first subtitle's
start time."
+ (it "returns nil if time is before the first subtitle's start time."
(with-temp-srt-buffer
(insert mock-srt-data)
(let ((msecs (- (save-excursion
@@ -70,8 +70,8 @@ Baz.
(cl-loop for outset-id from 1 to 3 do
(progn
(subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal
1))))))
- (it "returns last subtitle ID if time is after the last subtitle's start
time."
+ (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal
nil))))))
+ (it "returns nil if time is after the last subtitle's start time."
(with-temp-srt-buffer
(insert mock-srt-data)
(let ((msecs (+ (save-excursion
@@ -80,8 +80,8 @@ Baz.
(cl-loop for outset-id from 1 to 3 do
(progn
(subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal
3))))))
- (it "returns previous subtitle ID when time is between subtitles."
+ (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal
nil))))))
+ (it "returns nil if time is between subtitles."
(with-temp-srt-buffer
(insert mock-srt-data)
(cl-loop for target-id from 1 to 2 do
@@ -89,13 +89,13 @@ Baz.
(cl-loop for outset-id from 1 to 3 do
(progn
(subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal target-id))))
+ (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal nil))))
(let ((msecs (- (subed-srt--subtitle-msecs-start (+ target-id
1)) 1)))
(cl-loop for outset-id from 1 to 3 do
(progn
(subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
- (it "doesn't fail when start time is invalid."
+ (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal nil)))))))
+ (it "doesn't fail if start time is invalid."
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-srt--jump-to-subtitle-id 2)
- [nongnu] elpa/subed e065632 362/389: Fix previous commit for subed-set-subtitle-text, (continued)
- [nongnu] elpa/subed e065632 362/389: Fix previous commit for subed-set-subtitle-text, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed ec7b222 368/389: Enable CPS showing by default and improve CPS toggling functions, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed f28ad22 379/389: Make subed-mpv-jump-to-current-subtitle interactive, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed c76ba50 387/389: Prompt for playback speed factor, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 9d0aa0f 388/389: Make make-subtitle a generic function, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed d0dfa1a 389/389: Preliminary support for .ass files (Advanced SubStation Alpha), ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed f30780e 249/389: Default keybinding: C-M-i -> subed-insert-subtitle-adjacent, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed f8793fb 330/389: Move motion hooks from subed-config.el to subed-common.el, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 31556c6 372/389: Add functions for bold and italic and change keybindings, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed ba22919 289/389: Add subed-mpv-jump-to-current-subtitle, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 14ebbbb 293/389: subed-srt--subtitle-id-at-msecs: Return nil if no matching subtitle,
ELPA Syncer <=
- [nongnu] elpa/subed 2e18727 294/389: Pause video initially, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3d5902b 295/389: Reword comment, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3baf5c1 296/389: subed-mpv--client-filter: Store process mark in variable, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 08d5033 301/389: Remove unused variable subed-mode--enabled-p, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 070384b 302/389: subed--set-subtitle-loop: Don't croak on empty file, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 89df304 304/389: subed-srt--sanitize: Don't insert newline in empty buffer, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b0a4ff0 307/389: Fix parentheses, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 8007c12 308/389: Make debugging window a bit smaller, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed ec38a0b 317/389: Add function: subed-mpv-add-subtitles, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 7764909 324/389: Add some (require ...)s to prevent compiler warnings, ELPA Syncer, 2021/12/03