@@ -2,29 +2,30 @@ use crate::alacritty::{BackendCommand, TerminalContext};
22use crate :: bindings:: Binding ;
33use crate :: bindings:: { BindingAction , Bindings , InputKind } ;
44use crate :: font:: TerminalFont ;
5- use crate :: input:: InputAction ;
5+ use crate :: input:: { is_in_terminal , InputAction } ;
66use crate :: scroll_bar:: { InteractiveScrollbar , ScrollbarState } ;
77use crate :: theme:: TerminalTheme ;
88use crate :: types:: Size ;
99use alacritty_terminal:: grid:: { Dimensions , Scroll } ;
1010use alacritty_terminal:: index:: Point ;
1111use alacritty_terminal:: vte:: ansi:: { Color , NamedColor } ;
12- use egui:: ImeEvent ;
12+ use egui:: output :: IMEOutput ;
1313use egui:: Widget ;
1414use egui:: { Context , Event } ;
1515use egui:: { CursorIcon , Key } ;
1616use egui:: { Id , Pos2 } ;
17+ use egui:: { ImeEvent , Rect } ;
1718use egui:: { Response , Vec2 } ;
1819
1920#[ derive( Clone , Default ) ]
2021pub struct TerminalViewState {
2122 pub is_dragged : bool ,
2223 pub scroll_pixels : f32 ,
2324 // for terminal
24- pub mouse_position : Point ,
25+ pub mouse_point : Point ,
26+ pub mouse_position : Option < Pos2 > ,
27+ pub context_menu_position : Option < Pos2 > ,
2528 pub cursor_position : Option < Pos2 > ,
26- // ime_enabled: bool,
27- // ime_cursor_range: CursorRange,
2829 pub scrollbar_state : ScrollbarState ,
2930}
3031
@@ -80,13 +81,14 @@ impl Widget for TerminalView<'_> {
8081 }
8182
8283 // context menu
83- if let Some ( pos) = state. cursor_position {
84- if ! out_of_terminal ( pos, & layout) {
84+ if let Some ( pos) = state. context_menu_position {
85+ if is_in_terminal ( pos, layout. rect ) {
8586 self . context_menu ( pos, & layout, ui) ;
8687 }
8788 }
89+
8890 if ui. input ( |input_state| input_state. pointer . primary_clicked ( ) ) {
89- state. cursor_position = None ;
91+ state. context_menu_position = None ;
9092 ui. close ( ) ;
9193 }
9294
@@ -97,6 +99,20 @@ impl Widget for TerminalView<'_> {
9799 . resize ( & layout)
98100 . process_input ( & mut state, & layout) ;
99101
102+ if let Some ( pos) = state. mouse_position {
103+ if is_in_terminal ( pos, layout. rect ) {
104+ if let Some ( cur_pos) = state. cursor_position {
105+ ui. ctx ( ) . output_mut ( |output| {
106+ let vec = Vec2 :: new ( 15. , 15. ) ;
107+ output. ime = Some ( IMEOutput {
108+ rect : Rect :: from_min_size ( cur_pos, vec) ,
109+ cursor_rect : Rect :: from_min_size ( cur_pos, vec) ,
110+ } )
111+ } ) ;
112+ }
113+ }
114+ }
115+
100116 let grid = term. term_ctx . terminal . grid_mut ( ) ;
101117 let total_lines = grid. total_lines ( ) as f32 ;
102118 let display_offset = grid. display_offset ( ) as f32 ;
@@ -241,10 +257,10 @@ impl<'a> TerminalView<'a> {
241257 modifiers,
242258 pos,
243259 } => {
244- let new_pos = if out_of_terminal ( pos, layout) {
245- pos. clamp ( layout. rect . min , layout. rect . max )
246- } else {
260+ let new_pos = if is_in_terminal ( pos, layout. rect ) {
247261 pos
262+ } else {
263+ pos. clamp ( layout. rect . min , layout. rect . max )
248264 } ;
249265
250266 if let Some ( action) =
@@ -257,15 +273,17 @@ impl<'a> TerminalView<'a> {
257273 input_actions = self . mouse_move ( state, layout, pos, & modifiers)
258274 }
259275 Event :: Ime ( event) => match event {
260- ImeEvent :: Disabled => {
261- // state.ime_enabled = false;
276+ ImeEvent :: Preedit ( text_mark) => {
277+ if text_mark != "\n " && text_mark != "\r " {
278+ // TODO: handle preedit
279+ }
262280 }
263- ImeEvent :: Enabled | ImeEvent :: Preedit ( _) => {
264- // state.ime_enabled = true;
265- }
266- ImeEvent :: Commit ( text) => {
267- input_actions. push ( self . text_input ( & text) ) ;
281+ ImeEvent :: Commit ( prediction) => {
282+ if prediction != "\n " && prediction != "\r " {
283+ input_actions. push ( self . text_input ( & prediction) ) ;
284+ }
268285 }
286+ _ => { }
269287 } ,
270288 _ => { }
271289 } ;
@@ -285,10 +303,3 @@ impl<'a> TerminalView<'a> {
285303 self
286304 }
287305}
288-
289- fn out_of_terminal ( pos : Pos2 , layout : & Response ) -> bool {
290- !( pos. x > layout. rect . min . x
291- && pos. x < layout. rect . max . x
292- && pos. y > layout. rect . min . y
293- && pos. y < layout. rect . max . y )
294- }
0 commit comments