File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1036,6 +1036,32 @@ def cut_selection(self) -> tuple[Document, ClipboardData]:
1036
1036
else :
1037
1037
return self , ClipboardData ("" )
1038
1038
1039
+ def delete_selection (self ) -> Document :
1040
+ """
1041
+ Returns :class:`.Document` where the
1042
+ document represents the new document when the selection is deleted.
1043
+ """
1044
+ if self .selection :
1045
+ # cut_parts = []
1046
+ remaining_parts = []
1047
+ new_cursor_position = self .cursor_position
1048
+
1049
+ last_to = 0
1050
+ for from_ , to in self .selection_ranges ():
1051
+ if last_to == 0 :
1052
+ new_cursor_position = from_
1053
+
1054
+ remaining_parts .append (self .text [last_to :from_ ])
1055
+ last_to = to
1056
+
1057
+ remaining_parts .append (self .text [last_to :])
1058
+
1059
+ remaining_text = "" .join (remaining_parts )
1060
+
1061
+ return Document (text = remaining_text , cursor_position = new_cursor_position )
1062
+ else :
1063
+ return self
1064
+
1039
1065
def paste_clipboard_data (
1040
1066
self ,
1041
1067
data : ClipboardData ,
You can’t perform that action at this time.
0 commit comments