зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-03 14:26:17 +03:00
fix selected text is not deleted on paste
Этот коммит содержится в:
@@ -1276,6 +1276,7 @@ impl<'a> TextArea<'a> {
|
||||
/// assert_eq!(textarea.lines(), [" bbb cccaaa"]);
|
||||
/// ```
|
||||
pub fn paste(&mut self) -> bool {
|
||||
self.delete_selection(false);
|
||||
match self.yank.clone() {
|
||||
YankText::Piece(s) => self.insert_piece(s),
|
||||
YankText::Chunk(c) => self.insert_chunk(c),
|
||||
|
||||
@@ -1432,6 +1432,27 @@ fn test_select_all() {
|
||||
assert_undo_redo((2, 3), &["aaa", "bbb", "ccc"], &[""], &mut t, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_paste_while_selection() {
|
||||
let mut t = TextArea::from(["ab", "cd"]);
|
||||
t.move_cursor(CursorMove::Jump(0, 1));
|
||||
t.start_selection();
|
||||
t.move_cursor(CursorMove::Jump(1, 1));
|
||||
t.set_yank_text("x\ny");
|
||||
assert!(t.paste());
|
||||
assert_eq!(t.lines(), ["ax", "yd"]);
|
||||
assert_eq!(t.cursor(), (1, 1));
|
||||
assert!(!t.is_selecting());
|
||||
|
||||
let mut t = TextArea::from(["ab", "cd"]);
|
||||
t.select_all();
|
||||
t.set_yank_text("xy\nzw");
|
||||
assert!(t.paste());
|
||||
assert_eq!(t.lines(), ["xy", "zw"]);
|
||||
assert_eq!(t.cursor(), (1, 2));
|
||||
assert!(!t.is_selecting());
|
||||
}
|
||||
|
||||
struct DeleteTester(&'static [&'static str], fn(&mut TextArea) -> bool);
|
||||
impl DeleteTester {
|
||||
fn test(&self, before: (usize, usize), after: (usize, usize, &[&str], &str)) {
|
||||
|
||||
Ссылка в новой задаче
Block a user