Add Save as Copy button to message edit area #154

Closed
opened 2025-12-26 18:09:02 +00:00 by rwachters · 0 comments
rwachters commented 2025-12-26 18:09:02 +00:00 (Migrated from github.com)

Feature Description

Add a "Save as Copy" button to the message edit area (in addition to the existing Save/Cancel buttons). This action will save the edited message as a new message and create a new branch in the conversation tree (including for leaf messages).

Behavior

  • When a user is editing a message and clicks "Save as Copy", the edited content is saved as a new sibling message
  • This creates a new branch in the conversation, with the new message becoming the new leaf
  • Unlike "Save" which updates the existing message, "Save as Copy" preserves the original message and creates a new one

Implementation Plan

1. Add UI Action to ChatAreaActions interface

  • File: app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/chatarea/ChatAreaActions.kt
  • Add onSaveEditingAsCopy() function after the existing onSaveEditing() function

2. Implement SaveEditingAsCopy in EditMessageUseCase

  • File: app/src/commonMain/kotlin/eu/torvian/chatbot/app/viewmodel/chat/usecase/EditMessageUseCase.kt
  • Add suspend fun saveEditingAsCopy() that:
    • Gets the message being edited
    • Gets the message's parent (to determine insertion point)
    • Uses InsertMessageUseCase to create a new message with MessageInsertPosition.APPEND relative to the parent
    • Clears the editing state on success
    • Handles errors with appropriate notifications

3. Wire up in ChatViewModel

  • File: app/src/commonMain/kotlin/eu/torvian/chatbot/app/viewmodel/chat/ChatViewModel.kt
  • Add fun saveEditingAsCopy() that delegates to editMessageUC.saveEditingAsCopy()

4. Wire up in ChatScreen

  • File: app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/ChatScreen.kt
  • Add override fun onSaveEditingAsCopy() = chatViewModel.saveEditingAsCopy() to the chatAreaActions object

5. Add Button to MessageContent Composable

  • File: app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/chatarea/MessageContent.kt
  • Add "Save as Copy" button in MessageEditActions composable between Save and Cancel buttons

6. Update Preview

  • File: app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/preview/ChatAreaPreview.kt
  • Add empty implementation of onSaveEditingAsCopy() to the preview ChatAreaActions object

Notes

  • Uses existing MessageInsertPosition.APPEND to create new branch
  • Reuses existing error handling and notification infrastructure
  • Works for both intermediate and leaf messages in the conversation tree
  • Should follow the same pattern as the existing "Save" button implementation
## Feature Description Add a "Save as Copy" button to the message edit area (in addition to the existing Save/Cancel buttons). This action will save the edited message as a new message and create a new branch in the conversation tree (including for leaf messages). ## Behavior - When a user is editing a message and clicks "Save as Copy", the edited content is saved as a new sibling message - This creates a new branch in the conversation, with the new message becoming the new leaf - Unlike "Save" which updates the existing message, "Save as Copy" preserves the original message and creates a new one ## Implementation Plan ### 1. Add UI Action to ChatAreaActions interface - File: `app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/chatarea/ChatAreaActions.kt` - Add `onSaveEditingAsCopy()` function after the existing `onSaveEditing()` function ### 2. Implement SaveEditingAsCopy in EditMessageUseCase - File: `app/src/commonMain/kotlin/eu/torvian/chatbot/app/viewmodel/chat/usecase/EditMessageUseCase.kt` - Add `suspend fun saveEditingAsCopy()` that: - Gets the message being edited - Gets the message's parent (to determine insertion point) - Uses `InsertMessageUseCase` to create a new message with `MessageInsertPosition.APPEND` relative to the parent - Clears the editing state on success - Handles errors with appropriate notifications ### 3. Wire up in ChatViewModel - File: `app/src/commonMain/kotlin/eu/torvian/chatbot/app/viewmodel/chat/ChatViewModel.kt` - Add `fun saveEditingAsCopy()` that delegates to `editMessageUC.saveEditingAsCopy()` ### 4. Wire up in ChatScreen - File: `app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/ChatScreen.kt` - Add `override fun onSaveEditingAsCopy() = chatViewModel.saveEditingAsCopy()` to the `chatAreaActions` object ### 5. Add Button to MessageContent Composable - File: `app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/chatarea/MessageContent.kt` - Add "Save as Copy" button in `MessageEditActions` composable between Save and Cancel buttons ### 6. Update Preview - File: `app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/preview/ChatAreaPreview.kt` - Add empty implementation of `onSaveEditingAsCopy()` to the preview `ChatAreaActions` object ## Notes - Uses existing `MessageInsertPosition.APPEND` to create new branch - Reuses existing error handling and notification infrastructure - Works for both intermediate and leaf messages in the conversation tree - Should follow the same pattern as the existing "Save" button implementation
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Torvian.eu/chatbot#154
No description provided.