diff --git a/term/src/terminalstate/image.rs b/term/src/terminalstate/image.rs index ddb974378..db66783cc 100644 --- a/term/src/terminalstate/image.rs +++ b/term/src/terminalstate/image.rs @@ -44,6 +44,7 @@ pub struct ImageAttachParams { pub placement_id: Option, pub style: ImageAttachStyle, + pub do_not_move_cursor: bool, pub data: Arc, } @@ -99,9 +100,20 @@ impl TerminalState { self.pixel_width, self.pixel_height ); - for _ in 0..height_in_cells { + + let height_in_cells = if params.do_not_move_cursor { + height_in_cells.min(self.screen().physical_rows - self.cursor.y as usize) + } else { + height_in_cells + }; + + for y in 0..height_in_cells { let mut xpos = start_xpos; - let cursor_y = self.cursor.y; + let cursor_y = if params.do_not_move_cursor { + self.cursor.y + y as i64 + } else { + self.cursor.y + }; log::debug!( "setting cells for y={} x=[{}..{}]", cursor_y, @@ -135,22 +147,26 @@ impl TerminalState { xpos += x_delta; } ypos += y_delta; - self.new_line(false); + if !params.do_not_move_cursor { + self.new_line(false); + } } - // Sixel places the cursor under the left corner of the image, - // unless sixel_scrolls_right is enabled. - // iTerm places it after the bottom right corner. - let bottom_right = match params.style { - ImageAttachStyle::Kitty | ImageAttachStyle::Iterm => true, - ImageAttachStyle::Sixel => self.sixel_scrolls_right, - }; + if !params.do_not_move_cursor { + // Sixel places the cursor under the left corner of the image, + // unless sixel_scrolls_right is enabled. + // iTerm places it after the bottom right corner. + let bottom_right = match params.style { + ImageAttachStyle::Kitty | ImageAttachStyle::Iterm => true, + ImageAttachStyle::Sixel => self.sixel_scrolls_right, + }; - if bottom_right { - self.set_cursor_pos( - &Position::Relative(width_in_cells as i64), - &Position::Relative(-1), - ); + if bottom_right { + self.set_cursor_pos( + &Position::Relative(width_in_cells as i64), + &Position::Relative(-1), + ); + } } PlacementInfo { diff --git a/term/src/terminalstate/iterm.rs b/term/src/terminalstate/iterm.rs index a3c7242ad..a3331b566 100644 --- a/term/src/terminalstate/iterm.rs +++ b/term/src/terminalstate/iterm.rs @@ -138,6 +138,7 @@ impl TerminalState { style: ImageAttachStyle::Iterm, image_id: 0, placement_id: None, + do_not_move_cursor: false, }); } } diff --git a/term/src/terminalstate/kitty.rs b/term/src/terminalstate/kitty.rs index b6e100b66..2a018cf6f 100644 --- a/term/src/terminalstate/kitty.rs +++ b/term/src/terminalstate/kitty.rs @@ -110,8 +110,6 @@ impl TerminalState { | ImageDataType::Rgba8 { width, height, .. } => (*width, *height), }; - let saved_cursor = self.cursor.clone(); - let info = self.assign_image_to_cells(ImageAttachParams { image_width, image_height, @@ -128,6 +126,7 @@ impl TerminalState { rows: placement.rows.map(|x| x as usize), image_id, placement_id: placement.placement_id, + do_not_move_cursor: placement.do_not_move_cursor, }); self.kitty_img @@ -140,10 +139,6 @@ impl TerminalState { placement.placement_id ); - if placement.do_not_move_cursor { - self.cursor = saved_cursor; - } - Ok(()) } diff --git a/term/src/terminalstate/sixel.rs b/term/src/terminalstate/sixel.rs index 83ca30068..26186451a 100644 --- a/term/src/terminalstate/sixel.rs +++ b/term/src/terminalstate/sixel.rs @@ -123,6 +123,7 @@ impl TerminalState { z_index: 0, image_id: 0, placement_id: None, + do_not_move_cursor: false, }); } }