pub(crate) fn store_comments(&mut self, comments: &[Comment]) {
        for child in &mut self.document.children {
            match child {
                DocumentChild::Paragraph(paragraph) => {
                    for child in &mut paragraph.children {
                        if let ParagraphChild::CommentStart(ref mut c) = child {
                            let comment_id = c.get_id();
                            if let Some(comment) = comments.iter().find(|c| c.id() == comment_id) {
                                let comment = comment.clone();
                                c.as_mut().comment(comment);
                            }
                        }
                        if let ParagraphChild::Insert(ref mut insert) = child {
                            for child in &mut insert.children {
                                if let InsertChild::CommentStart(ref mut c) = child {
                                    let comment_id = c.get_id();
                                    if let Some(comment) =
                                        comments.iter().find(|c| c.id() == comment_id)
                                    {
                                        let comment = comment.clone();
                                        c.as_mut().comment(comment);
                                    }
                                }
                            }
                        }
                        if let ParagraphChild::Delete(ref mut delete) = child {
                            for child in &mut delete.children {
                                if let DeleteChild::CommentStart(ref mut c) = child {
                                    let comment_id = c.get_id();
                                    if let Some(comment) =
                                        comments.iter().find(|c| c.id() == comment_id)
                                    {
                                        let comment = comment.clone();
                                        c.as_mut().comment(comment);
                                    }
                                }
                            }
                        }
                    }
                }
                DocumentChild::Table(table) => {
                    for TableChild::TableRow(row) in &mut table.rows {
                        for TableRowChild::TableCell(cell) in &mut row.cells {
                            for content in &mut cell.children {
                                match content {
                                    TableCellContent::Paragraph(paragraph) => {
                                        for child in &mut paragraph.children {
                                            if let ParagraphChild::CommentStart(ref mut c) = child {
                                                let comment_id = c.get_id();
                                                if let Some(comment) =
                                                    comments.iter().find(|c| c.id() == comment_id)
                                                {
                                                    let comment = comment.clone();
                                                    c.as_mut().comment(comment);
                                                }
                                            }
                                            if let ParagraphChild::Insert(ref mut insert) = child {
                                                for child in &mut insert.children {
                                                    if let InsertChild::CommentStart(ref mut c) =
                                                        child
                                                    {
                                                        let comment_id = c.get_id();
                                                        if let Some(comment) = comments
                                                            .iter()
                                                            .find(|c| c.id() == comment_id)
                                                        {
                                                            let comment = comment.clone();
                                                            c.as_mut().comment(comment);
                                                        }
                                                    }
                                                }
                                            }
                                            if let ParagraphChild::Delete(ref mut delete) = child {
                                                for child in &mut delete.children {
                                                    if let DeleteChild::CommentStart(ref mut c) =
                                                        child
                                                    {
                                                        let comment_id = c.get_id();
                                                        if let Some(comment) = comments
                                                            .iter()
                                                            .find(|c| c.id() == comment_id)
                                                        {
                                                            let comment = comment.clone();
                                                            c.as_mut().comment(comment);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    TableCellContent::Table(_) => {
                                        // TODO: support comment
                                    }
                                }
                            }
                        }
                    }
                }
                _ => {}
            }
        }

        if !comments.is_empty() {
            self.document_rels.has_comments = true;
        }
    }
// Traverse and clone comments from document and add to comments node.
Traverse and clone comments from document and add to comments node.
Traverse and clone comments from document and add to comments node .
pub(crate) fn store_comments(&mut self, comments: &[Comment]) {
        for child in &mut self.document.children {
            match child {
                DocumentChild::Paragraph(paragraph) => {
                    for child in &mut paragraph.children {
                        if let ParagraphChild::CommentStart(ref mut c) = child {
                            let comment_id = c.get_id();
                            if let Some(comment) = comments.iter().find(|c| c.id() == comment_id) {
                                let comment = comment.clone();
                                c.as_mut().comment(comment);
                            }
                        }
                        if let ParagraphChild::Insert(ref mut insert) = child {
                            for child in &mut insert.children {
                                if let InsertChild::CommentStart(ref mut c) = child {
                                    let comment_id = c.get_id();
                                    if let Some(comment) =
                                        comments.iter().find(|c| c.id() == comment_id)
                                    {
                                        let comment = comment.clone();
                                        c.as_mut().comment(comment);
                                    }
                                }
                            }
                        }
                        if let ParagraphChild::Delete(ref mut delete) = child {
                            for child in &mut delete.children {
                                if let DeleteChild::CommentStart(ref mut c) = child {
                                    let comment_id = c.get_id();
                                    if let Some(comment) =
                                        comments.iter().find(|c| c.id() == comment_id)
                                    {
                                        let comment = comment.clone();
                                        c.as_mut().comment(comment);
                                    }
                                }
                            }
                        }
                    }
                }
                DocumentChild::Table(table) => {
                    for TableChild::TableRow(row) in &mut table.rows {
                        for TableRowChild::TableCell(cell) in &mut row.cells {
                            for content in &mut cell.children {
                                match content {
                                    TableCellContent::Paragraph(paragraph) => {
                                        for child in &mut paragraph.children {
                                            if let ParagraphChild::CommentStart(ref mut c) = child {
                                                let comment_id = c.get_id();
                                                if let Some(comment) =
                                                    comments.iter().find(|c| c.id() == comment_id)
                                                {
                                                    let comment = comment.clone();
                                                    c.as_mut().comment(comment);
                                                }
                                            }
                                            if let ParagraphChild::Insert(ref mut insert) = child {
                                                for child in &mut insert.children {
                                                    if let InsertChild::CommentStart(ref mut c) =
                                                        child
                                                    {
                                                        let comment_id = c.get_id();
                                                        if let Some(comment) = comments
                                                            .iter()
                                                            .find(|c| c.id() == comment_id)
                                                        {
                                                            let comment = comment.clone();
                                                            c.as_mut().comment(comment);
                                                        }
                                                    }
                                                }
                                            }
                                            if let ParagraphChild::Delete(ref mut delete) = child {
                                                for child in &mut delete.children {
                                                    if let DeleteChild::CommentStart(ref mut c) =
                                                        child
                                                    {
                                                        let comment_id = c.get_id();
                                                        if let Some(comment) = comments
                                                            .iter()
                                                            .find(|c| c.id() == comment_id)
                                                        {
                                                            let comment = comment.clone();
                                                            c.as_mut().comment(comment);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    TableCellContent::Table(_) => {
                                        // TODO: support comment
                                    }
                                }
                            }
                        }
                    }
                }
                _ => {}
            }
        }
        if !comments.is_empty() {
            self.document_rels.has_comments = true;
        }
    }
pub ( crate ) fn store_comments ( & mut self , comments : & [ Comment ] ) { for child in & mut self . document . children { match child { DocumentChild :: Paragraph ( paragraph ) => { for child in & mut paragraph . children { if let ParagraphChild :: CommentStart ( ref mut c ) = child { let comment_id = c . get_id ( ) ; if let Some ( comment ) = comments . iter ( ) . find ( | c | c . id ( ) == comment_id ) { let comment = comment . clone ( ) ; c . as_mut ( ) . comment ( comment ) ; } } if let ParagraphChild :: Insert ( ref mut insert ) = child { for child in & mut insert . children { if let InsertChild :: CommentStart ( ref mut c ) = child { let comment_id = c . get_id ( ) ; if let Some ( comment ) = comments . iter ( ) . find ( | c | c . id ( ) == comment_id ) { let comment = comment . clone ( ) ; c . as_mut ( ) . comment ( comment ) ; } } } } if let ParagraphChild :: Delete ( ref mut delete ) = child { for child in & mut delete . children { if let DeleteChild :: CommentStart ( ref mut c ) = child { let comment_id = c . get_id ( ) ; if let Some ( comment ) = comments . iter ( ) . find ( | c | c . id ( ) == comment_id ) { let comment = comment . clone ( ) ; c . as_mut ( ) . comment ( comment ) ; } } } } } } DocumentChild :: Table ( table ) => { for TableChild :: TableRow ( row ) in & mut table . rows { for TableRowChild :: TableCell ( cell ) in & mut row . cells { for content in & mut cell . children { match content { TableCellContent :: Paragraph ( paragraph ) => { for child in & mut paragraph . children { if let ParagraphChild :: CommentStart ( ref mut c ) = child { let comment_id = c . get_id ( ) ; if let Some ( comment ) = comments . iter ( ) . find ( | c | c . id ( ) == comment_id ) { let comment = comment . clone ( ) ; c . as_mut ( ) . comment ( comment ) ; } } if let ParagraphChild :: Insert ( ref mut insert ) = child { for child in & mut insert . children { if let InsertChild :: CommentStart ( ref mut c ) = child { let comment_id = c . get_id ( ) ; if let Some ( comment ) = comments . iter ( ) . find ( | c | c . id ( ) == comment_id ) { let comment = comment . clone ( ) ; c . as_mut ( ) . comment ( comment ) ; } } } } if let ParagraphChild :: Delete ( ref mut delete ) = child { for child in & mut delete . children { if let DeleteChild :: CommentStart ( ref mut c ) = child { let comment_id = c . get_id ( ) ; if let Some ( comment ) = comments . iter ( ) . find ( | c | c . id ( ) == comment_id ) { let comment = comment . clone ( ) ; c . as_mut ( ) . comment ( comment ) ; } } } } } } TableCellContent :: Table ( _ ) => { // TODO: support comment } } } } } } _ => { } } } if ! comments . is_empty ( ) { self . document_rels . has_comments = true ; } }
Traverse and clone comments from document and add to comments node.
Traverse and clone comments from document and add to comments node .
&mut self
comments
&[Comment]