From d2797c28c7ca721c758a65ee61347e7c172b53a4 Mon Sep 17 00:00:00 2001 From: Marcin Konarski Date: Mon, 8 Nov 2021 02:21:08 +0100 Subject: [PATCH] ReplxxImpl: Fix bracketed paste of character. --- examples/cxx-api.cxx | 10 +++++++++- src/replxx_impl.cxx | 2 ++ tests.py | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/cxx-api.cxx b/examples/cxx-api.cxx index 3e79787..7ce6db2 100644 --- a/examples/cxx-api.cxx +++ b/examples/cxx-api.cxx @@ -356,6 +356,7 @@ int main( int argc_, char** argv_ ) { bool promptFan( false ); bool promptInCallback( false ); bool indentMultiline( false ); + bool bracketedPaste( false ); std::string keys; std::string prompt; int hintDelay( 0 ); @@ -371,6 +372,7 @@ int main( int argc_, char** argv_ ) { case ( 'd' ): hintDelay = std::stoi( (*argv_) + 1 ); break; case ( 'h' ): examples.push_back( (*argv_) + 1 ); break; case ( 'p' ): prompt = (*argv_) + 1; break; + case ( 'B' ): bracketedPaste = true; break; } } @@ -412,6 +414,9 @@ int main( int argc_, char** argv_ ) { rx.set_beep_on_ambiguous_completion( false ); rx.set_no_color( false ); rx.set_indent_multiline( indentMultiline ); + if ( bracketedPaste ) { + rx.enable_bracketed_paste(); + } // showcase key bindings rx.bind_key_internal( Replxx::KEY::BACKSPACE, "delete_character_left_of_cursor" ); @@ -615,7 +620,10 @@ int main( int argc_, char** argv_ ) { // save the history rx.history_sync( history_file_path ); - if ( promptInCallback || promptFan ) { + if ( bracketedPaste ) { + rx.disable_bracketed_paste(); + } + if ( bracketedPaste || promptInCallback || promptFan ) { std::cout << "\n" << prompt; } diff --git a/src/replxx_impl.cxx b/src/replxx_impl.cxx index 22ee748..6fcacff 100644 --- a/src/replxx_impl.cxx +++ b/src/replxx_impl.cxx @@ -2302,6 +2302,8 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::bracketed_paste( char32_t ) { } if ( ( c == '\r' ) || ( c == KEY::control( 'M' ) ) ) { c = '\n'; + } else if ( c == KEY::control( 'I' ) ) { + c = '\t'; } buf.push_back( c ); } diff --git a/tests.py b/tests.py index e87689a..8dbd525 100755 --- a/tests.py +++ b/tests.py @@ -2118,6 +2118,11 @@ def test_bracketed_paste( self_ ): "x\r\n", command = [ ReplxxTests._cSample_, "q1" ] ) + self_.check_scenario( + "aaa\n\tbbb", + "\r\n", + command = [ ReplxxTests._cxxSample_, "B" ] + ) def test_embedded_newline( self_ ): self_.check_scenario( "",