Skip to content

Commit 2e5df5e

Browse files
committed
feat: support ime
1 parent 3144d1e commit 2e5df5e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

crates/egui-term/src/input/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{BindingAction, InputKind, TerminalView};
44
use alacritty_terminal::grid::Dimensions;
55
use alacritty_terminal::selection::SelectionType;
66
use alacritty_terminal::term::TermMode;
7-
use egui::{Key, Modifiers, MouseWheelUnit, PointerButton, Pos2, Response, Vec2};
7+
use egui::{Key, Modifiers, MouseWheelUnit, PointerButton, Pos2, Rect, Response, Vec2};
88
use std::cmp::min;
99

1010
/// Minimum number of pixels at the bottom/top where selection scrolling is performed.
@@ -160,7 +160,7 @@ impl TerminalView<'_> {
160160
state.mouse_point,
161161
pressed,
162162
)))
163-
} else if pressed {
163+
} else if pressed && is_in_terminal(position, layout.rect) {
164164
state.is_dragged = true;
165165
Some(InputAction::BackendCall(start_select_command(
166166
layout, position,
@@ -294,3 +294,7 @@ fn start_select_command(layout: &Response, cursor_position: Pos2) -> BackendComm
294294
cursor_position.y - layout.rect.min.y,
295295
)
296296
}
297+
298+
pub fn is_in_terminal(pos: Pos2, rect: Rect) -> bool {
299+
pos.x > rect.min.x && pos.x < rect.max.x && pos.y > rect.min.y && pos.y < rect.max.y
300+
}

crates/egui-term/src/view.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::alacritty::{BackendCommand, TerminalContext};
22
use crate::bindings::Binding;
33
use crate::bindings::{BindingAction, Bindings, InputKind};
44
use crate::font::TerminalFont;
5-
use crate::input::InputAction;
5+
use crate::input::{is_in_terminal, InputAction};
66
use crate::scroll_bar::{InteractiveScrollbar, ScrollbarState};
77
use crate::theme::TerminalTheme;
88
use crate::types::Size;
@@ -82,7 +82,7 @@ impl Widget for TerminalView<'_> {
8282

8383
// context menu
8484
if let Some(pos) = state.context_menu_position {
85-
if !out_of_terminal(pos, layout.rect) {
85+
if is_in_terminal(pos, layout.rect) {
8686
self.context_menu(pos, &layout, ui);
8787
}
8888
}
@@ -100,7 +100,7 @@ impl Widget for TerminalView<'_> {
100100
.process_input(&mut state, &layout);
101101

102102
if let Some(pos) = state.mouse_position {
103-
if !out_of_terminal(pos, layout.rect) {
103+
if is_in_terminal(pos, layout.rect) {
104104
if let Some(cur_pos) = state.cursor_position {
105105
ui.ctx().output_mut(|output| {
106106
let vec = Vec2::new(15., 15.);
@@ -257,10 +257,10 @@ impl<'a> TerminalView<'a> {
257257
modifiers,
258258
pos,
259259
} => {
260-
let new_pos = if out_of_terminal(pos, layout.rect) {
261-
pos.clamp(layout.rect.min, layout.rect.max)
262-
} else {
260+
let new_pos = if is_in_terminal(pos, layout.rect) {
263261
pos
262+
} else {
263+
pos.clamp(layout.rect.min, layout.rect.max)
264264
};
265265

266266
if let Some(action) =
@@ -303,7 +303,3 @@ impl<'a> TerminalView<'a> {
303303
self
304304
}
305305
}
306-
307-
fn out_of_terminal(pos: Pos2, rect: Rect) -> bool {
308-
!(pos.x > rect.min.x && pos.x < rect.max.x && pos.y > rect.min.y && pos.y < rect.max.y)
309-
}

0 commit comments

Comments
 (0)