Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/MarkdownUI/Document Model/MarkdownBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public enum MarkdownBlock: Identifiable {
public let id: MarkdownBlock.ID
public let index: Int
public let isHeader: Bool
public let cells: [Cell]
public var cells: [Cell]

public init(id: MarkdownBlock.ID, index: Int, isHeader: Bool, cells: [Cell]) {
self.id = id
Expand All @@ -198,7 +198,7 @@ public enum MarkdownBlock: Identifiable {

public let id: MarkdownBlock.ID
public let indentationLevel: Int
public let rows: [Row]
public var rows: [Row]
public let columns: [Column]

public init(id: MarkdownBlock.ID, indentationLevel: Int, rows: [Row], columns: [Column]) {
Expand Down
9 changes: 7 additions & 2 deletions Sources/MarkdownUI/Document Model/MarkdownDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,22 @@ public struct MarkdownDocument {
break
}

if let block = blocksByID[id], case .table(let table) = block {
if let block = blocksByID[id], case .table(var table) = block {
if table.rows.count > rowIndex {
// Row already exists
let row = table.rows[rowIndex]
let newRow = row.insertingCell(cell, at: cell.index)
let newTable = table.replacingRow(at: rowIndex, with: newRow)
blocksByID[id] = .table(newTable)
} else {
} else if table.rows.count == rowIndex {
let row = MarkdownBlock.Table.Row(id: rowID, index: rowIndex, isHeader: isHeaderRow, cells: [cell])
let newTable = table.insertingRow(row, at: rowIndex)
blocksByID[id] = .table(newTable)
} else if table.rows.count < rowIndex {
continue
} else {
table.rows[rowIndex].cells.append(cell)
blocksByID[id] = .table(table )
}
} else {
blockOrder.append(id)
Expand Down