input: Delete selected text with modifier keys (#1497)
In most applications, when text is selected and backspace/delete is pressed, the selection is simply deleted. Currently, gpui-component will ignore the selected text and delete the previous/next word when Ctrl is pressed. This can be very confusing especially if you do ctrl+a then ctrl+backspace, expecting the input to be cleared. This PR makes it so that if there is an active selection, the active selection is deleted before doing any extra processing.
This commit is contained in:
parent
893e323692
commit
e7aa8983dc
1 changed files with 24 additions and 1 deletions
|
|
@ -1060,6 +1060,12 @@ impl InputState {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if !self.selected_range.is_empty() {
|
||||
self.replace_text_in_range(None, "", window, cx);
|
||||
self.pause_blink_cursor(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut offset = self.start_of_line();
|
||||
if offset == self.cursor() {
|
||||
offset = offset.saturating_sub(1);
|
||||
|
|
@ -1070,7 +1076,6 @@ impl InputState {
|
|||
window,
|
||||
cx,
|
||||
);
|
||||
|
||||
self.pause_blink_cursor(cx);
|
||||
}
|
||||
|
||||
|
|
@ -1080,6 +1085,12 @@ impl InputState {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if !self.selected_range.is_empty() {
|
||||
self.replace_text_in_range(None, "", window, cx);
|
||||
self.pause_blink_cursor(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut offset = self.end_of_line();
|
||||
if offset == self.cursor() {
|
||||
offset = (offset + 1).clamp(0, self.text.len());
|
||||
|
|
@ -1099,6 +1110,12 @@ impl InputState {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if !self.selected_range.is_empty() {
|
||||
self.replace_text_in_range(None, "", window, cx);
|
||||
self.pause_blink_cursor(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let offset = self.previous_start_of_word();
|
||||
self.replace_text_in_range_silent(
|
||||
Some(self.range_to_utf16(&(offset..self.cursor()))),
|
||||
|
|
@ -1115,6 +1132,12 @@ impl InputState {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if !self.selected_range.is_empty() {
|
||||
self.replace_text_in_range(None, "", window, cx);
|
||||
self.pause_blink_cursor(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let offset = self.next_end_of_word();
|
||||
self.replace_text_in_range_silent(
|
||||
Some(self.range_to_utf16(&(self.cursor()..offset))),
|
||||
|
|
|
|||
Loading…
Reference in a new issue