Fix cannot select in terminal when copy_on_select is enabled (#34131)
Closes #33989  Release Notes: - N/A
This commit is contained in:
parent
cf1ce1beed
commit
84124c60db
2 changed files with 12 additions and 12 deletions
|
@ -162,7 +162,8 @@ enum InternalEvent {
|
||||||
UpdateSelection(Point<Pixels>),
|
UpdateSelection(Point<Pixels>),
|
||||||
// Adjusted mouse position, should open
|
// Adjusted mouse position, should open
|
||||||
FindHyperlink(Point<Pixels>, bool),
|
FindHyperlink(Point<Pixels>, bool),
|
||||||
Copy,
|
// Whether keep selection when copy
|
||||||
|
Copy(Option<bool>),
|
||||||
// Vi mode events
|
// Vi mode events
|
||||||
ToggleViMode,
|
ToggleViMode,
|
||||||
ViMotion(ViMotion),
|
ViMotion(ViMotion),
|
||||||
|
@ -931,13 +932,13 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalEvent::Copy => {
|
InternalEvent::Copy(keep_selection) => {
|
||||||
if let Some(txt) = term.selection_to_string() {
|
if let Some(txt) = term.selection_to_string() {
|
||||||
cx.write_to_clipboard(ClipboardItem::new_string(txt));
|
cx.write_to_clipboard(ClipboardItem::new_string(txt));
|
||||||
|
if !keep_selection.unwrap_or_else(|| {
|
||||||
let settings = TerminalSettings::get_global(cx);
|
let settings = TerminalSettings::get_global(cx);
|
||||||
|
settings.keep_selection_on_copy
|
||||||
if !settings.keep_selection_on_copy {
|
}) {
|
||||||
self.events.push_back(InternalEvent::SetSelection(None));
|
self.events.push_back(InternalEvent::SetSelection(None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1108,8 +1109,8 @@ impl Terminal {
|
||||||
.push_back(InternalEvent::SetSelection(selection));
|
.push_back(InternalEvent::SetSelection(selection));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy(&mut self) {
|
pub fn copy(&mut self, keep_selection: Option<bool>) {
|
||||||
self.events.push_back(InternalEvent::Copy);
|
self.events.push_back(InternalEvent::Copy(keep_selection));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
|
@ -1267,8 +1268,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
|
|
||||||
"y" => {
|
"y" => {
|
||||||
self.events.push_back(InternalEvent::Copy);
|
self.copy(Some(false));
|
||||||
self.events.push_back(InternalEvent::SetSelection(None));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1653,7 +1653,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if e.button == MouseButton::Left && setting.copy_on_select {
|
if e.button == MouseButton::Left && setting.copy_on_select {
|
||||||
self.copy();
|
self.copy(Some(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hyperlinks
|
//Hyperlinks
|
||||||
|
|
|
@ -715,7 +715,7 @@ impl TerminalView {
|
||||||
|
|
||||||
///Attempt to paste the clipboard into the terminal
|
///Attempt to paste the clipboard into the terminal
|
||||||
fn copy(&mut self, _: &Copy, _: &mut Window, cx: &mut Context<Self>) {
|
fn copy(&mut self, _: &Copy, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.terminal.update(cx, |term, _| term.copy());
|
self.terminal.update(cx, |term, _| term.copy(None));
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue