message: Clean and refactor (mac)
diff: @@ -235,21 +235,42 @@ extension TimelineData {
  }
  // Add empty time entry
  - // Only add if there is a gap between two entries
  - let sortedFirstRowEntries = firstRowTEs.sorted { (first, second) -> Bool in
  + if let gapEntries = calculateGapEntry(from: firstRowTEs), !gapEntries.isEmpty {
  + timeEntries.append(contentsOf: gapEntries)
  + }
  + }
  +
  + private func getAllConflictedTimeEntries(at entry: TimelineTimeEntry) -> [TimelineTimeEntry] {
  + // Get all conflicted entry in same group
  + return timeEntries
  + .filter { $0 is TimelineTimeEntry && $0.group == entry.group }
  + .sorted { (lhs, rhs) -> Bool in
  + return lhs.col <= rhs.col
  + }
  + .compactMap { (entry) -> TimelineTimeEntry? in
  + return entry as? TimelineTimeEntry
  + }
  + }
  +
  + private func calculateGapEntry(from firstRowEntries: [TimelineBaseTimeEntry]) -> [TimelineBaseTimeEntry]? {
  + guard firstRowEntries.count > 1 else { return nil }
  +
  + // Sort ASC to make sure it's correct order
  + let sortedEntry = firstRowEntries.sorted { (first, second) -> Bool in
  return first.start < second.start
  }
  - if sortedFirstRowEntries.count >= 2 {
  + // Calculate the gap
  var gapEntries: [TimelineBaseTimeEntry] = []
  - for (i, item) in sortedFirstRowEntries.enumerated() {
  + for (i, item) in sortedEntry.enumerated() {
  +
  // Stop if the index is end
  - if i == (sortedFirstRowEntries.count - 1) {
  + if i == (sortedEntry.count - 1) {
  break
  }
  // Get the next TE
  - let next = sortedFirstRowEntries[i+1]
  + let next = sortedEntry[i+1]
  // Make sure the gap is bigger the minimum
  let distance = next.start - item.end
  @@ -260,21 +281,6 @@ extension TimelineData {
  gapEntries.append(gapEntry)
  }
  }
  -
  - // Add
  - timeEntries.append(contentsOf: gapEntries)
  - }
  - }
  -
  - fileprivate func getAllConflictedTimeEntries(at entry: TimelineTimeEntry) -> [TimelineTimeEntry] {
  - // Get all conflicted entry in same group
  - return timeEntries
  - .filter { $0 is TimelineTimeEntry && $0.group == entry.group }
  - .sorted { (lhs, rhs) -> Bool in
  - return lhs.col <= rhs.col
  - }
  - .compactMap { (entry) -> TimelineTimeEntry? in
  - return entry as? TimelineTimeEntry
  - }
  + return gapEntries
  }
  }
  