@@ -41,6 +41,7 @@ pub struct EditorView {
4141 pseudo_pending : Vec < KeyEvent > ,
4242 pub ( crate ) last_insert : ( commands:: MappableCommand , Vec < InsertEvent > ) ,
4343 pub ( crate ) completion : Option < Completion > ,
44+ pub ( crate ) terminal : super :: terminal:: Terminal ,
4445 spinners : ProgressSpinners ,
4546 /// Tracks if the terminal window is focused by reaction to terminal focus events
4647 terminal_focused : bool ,
@@ -65,6 +66,7 @@ impl EditorView {
6566 pseudo_pending : Vec :: new ( ) ,
6667 last_insert : ( commands:: MappableCommand :: normal_mode, Vec :: new ( ) ) ,
6768 completion : None ,
69+ terminal : super :: terminal:: Terminal :: new ( ) ,
6870 spinners : ProgressSpinners :: default ( ) ,
6971 terminal_focused : true ,
7072 }
@@ -492,7 +494,7 @@ impl EditorView {
492494 let cursor_scope = match mode {
493495 Mode :: Insert => theme. find_highlight_exact ( "ui.cursor.insert" ) ,
494496 Mode :: Select => theme. find_highlight_exact ( "ui.cursor.select" ) ,
495- Mode :: Normal => theme. find_highlight_exact ( "ui.cursor.normal" ) ,
497+ _ => theme. find_highlight_exact ( "ui.cursor.normal" ) ,
496498 }
497499 . unwrap_or ( base_cursor_scope) ;
498500
@@ -1360,6 +1362,10 @@ impl Component for EditorView {
13601362 event : & Event ,
13611363 context : & mut crate :: compositor:: Context ,
13621364 ) -> EventResult {
1365+ if let Some ( result) = self . terminal . handle_event ( event, context) {
1366+ return result;
1367+ }
1368+
13631369 let mut cx = commands:: Context {
13641370 editor : context. editor ,
13651371 count : None ,
@@ -1541,9 +1547,21 @@ impl Component for EditorView {
15411547 editor_area = editor_area. clip_top ( 1 ) ;
15421548 }
15431549
1550+ let original_height = editor_area. height ;
1551+ if cx. editor . terminals . visible {
1552+ editor_area = editor_area. clip_bottom ( editor_area. height / 2 ) ;
1553+ }
1554+
15441555 // if the terminal size suddenly changed, we need to trigger a resize
15451556 cx. editor . resize ( editor_area) ;
15461557
1558+ if cx. editor . terminals . visible {
1559+ let mut term_area = editor_area;
1560+ term_area. height = original_height - editor_area. height ;
1561+ term_area. y += editor_area. height ;
1562+ self . terminal . render ( term_area, surface, cx) ;
1563+ }
1564+
15471565 if use_bufferline {
15481566 Self :: render_bufferline ( cx. editor , area. with_height ( 1 ) , surface) ;
15491567 }
@@ -1624,18 +1642,29 @@ impl Component for EditorView {
16241642 }
16251643 }
16261644
1627- fn cursor ( & self , _area : Rect , editor : & Editor ) -> ( Option < Position > , CursorKind ) {
1628- match editor. cursor ( ) {
1629- // all block cursors are drawn manually
1630- ( pos, CursorKind :: Block ) => {
1631- if self . terminal_focused {
1632- ( pos, CursorKind :: Hidden )
1633- } else {
1634- // use terminal cursor when terminal loses focus
1635- ( pos, CursorKind :: Underline )
1645+ fn cursor ( & self , area : Rect , editor : & Editor ) -> ( Option < Position > , CursorKind ) {
1646+ if editor. terminals . visible {
1647+ let mut a = area;
1648+ a. y += a. height / 2 ;
1649+
1650+ if let Some ( v) = self . terminal . get_cursor ( a, editor) {
1651+ v
1652+ } else {
1653+ ( None , CursorKind :: Hidden )
1654+ }
1655+ } else {
1656+ match editor. cursor ( ) {
1657+ // all block cursors are drawn manually
1658+ ( pos, CursorKind :: Block ) => {
1659+ if self . terminal_focused {
1660+ ( pos, CursorKind :: Hidden )
1661+ } else {
1662+ // use terminal cursor when terminal loses focus
1663+ ( pos, CursorKind :: Underline )
1664+ }
16361665 }
1666+ cursor => cursor,
16371667 }
1638- cursor => cursor,
16391668 }
16401669 }
16411670}
0 commit comments