Skip to content

Commit

Permalink
fix export to plain text of multiple nodes with tables and/or codebox…
Browse files Browse the repository at this point in the history
…es (#1880)
  • Loading branch information
giuspen committed Dec 6, 2021
1 parent c70e16c commit 8e9d97e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ct/ct_clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void CtClipboard::_selection_to_clipboard(Glib::RefPtr<Gtk::TextBuffer> text_buf
if (not pCodebox and node_syntax_high == CtConst::RICH_TEXT_ID)
{
std::vector<std::string> targets_vector;
clip_data->plain_text = CtExport2Txt(_pCtMainWin).selection_export_to_txt(text_buffer, iter_sel_start.get_offset(), iter_sel_end.get_offset(), true);
clip_data->plain_text = CtExport2Txt{_pCtMainWin}.selection_export_to_txt(_pCtMainWin->curr_tree_iter(), text_buffer, iter_sel_start.get_offset(), iter_sel_end.get_offset(), true);
clip_data->rich_text = rich_text_get_from_text_buffer_selection(_pCtMainWin->curr_tree_iter(), text_buffer, iter_sel_start, iter_sel_end);
if (not CtClipboard::_static_force_plain_text)
{
Expand Down
8 changes: 4 additions & 4 deletions src/ct/ct_export2txt.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_export2txt.cc
*
* Copyright 2009-2020
* Copyright 2009-2021
* Giuseppe Penone <[email protected]>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -39,7 +39,7 @@ Glib::ustring CtExport2Txt::node_export_to_txt(CtTreeIter tree_iter, fs::path fi
}
plain_text += CtConst::CHAR_SPACE + tree_iter.get_node_name() + CtConst::CHAR_NEWLINE;
}
plain_text += selection_export_to_txt(tree_iter.get_node_text_buffer(), sel_start, sel_end, false);
plain_text += selection_export_to_txt(tree_iter, tree_iter.get_node_text_buffer(), sel_start, sel_end, false);
plain_text += str::repeat(CtConst::CHAR_NEWLINE, 2);
if (filepath != "")
g_file_set_contents(filepath.c_str(), plain_text.c_str(), (gssize)plain_text.bytes(), nullptr);
Expand Down Expand Up @@ -76,10 +76,10 @@ void CtExport2Txt::nodes_all_export_to_txt(bool all_tree, fs::path export_dir, f
}

// Export the Buffer To Txt
Glib::ustring CtExport2Txt::selection_export_to_txt(Glib::RefPtr<Gtk::TextBuffer> text_buffer, int sel_start, int sel_end, bool check_link_target)
Glib::ustring CtExport2Txt::selection_export_to_txt(CtTreeIter tree_iter, Glib::RefPtr<Gtk::TextBuffer> text_buffer, int sel_start, int sel_end, bool check_link_target)
{
Glib::ustring plain_text;
std::list<CtAnchoredWidget*> widgets = _pCtMainWin->curr_tree_iter().get_anchored_widgets(sel_start, sel_end);
std::list<CtAnchoredWidget*> widgets = tree_iter.get_anchored_widgets(sel_start, sel_end);

int start_offset = sel_start >= 0 ? sel_start : 0;
for (CtAnchoredWidget* widget: widgets)
Expand Down
6 changes: 4 additions & 2 deletions src/ct/ct_export2txt.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
* ct_export2txt.h
*
* Copyright 2017-2020 Giuseppe Penone <[email protected]>
* Copyright 2009-2021
* Giuseppe Penone <[email protected]>
* Evgenii Gurianov <https://github.com/txe>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,7 +36,7 @@ class CtExport2Txt
public:
Glib::ustring node_export_to_txt(CtTreeIter tree_iter, fs::path filepath, CtExportOptions export_options, int sel_start, int sel_end);
void nodes_all_export_to_txt(bool all_tree, fs::path export_dir, fs::path single_txt_filepath, CtExportOptions export_options);
Glib::ustring selection_export_to_txt(Glib::RefPtr<Gtk::TextBuffer> text_buffer, int sel_start, int sel_end, bool check_link_target);
Glib::ustring selection_export_to_txt(CtTreeIter tree_iter, Glib::RefPtr<Gtk::TextBuffer> text_buffer, int sel_start, int sel_end, bool check_link_target);

Glib::ustring get_table_plain(CtTable* table_orig);
Glib::ustring get_codebox_plain(CtCodebox* codebox);
Expand Down
9 changes: 9 additions & 0 deletions tests/data_данные/test.export.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ anchored widgets:

codebox:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def test_function:
print "hi there йцукенгшщз"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


anchor:


table:

| h1 | h2 |
| йцукенгшщз | 2 |
| 3 | 4 |


image:

Expand Down
1 change: 1 addition & 0 deletions tests/tests_exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ TEST_P(ExportsMultipleParametersTests, ChecksExports)
std::string expectTxt = Glib::file_get_contents(expectTxt_path);
std::string resultTxt = Glib::file_get_contents(tmpFilepath.string());
ASSERT_FALSE(resultTxt.empty());
//g_file_set_contents(Glib::build_filename(UT::unitTestsDataDir, "test.export.txtt").c_str(), resultTxt.c_str(), -1, NULL);
ASSERT_STREQ(expectTxt.c_str(), resultTxt.c_str());
}
else if (ExportType::Pdf == exportType) {
Expand Down

0 comments on commit 8e9d97e

Please sign in to comment.