refactor(copy): keep document ownership in mode
- commit
- 661ba078d75b63dfe64f0ceb19a276028c888131
- author
- brice · · 2026-07-15 07:21 UTC
- committer
- brice · · 2026-07-15 09:45 UTC
- parent
- e769ef3
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +7 -7
M internal/usecase/daemon/overlay_runtime.go +0 -2
| @@ -158,7 +158,6 @@ type overlayRenderSnapshot struct { | |||
| 158 | 158 | ||
| 159 | 159 | copyActive bool | |
| 160 | 160 | copyMode *scopy.Mode | |
| 161 | - | copyDocument *scopy.Document | |
| 162 | 161 | copyPane *pane | |
| 163 | 162 | copySearchModel *visualsearch.Model | |
| 164 | 163 | copyFeedback string | |
| @@ -195,7 +194,6 @@ func (rt *overlayRuntime) SnapshotForRender() *overlayRenderSnapshot { | |||
| 195 | 194 | rt.copyMu.Lock() | |
| 196 | 195 | snap.copyActive = rt.copyMode != nil | |
| 197 | 196 | snap.copyPane = rt.copyPane | |
| 198 | - | snap.copyDocument = rt.copyDocument | |
| 199 | 197 | if rt.copyMode != nil { | |
| 200 | 198 | copyModeValue := *rt.copyMode | |
| 201 | 199 | copyModeValue.Searches = append([]scopy.SearchMatch(nil), rt.copyMode.Searches...) | |
| @@ -158,7 +158,6 @@ type overlayRenderSnapshot struct { | |||||
| 158 | 158 | ||||
| 159 | copyActive bool | 159 | copyActive bool | ||
| 160 | copyMode *scopy.Mode | 160 | copyMode *scopy.Mode | ||
| 161 | - | copyDocument *scopy.Document | |||
| 162 | copyPane *pane | 161 | copyPane *pane | ||
| 163 | copySearchModel *visualsearch.Model | 162 | copySearchModel *visualsearch.Model | ||
| 164 | copyFeedback string | 163 | copyFeedback string | ||
| @@ -195,7 +194,6 @@ func (rt *overlayRuntime) SnapshotForRender() *overlayRenderSnapshot { | |||||
| 195 | rt.copyMu.Lock() | 194 | rt.copyMu.Lock() | ||
| 196 | snap.copyActive = rt.copyMode != nil | 195 | snap.copyActive = rt.copyMode != nil | ||
| 197 | snap.copyPane = rt.copyPane | 196 | snap.copyPane = rt.copyPane | ||
| 198 | - | snap.copyDocument = rt.copyDocument | |||
| 199 | if rt.copyMode != nil { | 197 | if rt.copyMode != nil { | ||
| 200 | copyModeValue := *rt.copyMode | 198 | copyModeValue := *rt.copyMode | ||
| 201 | copyModeValue.Searches = append([]scopy.SearchMatch(nil), rt.copyMode.Searches...) | 199 | copyModeValue.Searches = append([]scopy.SearchMatch(nil), rt.copyMode.Searches...) | ||
M internal/usecase/daemon/overlay_runtime_test.go +7 -5
| @@ -145,7 +145,7 @@ func TestOverlayRuntimeHandleInputInactive(t *testing.T) { | |||
| 145 | 145 | require.False(t, ac.overlays.HandleInput(&Daemon{}, []byte("x"))) | |
| 146 | 146 | } | |
| 147 | 147 | ||
| 148 | - | func TestOverlayRuntimeSnapshotCarriesCopyDocumentAndClearReleasesIt(t *testing.T) { | |
| 148 | + | func TestOverlayRuntimeSnapshotCarriesCopyModeDocumentAndClearReleasesIt(t *testing.T) { | |
| 149 | 149 | ac := &attachedClient{} | |
| 150 | 150 | ac.initOverlays() | |
| 151 | 151 | p := newPane("floating", nil, domain.Size{Cols: 4, Rows: 2}) | |
| @@ -159,7 +159,8 @@ func TestOverlayRuntimeSnapshotCarriesCopyDocumentAndClearReleasesIt(t *testing. | |||
| 159 | 159 | ||
| 160 | 160 | renderSnap := ac.overlays.SnapshotForRender() | |
| 161 | 161 | require.Same(t, p, renderSnap.copyPane) | |
| 162 | - | require.Same(t, document, renderSnap.copyDocument) | |
| 162 | + | require.NotNil(t, renderSnap.copyMode) | |
| 163 | + | require.Same(t, document, renderSnap.copyMode.Document()) | |
| 163 | 164 | renderSnap.Unlock() | |
| 164 | 165 | ||
| 165 | 166 | ac.overlays.copyMu.Lock() | |
| @@ -170,7 +171,7 @@ func TestOverlayRuntimeSnapshotCarriesCopyDocumentAndClearReleasesIt(t *testing. | |||
| 170 | 171 | ac.overlays.copyMu.Unlock() | |
| 171 | 172 | } | |
| 172 | 173 | ||
| 173 | - | func TestOverlayRuntimeCopyDocumentSurvivesRingOverwrite(t *testing.T) { | |
| 174 | + | func TestOverlayRuntimeCopyModeDocumentSurvivesRingOverwrite(t *testing.T) { | |
| 174 | 175 | ac := &attachedClient{} | |
| 175 | 176 | ac.initOverlays() | |
| 176 | 177 | history := newTestHistory(1) | |
| @@ -185,6 +186,7 @@ func TestOverlayRuntimeCopyDocumentSurvivesRingOverwrite(t *testing.T) { | |||
| 185 | 186 | history.Append(testRow("after")) | |
| 186 | 187 | renderSnap := ac.overlays.SnapshotForRender() | |
| 187 | 188 | defer renderSnap.Unlock() | |
| 188 | - | require.Same(t, document, renderSnap.copyDocument) | |
| 189 | - | require.Equal(t, "before", rowText(renderSnap.copyDocument.Snapshot().Row(0))) | |
| 189 | + | require.NotNil(t, renderSnap.copyMode) | |
| 190 | + | require.Same(t, document, renderSnap.copyMode.Document()) | |
| 191 | + | require.Equal(t, "before", rowText(renderSnap.copyMode.Document().Snapshot().Row(0))) | |
| 190 | 192 | } | |
| @@ -145,7 +145,7 @@ func TestOverlayRuntimeHandleInputInactive(t *testing.T) { | |||||
| 145 | require.False(t, ac.overlays.HandleInput(&Daemon{}, []byte("x"))) | 145 | require.False(t, ac.overlays.HandleInput(&Daemon{}, []byte("x"))) | ||
| 146 | } | 146 | } | ||
| 147 | 147 | ||||
| 148 | - | func TestOverlayRuntimeSnapshotCarriesCopyDocumentAndClearReleasesIt(t *testing.T) { | 148 | + | func TestOverlayRuntimeSnapshotCarriesCopyModeDocumentAndClearReleasesIt(t *testing.T) { |
| 149 | ac := &attachedClient{} | 149 | ac := &attachedClient{} | ||
| 150 | ac.initOverlays() | 150 | ac.initOverlays() | ||
| 151 | p := newPane("floating", nil, domain.Size{Cols: 4, Rows: 2}) | 151 | p := newPane("floating", nil, domain.Size{Cols: 4, Rows: 2}) | ||
| @@ -159,7 +159,8 @@ func TestOverlayRuntimeSnapshotCarriesCopyDocumentAndClearReleasesIt(t *testing. | |||||
| 159 | 159 | ||||
| 160 | renderSnap := ac.overlays.SnapshotForRender() | 160 | renderSnap := ac.overlays.SnapshotForRender() | ||
| 161 | require.Same(t, p, renderSnap.copyPane) | 161 | require.Same(t, p, renderSnap.copyPane) | ||
| 162 | - | require.Same(t, document, renderSnap.copyDocument) | 162 | + | require.NotNil(t, renderSnap.copyMode) |
| 163 | + | require.Same(t, document, renderSnap.copyMode.Document()) | |||
| 163 | renderSnap.Unlock() | 164 | renderSnap.Unlock() | ||
| 164 | 165 | ||||
| 165 | ac.overlays.copyMu.Lock() | 166 | ac.overlays.copyMu.Lock() | ||
| @@ -170,7 +171,7 @@ func TestOverlayRuntimeSnapshotCarriesCopyDocumentAndClearReleasesIt(t *testing. | |||||
| 170 | ac.overlays.copyMu.Unlock() | 171 | ac.overlays.copyMu.Unlock() | ||
| 171 | } | 172 | } | ||
| 172 | 173 | ||||
| 173 | - | func TestOverlayRuntimeCopyDocumentSurvivesRingOverwrite(t *testing.T) { | 174 | + | func TestOverlayRuntimeCopyModeDocumentSurvivesRingOverwrite(t *testing.T) { |
| 174 | ac := &attachedClient{} | 175 | ac := &attachedClient{} | ||
| 175 | ac.initOverlays() | 176 | ac.initOverlays() | ||
| 176 | history := newTestHistory(1) | 177 | history := newTestHistory(1) | ||
| @@ -185,6 +186,7 @@ func TestOverlayRuntimeCopyDocumentSurvivesRingOverwrite(t *testing.T) { | |||||
| 185 | history.Append(testRow("after")) | 186 | history.Append(testRow("after")) | ||
| 186 | renderSnap := ac.overlays.SnapshotForRender() | 187 | renderSnap := ac.overlays.SnapshotForRender() | ||
| 187 | defer renderSnap.Unlock() | 188 | defer renderSnap.Unlock() | ||
| 188 | - | require.Same(t, document, renderSnap.copyDocument) | 189 | + | require.NotNil(t, renderSnap.copyMode) |
| 189 | - | require.Equal(t, "before", rowText(renderSnap.copyDocument.Snapshot().Row(0))) | 190 | + | require.Same(t, document, renderSnap.copyMode.Document()) |
| 191 | + | require.Equal(t, "before", rowText(renderSnap.copyMode.Document().Snapshot().Row(0))) | |||
| 190 | } | 192 | } | ||