@@ -226,7 +226,6 @@ class TextArea(ScrollView):
226
226
Binding (
227
227
"ctrl+f" , "delete_word_right" , "Delete right to start of word" , show = False
228
228
),
229
- Binding ("ctrl+shift+x" , "delete_line" , "Delete line" , show = False ),
230
229
Binding ("ctrl+x" , "cut" , "Cut" , show = False ),
231
230
Binding ("ctrl+c" , "copy" , "Copy" , show = False ),
232
231
Binding ("ctrl+v" , "paste" , "Paste" , show = False ),
@@ -239,9 +238,14 @@ class TextArea(ScrollView):
239
238
"Delete to line end" ,
240
239
show = False ,
241
240
),
241
+ Binding (
242
+ "ctrl+shift+k" ,
243
+ "delete_line" ,
244
+ "Delete line" ,
245
+ show = False ,
246
+ ),
242
247
Binding ("ctrl+z" , "undo" , "Undo" , show = False ),
243
248
Binding ("ctrl+y" , "redo" , "Redo" , show = False ),
244
- Binding ("ctrl+c" , "copy_selection" , "Copy selected text" , show = False ),
245
249
]
246
250
"""
247
251
| Key(s) | Description |
@@ -268,13 +272,16 @@ class TextArea(ScrollView):
268
272
| ctrl+w | Delete from cursor to start of the word. |
269
273
| delete,ctrl+d | Delete character to the right of cursor. |
270
274
| ctrl+f | Delete from cursor to end of the word. |
271
- | ctrl+shift+x | Delete the current line. |
275
+ | ctrl+shift+k | Delete the current line. |
272
276
| ctrl+u | Delete from cursor to the start of the line. |
273
277
| ctrl+k | Delete from cursor to the end of the line. |
274
278
| f6 | Select the current line. |
275
279
| f7 | Select all text in the document. |
276
280
| ctrl+z | Undo. |
277
281
| ctrl+y | Redo. |
282
+ | ctrl+x | Cut selection or line if no selection. |
283
+ | ctrl+c | Copy selection to clipboard. |
284
+ | ctrl+v | Paste from clipboard. |
278
285
"""
279
286
280
287
language : Reactive [str | None ] = reactive (None , always_update = True , init = False )
@@ -2185,6 +2192,10 @@ def action_delete_right(self) -> None:
2185
2192
2186
2193
def action_delete_line (self ) -> None :
2187
2194
"""Deletes the lines which intersect with the selection."""
2195
+ self ._delete_cursor_line ()
2196
+
2197
+ def _delete_cursor_line (self ) -> EditResult | None :
2198
+ """Deletes the line (including the line terminator) that the cursor is on."""
2188
2199
start , end = self .selection
2189
2200
start , end = sorted ((start , end ))
2190
2201
start_row , _start_column = start
@@ -2201,25 +2212,26 @@ def action_delete_line(self) -> None:
2201
2212
deletion = self ._delete_via_keyboard (from_location , to_location )
2202
2213
if deletion is not None :
2203
2214
self .move_cursor_relative (columns = end_column , record_width = False )
2215
+ return deletion
2204
2216
2205
2217
def action_cut (self ) -> None :
2206
2218
"""Cut text (remove and copy to clipboard)."""
2207
2219
if self .read_only :
2208
2220
return
2209
2221
start , end = self .selection
2210
2222
if start == end :
2211
- return
2212
- copy_text = self .get_text_range (start , end )
2213
- self .app .copy_to_clipboard (copy_text )
2214
- self ._delete_via_keyboard (start , end )
2223
+ edit_result = self ._delete_cursor_line ()
2224
+ else :
2225
+ edit_result = self ._delete_via_keyboard (start , end )
2226
+
2227
+ if edit_result is not None :
2228
+ self .app .copy_to_clipboard (edit_result .replaced_text )
2215
2229
2216
2230
def action_copy (self ) -> None :
2217
2231
"""Copy selection to clipboard."""
2218
- start , end = self .selection
2219
- if start == end :
2220
- return
2221
- copy_text = self .get_text_range (start , end )
2222
- self .app .copy_to_clipboard (copy_text )
2232
+ selected_text = self .selected_text
2233
+ if selected_text :
2234
+ self .app .copy_to_clipboard (selected_text )
2223
2235
2224
2236
def action_paste (self ) -> None :
2225
2237
"""Paste from local clipboard."""
@@ -2310,10 +2322,6 @@ def action_delete_word_right(self) -> None:
2310
2322
2311
2323
self ._delete_via_keyboard (end , to_location )
2312
2324
2313
- def action_copy_selection (self ) -> None :
2314
- """Copy the current selection to the clipboard."""
2315
- self .app .copy_to_clipboard (self .selected_text )
2316
-
2317
2325
2318
2326
@lru_cache (maxsize = 128 )
2319
2327
def build_byte_to_codepoint_dict (data : bytes ) -> dict [int , int ]:
0 commit comments