@@ -39,26 +39,20 @@ final class RowOperationsManager {
3939 func addNewRow(
4040 columns: [ String ] ,
4141 columnDefaults: [ String : String ? ] ,
42- resultRows: inout [ QueryResultRow ]
42+ resultRows: inout [ [ String ? ] ]
4343 ) -> ( rowIndex: Int , values: [ String ? ] ) ? {
44- // Create new row values with DEFAULT markers
4544 var newRowValues : [ String ? ] = [ ]
4645 for column in columns {
4746 if let defaultValue = columnDefaults [ column] , defaultValue != nil {
48- // Use __DEFAULT__ marker so generateInsertSQL skips this column
4947 newRowValues. append ( " __DEFAULT__ " )
5048 } else {
51- // NULL for columns without defaults
5249 newRowValues. append ( nil )
5350 }
5451 }
5552
56- // Add to resultRows
5753 let newRowIndex = resultRows. count
58- let newRow = QueryResultRow ( id: newRowIndex, values: newRowValues)
59- resultRows. append ( newRow)
54+ resultRows. append ( newRowValues)
6055
61- // Record in change manager as pending INSERT
6256 changeManager. recordRowInsertion ( rowIndex: newRowIndex, values: newRowValues)
6357
6458 return ( newRowIndex, newRowValues)
@@ -75,26 +69,20 @@ final class RowOperationsManager {
7569 func duplicateRow(
7670 sourceRowIndex: Int ,
7771 columns: [ String ] ,
78- resultRows: inout [ QueryResultRow ]
72+ resultRows: inout [ [ String ? ] ]
7973 ) -> ( rowIndex: Int , values: [ String ? ] ) ? {
8074 guard sourceRowIndex < resultRows. count else { return nil }
8175
82- // Copy values from selected row
83- let sourceRow = resultRows [ sourceRowIndex]
84- var newValues = sourceRow. values
76+ var newValues = resultRows [ sourceRowIndex]
8577
86- // Set primary key column to DEFAULT so DB auto-generates
8778 if let pkColumn = changeManager. primaryKeyColumn,
8879 let pkIndex = columns. firstIndex ( of: pkColumn) {
8980 newValues [ pkIndex] = " __DEFAULT__ "
9081 }
9182
92- // Add the duplicated row
9383 let newRowIndex = resultRows. count
94- let newRow = QueryResultRow ( id: newRowIndex, values: newValues)
95- resultRows. append ( newRow)
84+ resultRows. append ( newValues)
9685
97- // Record in change manager as pending INSERT
9886 changeManager. recordRowInsertion ( rowIndex: newRowIndex, values: newValues)
9987
10088 return ( newRowIndex, newValues)
@@ -109,26 +97,22 @@ final class RowOperationsManager {
10997 /// - Returns: Next row index to select after deletion, or -1 if no rows left
11098 func deleteSelectedRows(
11199 selectedIndices: Set < Int > ,
112- resultRows: inout [ QueryResultRow ]
100+ resultRows: inout [ [ String ? ] ]
113101 ) -> Int {
114102 guard !selectedIndices. isEmpty else { return - 1 }
115103
116- // Separate inserted rows from existing rows
117104 var insertedRowsToDelete : [ Int ] = [ ]
118105 var existingRowsToDelete : [ ( rowIndex: Int , originalRow: [ String ? ] ) ] = [ ]
119106
120- // Find the lowest selected row index for selection movement
121107 let minSelectedRow = selectedIndices. min ( ) ?? 0
122108 let maxSelectedRow = selectedIndices. max ( ) ?? 0
123109
124- // Categorize rows (process in descending order to maintain correct indices)
125110 for rowIndex in selectedIndices. sorted ( by: > ) {
126111 if changeManager. isRowInserted ( rowIndex) {
127112 insertedRowsToDelete. append ( rowIndex)
128113 } else if !changeManager. isRowDeleted ( rowIndex) {
129114 if rowIndex < resultRows. count {
130- let originalRow = resultRows [ rowIndex] . values
131- existingRowsToDelete. append ( ( rowIndex: rowIndex, originalRow: originalRow) )
115+ existingRowsToDelete. append ( ( rowIndex: rowIndex, originalRow: resultRows [ rowIndex] ) )
132116 }
133117 }
134118 }
@@ -174,15 +158,15 @@ final class RowOperationsManager {
174158 /// Undo the last change
175159 /// - Parameter resultRows: Current rows (will be mutated)
176160 /// - Returns: Updated selection indices
177- func undoLastChange( resultRows: inout [ QueryResultRow ] ) -> Set < Int > ? {
161+ func undoLastChange( resultRows: inout [ [ String ? ] ] ) -> Set < Int > ? {
178162 guard let result = changeManager. undoLastChange ( ) else { return nil }
179163
180164 var adjustedSelection : Set < Int > ?
181165
182166 switch result. action {
183167 case . cellEdit( let rowIndex, let columnIndex, _, let previousValue, _) :
184168 if rowIndex < resultRows. count {
185- resultRows [ rowIndex] . values [ columnIndex] = previousValue
169+ resultRows [ rowIndex] [ columnIndex] = previousValue
186170 }
187171
188172 case . rowInsertion( let rowIndex) :
@@ -192,22 +176,16 @@ final class RowOperationsManager {
192176 }
193177
194178 case . rowDeletion:
195- // Row is restored in changeManager - visual indicator will be removed
196179 break
197180
198181 case . batchRowDeletion:
199- // All rows are restored in changeManager
200182 break
201183
202184 case . batchRowInsertion( let rowIndices, let rowValues) :
203- // Restore deleted inserted rows - add them back to resultRows
204185 for (index, rowIndex) in rowIndices. enumerated ( ) . reversed ( ) {
205186 guard index < rowValues. count else { continue }
206187 guard rowIndex <= resultRows. count else { continue }
207-
208- let values = rowValues [ index]
209- let newRow = QueryResultRow ( id: rowIndex, values: values)
210- resultRows. insert ( newRow, at: rowIndex)
188+ resultRows. insert ( rowValues [ index] , at: rowIndex)
211189 }
212190 }
213191
@@ -219,32 +197,28 @@ final class RowOperationsManager {
219197 /// - resultRows: Current rows (will be mutated)
220198 /// - columns: Column names for new row creation
221199 /// - Returns: Updated selection indices
222- func redoLastChange( resultRows: inout [ QueryResultRow ] , columns: [ String ] ) -> Set < Int > ? {
200+ func redoLastChange( resultRows: inout [ [ String ? ] ] , columns: [ String ] ) -> Set < Int > ? {
223201 guard let result = changeManager. redoLastChange ( ) else { return nil }
224202
225203 switch result. action {
226204 case . cellEdit( let rowIndex, let columnIndex, _, _, let newValue) :
227205 if rowIndex < resultRows. count {
228- resultRows [ rowIndex] . values [ columnIndex] = newValue
206+ resultRows [ rowIndex] [ columnIndex] = newValue
229207 }
230208
231209 case . rowInsertion( let rowIndex) :
232210 let newValues = [ String? ] ( repeating: nil , count: columns. count)
233- let newRow = QueryResultRow ( id: rowIndex, values: newValues)
234211 if rowIndex <= resultRows. count {
235- resultRows. insert ( newRow , at: rowIndex)
212+ resultRows. insert ( newValues , at: rowIndex)
236213 }
237214
238215 case . rowDeletion:
239- // Row is re-marked as deleted in changeManager
240216 break
241217
242218 case . batchRowDeletion:
243- // Rows are re-marked as deleted
244219 break
245220
246221 case . batchRowInsertion( let rowIndices, _) :
247- // Redo the deletion - remove the rows from resultRows again
248222 for rowIndex in rowIndices. sorted ( by: > ) {
249223 guard rowIndex < resultRows. count else { continue }
250224 resultRows. remove ( at: rowIndex)
@@ -264,7 +238,7 @@ final class RowOperationsManager {
264238 /// - Returns: Adjusted selection indices
265239 func undoInsertRow(
266240 at rowIndex: Int ,
267- resultRows: inout [ QueryResultRow ] ,
241+ resultRows: inout [ [ String ? ] ] ,
268242 selectedIndices: Set < Int >
269243 ) -> Set < Int > {
270244 guard rowIndex >= 0 && rowIndex < resultRows. count else { return selectedIndices }
@@ -297,7 +271,7 @@ final class RowOperationsManager {
297271 /// - includeHeaders: Whether to prepend column headers as the first TSV line
298272 func copySelectedRowsToClipboard(
299273 selectedIndices: Set < Int > ,
300- resultRows: [ QueryResultRow ] ,
274+ resultRows: [ [ String ? ] ] ,
301275 columns: [ String ] = [ ] ,
302276 includeHeaders: Bool = false
303277 ) {
@@ -315,7 +289,7 @@ final class RowOperationsManager {
315289
316290 let indicesToCopy = isTruncated ? Array ( sortedIndices. prefix ( Self . maxClipboardRows) ) : sortedIndices
317291
318- let columnCount = resultRows. first? . values . count ?? 1
292+ let columnCount = resultRows. first? . count ?? 1
319293 let estimatedRowLength = columnCount * 12
320294 var result = " "
321295 result. reserveCapacity ( indicesToCopy. count * estimatedRowLength)
@@ -329,9 +303,8 @@ final class RowOperationsManager {
329303
330304 for rowIndex in indicesToCopy {
331305 guard rowIndex < resultRows. count else { continue }
332- let row = resultRows [ rowIndex]
333306 if !result. isEmpty { result. append ( " \n " ) }
334- for (colIdx, value) in row . values . enumerated ( ) {
307+ for (colIdx, value) in resultRows [ rowIndex ] . enumerated ( ) {
335308 if colIdx > 0 { result. append ( " \t " ) }
336309 result. append ( value ?? " NULL " )
337310 }
@@ -358,7 +331,7 @@ final class RowOperationsManager {
358331 func pasteRowsFromClipboard(
359332 columns: [ String ] ,
360333 primaryKeyColumn: String ? ,
361- resultRows: inout [ QueryResultRow ] ,
334+ resultRows: inout [ [ String ? ] ] ,
362335 clipboard: ClipboardProvider ? = nil ,
363336 parser: RowDataParser ? = nil
364337 ) -> [ ( rowIndex: Int , values: [ String ? ] ) ] {
@@ -448,18 +421,16 @@ final class RowOperationsManager {
448421 /// - Returns: Array of (rowIndex, values) for inserted rows
449422 private func insertParsedRows(
450423 _ parsedRows: [ ParsedRow ] ,
451- into resultRows: inout [ QueryResultRow ]
424+ into resultRows: inout [ [ String ? ] ]
452425 ) -> [ ( rowIndex: Int , values: [ String ? ] ) ] {
453426 var pastedRowInfo : [ ( Int , [ String ? ] ) ] = [ ]
454427
455428 for parsedRow in parsedRows {
456429 let rowValues = parsedRow. values
457430
458- // Add to resultRows
459- resultRows. append ( QueryResultRow ( id: resultRows. count, values: rowValues) )
431+ resultRows. append ( rowValues)
460432 let newRowIndex = resultRows. count - 1
461433
462- // Record as pending INSERT in change manager
463434 changeManager. recordRowInsertion ( rowIndex: newRowIndex, values: rowValues)
464435
465436 pastedRowInfo. append ( ( newRowIndex, rowValues) )
0 commit comments