Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions crates/openproof-core/src/apply_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,24 @@ impl AppState {
}
}

/// Threshold for collapsing paste into a marker block.
/// Pastes shorter than this AND single-line are inlined directly.
const PASTE_INLINE_MAX: usize = 120;

pub(crate) fn apply_paste(&mut self, text: String) {
if self.focus != FocusPane::Composer {
return;
}
let line_count = text.lines().count();
if line_count < 2 {
// Single-line paste: inline directly.
// Strip carriage returns to normalize line endings (Windows \r\n -> \n).
let text = text.replace('\r', "");
let is_multiline = text.lines().count() >= 2;
let is_long = text.len() > Self::PASTE_INLINE_MAX;
if !is_multiline && !is_long {
// Short single-line paste: inline directly.
self.composer.insert_str(self.composer_cursor, &text);
self.composer_cursor += text.len();
} else {
// Multi-line paste: store as a collapsed block.
// Long or multi-line paste: store as a collapsed block.
let marker_index = self.composer[..self.composer_cursor]
.chars()
.filter(|&c| c == PASTE_MARKER)
Expand Down
16 changes: 12 additions & 4 deletions crates/openproof-tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,12 @@ fn build_input_lines(text: &str, cursor: usize, paste_blocks: &[String]) -> Vec<

/// Compute the height needed for the input area, accounting for text wrapping,
/// newlines, and paste block display labels.
/// Get the display width of a character, using Unicode width tables.
/// Returns 0 for control characters, 2 for wide CJK characters, 1 for most others.
fn char_display_width(ch: char) -> usize {
unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0)
}

fn compute_input_height(
text: &str,
prefix_len: usize,
Expand Down Expand Up @@ -1073,10 +1079,11 @@ fn compute_input_height(
}
block_idx += 1;
} else {
col += 1;
let w = char_display_width(ch);
col += w;
if col >= usable {
visual_lines += 1;
col = 0;
col = if col > usable { w } else { 0 };
}
}
}
Expand Down Expand Up @@ -1116,10 +1123,11 @@ fn cursor_visual_row(
}
block_idx += 1;
} else {
col += 1;
let w = char_display_width(ch);
col += w;
if col >= width {
row += 1;
col = 0;
col = if col > width { w } else { 0 };
}
}
}
Expand Down
Loading