Fixed scrolling on text input

This commit is contained in:
Mikayla Maki 2022-08-18 13:22:48 -07:00
parent d545e59b49
commit aa98e5c3f7
3 changed files with 50 additions and 40 deletions

View file

@ -149,9 +149,9 @@ impl ConnectedView {
{
cx.show_character_palette();
} else {
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("ctrl-cmd-space").unwrap());
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("ctrl-cmd-space").unwrap())
});
}
}
@ -258,41 +258,41 @@ impl ConnectedView {
///Synthesize the keyboard event corresponding to 'up'
fn up(&mut self, _: &Up, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("up").unwrap());
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("up").unwrap())
});
}
///Synthesize the keyboard event corresponding to 'down'
fn down(&mut self, _: &Down, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("down").unwrap());
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("down").unwrap())
});
}
///Synthesize the keyboard event corresponding to 'ctrl-c'
fn ctrl_c(&mut self, _: &CtrlC, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("ctrl-c").unwrap());
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("ctrl-c").unwrap())
});
}
///Synthesize the keyboard event corresponding to 'escape'
fn escape(&mut self, _: &Escape, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("escape").unwrap());
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("escape").unwrap())
});
}
///Synthesize the keyboard event corresponding to 'enter'
fn enter(&mut self, _: &Enter, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("enter").unwrap());
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("enter").unwrap())
});
}
}
@ -358,8 +358,10 @@ impl View for ConnectedView {
text: &str,
cx: &mut ViewContext<Self>,
) {
self.terminal
.update(cx, |terminal, _| terminal.write_to_pty(text.into()));
self.terminal.update(cx, |terminal, _| {
terminal.write_to_pty(text.into());
terminal.scroll(alacritty_terminal::grid::Scroll::Bottom);
});
}
fn keymap_context(&self, _: &gpui::AppContext) -> gpui::keymap::Context {

View file

@ -467,14 +467,14 @@ impl Terminal {
AlacTermEvent::ClipboardStore(_, data) => {
cx.write_to_clipboard(ClipboardItem::new(data.to_string()))
}
AlacTermEvent::ClipboardLoad(_, format) => self.notify_pty(format(
AlacTermEvent::ClipboardLoad(_, format) => self.write_to_pty(format(
&cx.read_from_clipboard()
.map(|ci| ci.text().to_string())
.unwrap_or_else(|| "".to_string()),
)),
AlacTermEvent::PtyWrite(out) => self.notify_pty(out.clone()),
AlacTermEvent::PtyWrite(out) => self.write_to_pty(out.clone()),
AlacTermEvent::TextAreaSizeRequest(format) => {
self.notify_pty(format(self.cur_size.into()))
self.write_to_pty(format(self.cur_size.into()))
}
AlacTermEvent::CursorBlinkingChange => {
cx.emit(Event::BlinkChanged);
@ -517,7 +517,7 @@ impl Terminal {
let term_style = &cx.global::<Settings>().theme.terminal;
to_alac_rgb(get_color_at_index(index, &term_style.colors))
});
self.notify_pty(format(color))
self.write_to_pty(format(color))
}
}
InternalEvent::Resize(new_size) => {
@ -528,7 +528,7 @@ impl Terminal {
term.resize(*new_size);
}
InternalEvent::Clear => {
self.notify_pty("\x0c".to_string());
self.write_to_pty("\x0c".to_string());
term.clear_screen(ClearMode::Saved);
}
InternalEvent::Scroll(scroll) => term.scroll_display(*scroll),
@ -548,12 +548,8 @@ impl Terminal {
}
}
pub fn notify_pty(&self, txt: String) {
self.pty_tx.notify(txt.into_bytes());
}
///Write the Input payload to the tty.
pub fn write_to_pty(&mut self, input: String) {
pub fn write_to_pty(&self, input: String) {
self.pty_tx.notify(input.into_bytes());
}
@ -566,10 +562,11 @@ impl Terminal {
self.events.push(InternalEvent::Clear)
}
pub fn try_keystroke(&self, keystroke: &Keystroke) -> bool {
pub fn try_keystroke(&mut self, keystroke: &Keystroke) -> bool {
let esc = to_esc_str(keystroke, &self.last_mode);
if let Some(esc) = esc {
self.notify_pty(esc);
self.write_to_pty(esc);
self.scroll(Scroll::Bottom);
true
} else {
false
@ -579,11 +576,11 @@ impl Terminal {
///Paste text into the terminal
pub fn paste(&self, text: &str) {
if self.last_mode.contains(TermMode::BRACKETED_PASTE) {
self.notify_pty("\x1b[200~".to_string());
self.notify_pty(text.replace('\x1b', ""));
self.notify_pty("\x1b[201~".to_string());
self.write_to_pty("\x1b[200~".to_string());
self.write_to_pty(text.replace('\x1b', ""));
self.write_to_pty("\x1b[201~".to_string());
} else {
self.notify_pty(text.replace("\r\n", "\r").replace('\n', "\r"));
self.write_to_pty(text.replace("\r\n", "\r").replace('\n', "\r"));
}
}
@ -619,13 +616,13 @@ impl Terminal {
pub fn focus_in(&self) {
if self.last_mode.contains(TermMode::FOCUS_IN_OUT) {
self.notify_pty("\x1b[I".to_string());
self.write_to_pty("\x1b[I".to_string());
}
}
pub fn focus_out(&self) {
if self.last_mode.contains(TermMode::FOCUS_IN_OUT) {
self.notify_pty("\x1b[O".to_string());
self.write_to_pty("\x1b[O".to_string());
}
}