kitty img: don't move the cursor when requested not to
We were actually moving it during placement, and then restoring the original placement. That could potentially lead to the screen being scrolled, so we want to avoid that. refs: #986
This commit is contained in:
1 parent
4e1f933e00
commit
6d702275df
4 files changed
+34
-21
No files matched your search
@@ -44,6 +44,7 @@ pub struct ImageAttachParams {
|
||||
pub placement_id: Option<u32>,
|
||||
|
||||
pub style: ImageAttachStyle,
|
||||
pub do_not_move_cursor: bool,
|
||||
|
||||
pub data: Arc<ImageData>,
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -138,6 +138,7 @@ impl TerminalState {
|
||||
style: ImageAttachStyle::Iterm,
|
||||
image_id: 0,
|
||||
placement_id: None,
|
||||
do_not_move_cursor: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ impl TerminalState {
|
||||
z_index: 0,
|
||||
image_id: 0,
|
||||
placement_id: None,
|
||||
do_not_move_cursor: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user