@@ -22,6 +22,7 @@ use iced::widget::{
2222 self , button, column, container, operation, row, rule, text_editor,
2323} ;
2424use iced:: { Alignment , Length , Task , clipboard, event, keyboard, padding} ;
25+ use itertools:: Itertools ;
2526use tokio:: time;
2627
2728use self :: completion:: Completion ;
@@ -34,6 +35,8 @@ use crate::{Theme, font, theme, window};
3435
3536mod completion;
3637
38+ const MAX_LINE_COUNT : usize = 20 ;
39+
3740pub enum Event {
3841 InputSent {
3942 history_task : Task < history:: manager:: Message > ,
@@ -348,7 +351,8 @@ pub fn view<'a>(
348351 iced:: keyboard:: Key :: Named (
349352 iced:: keyboard:: key:: Named :: Enter ,
350353 ) if key_press. modifiers . shift ( ) => {
351- Some ( text_editor:: Binding :: Enter )
354+ ( state. input_content . line_count ( ) < MAX_LINE_COUNT )
355+ . then_some ( text_editor:: Binding :: Enter )
352356 }
353357 // Send
354358 iced:: keyboard:: Key :: Named (
@@ -1074,7 +1078,26 @@ impl State {
10741078 ( task, None )
10751079 }
10761080 Message :: Action ( action) => {
1077- self . input_content . perform ( action. clone ( ) ) ;
1081+ if let text_editor:: Action :: Edit ( text_editor:: Edit :: Paste (
1082+ clipboard,
1083+ ) ) = & action
1084+ {
1085+ let truncated_clipboard = clipboard
1086+ . lines ( )
1087+ . take (
1088+ MAX_LINE_COUNT . saturating_sub (
1089+ self . input_content . line_count ( ) ,
1090+ ) + 1 ,
1091+ )
1092+ . join ( "\n " ) ;
1093+ let action =
1094+ text_editor:: Action :: Edit ( text_editor:: Edit :: Paste (
1095+ std:: sync:: Arc :: new ( truncated_clipboard) ,
1096+ ) ) ;
1097+ self . input_content . perform ( action) ;
1098+ } else {
1099+ self . input_content . perform ( action. clone ( ) ) ;
1100+ }
10781101
10791102 match & action {
10801103 text_editor:: Action :: Edit ( _) => {
0 commit comments