@@ -432,8 +432,10 @@ final class InspectorViewController: NSViewController, NSUserInterfaceValidation
432432 alert. accessoryView = accessoryStack ( with: [ field] )
433433
434434 alert. beginSheetModal ( for: window) { [ weak self] response in
435- guard response == . alertFirstButtonReturn else { return }
436- self ? . inspectorDocument? . mergeColumns ( at: column, separator: field. stringValue)
435+ guard response == . alertFirstButtonReturn, let self, let inspector = self . inspectorDocument else { return }
436+ let removedName = column + 1 < inspector. columnNames. count ? inspector. columnNames [ column + 1 ] : nil
437+ inspector. mergeColumns ( at: column, separator: field. stringValue)
438+ if let removedName { self . removeLayoutKey ( removedName) }
437439 }
438440 DispatchQueue . main. async { alert. window. makeFirstResponder ( field) }
439441 }
@@ -444,7 +446,15 @@ final class InspectorViewController: NSViewController, NSUserInterfaceValidation
444446 presentInvalidPattern ( )
445447 return
446448 }
447- inspectorDocument? . splitColumn ( at: column, separator: separator, isRegex: isRegex)
449+ guard let inspector = inspectorDocument else { return }
450+ let oldName = column < inspector. columnNames. count ? inspector. columnNames [ column] : nil
451+ let oldCount = inspector. columnNames. count
452+ inspector. splitColumn ( at: column, separator: separator, isRegex: isRegex)
453+ guard let oldName else { return }
454+ let pieceCount = inspector. columnNames. count - oldCount + 1
455+ let upper = min ( column + max( pieceCount, 0 ) , inspector. columnNames. count)
456+ let newNames = column < upper ? Array ( inspector. columnNames [ column..< upper] ) : [ ]
457+ replaceLayoutKey ( oldName, with: newNames)
448458 }
449459
450460 private func presentInvalidPattern( ) {
@@ -521,6 +531,15 @@ final class InspectorViewController: NSViewController, NSUserInterfaceValidation
521531 state. columnLayout. columnOrder = order
522532 }
523533
534+ private func replaceLayoutKey( _ oldName: String , with newNames: [ String ] ) {
535+ if var order = state. columnLayout. columnOrder, let position = order. firstIndex ( of: oldName) {
536+ order. replaceSubrange ( position... position, with: newNames)
537+ state. columnLayout. columnOrder = order
538+ }
539+ state. columnLayout. columnWidths. removeValue ( forKey: oldName)
540+ state. columnLayout. hiddenColumns. remove ( oldName)
541+ }
542+
524543 private func promptForColumnName(
525544 title: String ,
526545 initial: String ,
0 commit comments