@@ -112,6 +112,13 @@ std::unique_ptr<AssDialogue> get_dialogue(String data) {
112112 }
113113}
114114
115+ enum class JoinDialogueFormat {
116+ DashSecondLineWithSpace,
117+ DashSecondLineWithoutSpace,
118+ DashBothLinesWithSpace,
119+ DashBothLinesWithoutSpace
120+ };
121+
115122template <typename Paster>
116123void paste_lines (agi::Context *c, bool paste_over, Paster&& paste_line) {
117124 std::string data = GetClipboard ();
@@ -781,8 +788,55 @@ static void combine_concat(AssDialogue *first, AssDialogue *second) {
781788 first->Text = agi::Str (first->Text .get (), " " , second->Text .get ());
782789}
783790
791+ static void combine_dialogue (AssDialogue *first, AssDialogue *second) {
792+ if (second) {
793+ auto format_option = OPT_GET (" Subtitle/Grid/Join as Dialogue Format" );
794+ JoinDialogueFormat format = JoinDialogueFormat::DashSecondLineWithSpace;
795+
796+ if (format_option) {
797+ format = static_cast <JoinDialogueFormat>(format_option->GetInt ());
798+ }
799+
800+ std::string first_text = first->Text .get ();
801+ std::string second_text = second ? second->Text .get () : " " ;
802+ std::string newline = OPT_GET (" Subtitle/Edit Box/Soft Line Break" )->GetBool () ? " \\ n" : " \\ N" ;
803+
804+ // Remove newlines from the lines to be merged
805+ boost::replace_all (first_text, newline, " " );
806+ boost::replace_all (second_text, newline, " " );
807+
808+ std::string combined_text = " " ;
809+ switch (format) {
810+ case JoinDialogueFormat::DashSecondLineWithSpace:
811+ combined_text = first_text + newline + " - " + second_text;
812+ break ;
813+ case JoinDialogueFormat::DashSecondLineWithoutSpace:
814+ combined_text = first_text + newline + " -" + second_text;
815+ break ;
816+ case JoinDialogueFormat::DashBothLinesWithSpace:
817+ combined_text = " - " + first_text + newline + " - " + second_text;
818+ break ;
819+ case JoinDialogueFormat::DashBothLinesWithoutSpace:
820+ combined_text = " -" + first_text + newline + " -" + second_text;
821+ break ;
822+ }
823+ first->Text = combined_text;
824+ }
825+ }
826+
784827static void combine_drop (AssDialogue *, AssDialogue *) { }
785828
829+ struct edit_line_join_dialogue final : public validate_sel_multiple {
830+ CMD_NAME (" edit/line/join/dialogue" )
831+ STR_MENU (" Join &Dialogue" )
832+ STR_DISP (" Join Dialogue" )
833+ STR_HELP (" Join selected lines in a single one, concatenating dialogue together" )
834+
835+ void operator ()(agi::Context *c) override {
836+ combine_lines (c, combine_dialogue, _ (" join dialogue" ));
837+ }
838+ };
839+
786840struct edit_line_join_as_karaoke final : public validate_sel_multiple {
787841 CMD_NAME (" edit/line/join/as_karaoke" )
788842 STR_MENU (" As &Karaoke" )
@@ -1283,6 +1337,7 @@ namespace cmd {
12831337 reg (std::make_unique<edit_line_duplicate_shift>());
12841338 reg (std::make_unique<edit_line_duplicate_shift_back>());
12851339 reg (std::make_unique<edit_line_join_as_karaoke>());
1340+ reg (std::make_unique<edit_line_join_dialogue>());
12861341 reg (std::make_unique<edit_line_join_concatenate>());
12871342 reg (std::make_unique<edit_line_join_keep_first>());
12881343 reg (std::make_unique<edit_line_paste>());
0 commit comments