[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 016c6a5 363/389: subed-split-subtitle: Handle more c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 016c6a5 363/389: subed-split-subtitle: Handle more cases |
Date: |
Fri, 3 Dec 2021 11:00:58 -0500 (EST) |
branch: elpa/subed
commit 016c6a54444cc3b6b267c138c2cc98586175031f
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
subed-split-subtitle: Handle more cases
* tests/test-subed-common.el ("Splitting subtitles"): Handle more
cases, like when there's a subtitle afterwards.
* subed/subed-common.el (subed-split-subtitle): Skip backward over newlines.
---
subed/subed-common.el | 1 +
tests/test-subed-common.el | 199 +++++++++++++++++++++++++++++++++------------
2 files changed, 147 insertions(+), 53 deletions(-)
diff --git a/subed/subed-common.el b/subed/subed-common.el
index 5b5be90..e5d3fa8 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -675,6 +675,7 @@ position of the point."
(new-text (string-trim (buffer-substring (point) text-end)))
(new-start-timestamp (+ split-timestamp subed-subtitle-spacing)))
(subed-set-subtitle-time-stop split-timestamp)
+ (skip-chars-backward "\n")
(delete-region (point) (progn (subed-jump-to-subtitle-end)
(skip-chars-forward " \t") (point)))
(when (looking-at "[ \t]+") (replace-match ""))
(subed-append-subtitle nil new-start-timestamp orig-end (string-trim
new-text)))
diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el
index 5bb3cc3..4a941fd 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -2153,20 +2153,21 @@ Baz.
")))
(describe "when there are multiple lines"
- :var ((text "1
+ (describe "at the last subtitle"
+ :var ((text "1
00:01:23,000 --> 00:02:34,567
This is a subtitle
that has two lines.
")
- (subed-subtitle-spacing 100))
- (it "properly splits text when called at the beginning of the subtitle."
- (with-temp-srt-buffer
- (insert text)
- (re-search-backward "This is a subtitle")
- (goto-char (match-beginning 0))
- (save-excursion (subed-split-subtitle 100))
- (expect (buffer-string) :to-equal "1
+ (subed-subtitle-spacing 100))
+ (it "properly splits text when called at the beginning of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "This is a subtitle")
+ (goto-char (match-beginning 0))
+ (save-excursion (subed-split-subtitle 100))
+ (expect (buffer-string) :to-equal "1
00:01:23,000 --> 00:01:23,100
@@ -2175,50 +2176,142 @@ that has two lines.
This is a subtitle
that has two lines.
")))
- (it "properly splits text when called in the middle of the subtitle."
- (with-temp-srt-buffer
- (insert text)
- (re-search-backward "This is a")
- (goto-char (match-end 0))
- (subed-split-subtitle 100)
- (expect (subed-subtitle-text 1) :to-equal "This is a")
- (subed-regenerate-ids)
- (expect (subed-subtitle-text 2) :to-equal "subtitle\nthat has two
lines.")))
- (it "properly splits text when called at the end of a line in the middle
of the subtitle"
- (with-temp-srt-buffer
- (insert text)
- (re-search-backward "This is a subtitle")
- (goto-char (match-end 0))
- (subed-split-subtitle 100)
- (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
- (subed-regenerate-ids)
- (expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
- (it "properly splits text when called at the beginning of a line in the
middle of the subtitle."
- (with-temp-srt-buffer
- (insert text)
- (re-search-backward "that has two lines")
- (goto-char (match-beginning 0))
- (subed-split-subtitle 100)
- (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
- (subed-regenerate-ids)
- (expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
- (it "properly splits text when called at the end of the subtitle."
- (with-temp-srt-buffer
- (insert text)
- (subed-jump-to-subtitle-end 1)
- (subed-split-subtitle 100)
- (expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
- (subed-regenerate-ids)
- (expect (subed-subtitle-text 2) :to-equal "")))
- (it "properly splits text when called before whitespace at the end of the
subtitle."
- (with-temp-srt-buffer
- (insert text)
- (subed-jump-to-subtitle-end 1)
- (save-excursion (insert " "))
- (subed-split-subtitle 100)
- (expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
- (subed-regenerate-ids)
- (expect (subed-subtitle-text 2) :to-equal ""))))
+ (it "properly splits text when called in the middle of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "This is a")
+ (goto-char (match-end 0))
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "subtitle\nthat has two
lines.")))
+ (it "properly splits text when called at the end of a line in the middle
of the subtitle"
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "This is a subtitle")
+ (goto-char (match-end 0))
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
+ (it "properly splits text when called at the beginning of a line in the
middle of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "that has two lines")
+ (goto-char (match-beginning 0))
+ (subed-split-subtitle 100)
+ (expect (buffer-string) :to-equal "1
+00:01:23,000 --> 00:01:23,100
+This is a subtitle
+
+0
+00:01:23,200 --> 00:02:34,567
+that has two lines.
+") (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
+ (it "properly splits text when called at the end of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (subed-jump-to-subtitle-end 1)
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "")))
+ (it "properly splits text when called before whitespace at the end of
the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (subed-jump-to-subtitle-end 1)
+ (save-excursion (insert " "))
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal ""))))
+ (describe "with another subtitle after it"
+ :var ((text "1
+00:01:23,000 --> 00:02:34,567
+This is a subtitle
+that has two lines.
+
+2
+00:05:00,000 --> 00:06:00,000
+This is another.
+")
+ (subed-subtitle-spacing 100))
+ (it "properly splits text when called at the beginning of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "This is a subtitle")
+ (goto-char (match-beginning 0))
+ (save-excursion (subed-split-subtitle 100))
+ (expect (buffer-string) :to-equal "1
+00:01:23,000 --> 00:01:23,100
+
+0
+00:01:23,200 --> 00:02:34,567
+This is a subtitle
+that has two lines.
+
+2
+00:05:00,000 --> 00:06:00,000
+This is another.
+")))
+ (it "properly splits text when called in the middle of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "This is a subtitle")
+ (goto-char (match-end 0))
+ (backward-word 1)
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "subtitle\nthat has two
lines.")))
+ (it "properly splits text when called at the end of a line in the middle
of the subtitle"
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "This is a subtitle")
+ (goto-char (match-end 0))
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
+ (it "properly splits text when called at the beginning of a line in the
middle of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "that has two lines")
+ (goto-char (match-beginning 0))
+ (subed-split-subtitle 100)
+ (expect (buffer-string) :to-equal "1
+00:01:23,000 --> 00:01:23,100
+This is a subtitle
+
+0
+00:01:23,200 --> 00:02:34,567
+that has two lines.
+
+2
+00:05:00,000 --> 00:06:00,000
+This is another.
+") (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
+ (it "properly splits text when called at the end of the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (subed-jump-to-subtitle-end 1)
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "")))
+ (it "properly splits text when called before whitespace at the end of
the subtitle."
+ (with-temp-srt-buffer
+ (insert text)
+ (subed-jump-to-subtitle-end 1)
+ (save-excursion (insert " "))
+ (subed-split-subtitle 100)
+ (expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
+ (subed-regenerate-ids)
+ (expect (subed-subtitle-text 2) :to-equal "")))))
(describe "when playing the video in MPV"
(it "splits at point in the middle of the subtitle."
(with-temp-srt-buffer
- [nongnu] elpa/subed 6a5802c 374/389: Add video movement per frame, (continued)
- [nongnu] elpa/subed 6a5802c 374/389: Add video movement per frame, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 828764f 375/389: Change keybindings and use a transient keymap, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 5de6f21 377/389: Add msecs-to-timestamp as a common function, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b42f563 378/389: Add audio extensions, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 6b1a6f2 367/389: Add computing and displaying characters per second, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3ba295b 336/389: Fix "service name too long", ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 961e5eb 343/389: More subed-vtt fixes: require subed-vtt, validate better, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 87b3823 353/389: subed-split-subtitle works at the beginning or end of subtitle text, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3b4b56a 384/389: Merge pull request #49 from sachac/fix-vtt-spaces, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed bee9e63 342/389: subed-vtt: Fix syncing point with player, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 016c6a5 363/389: subed-split-subtitle: Handle more cases,
ELPA Syncer <=
- [nongnu] elpa/subed 6164f88 380/389: Keep track of video being played, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 70561f0 381/389: Make hours optional in VTT files, following the spec, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed bf3e832 382/389: Check if subed--cps-overlay exists before trying to update it, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b6e08c2 383/389: Handle spaces in between VTT subtitles, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 564b6fe 386/389: Add preliminary support for comments in VTT files, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed d5751c5 334/389: Change default faces to inherit color values, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 65ed21c 350/389: Add tests/test-subed-vtt.el, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 6eba992 376/389: Add ability to proportionally scale subtitles., ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 7d1aa59 385/389: Make timestamp-to-msecs a generic function, ELPA Syncer, 2021/12/03