Skip to content

Commit d2797c2

Browse files
ReplxxImpl: Fix bracketed paste of <tab> character.
1 parent 2b24846 commit d2797c2

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

examples/cxx-api.cxx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ int main( int argc_, char** argv_ ) {
356356
bool promptFan( false );
357357
bool promptInCallback( false );
358358
bool indentMultiline( false );
359+
bool bracketedPaste( false );
359360
std::string keys;
360361
std::string prompt;
361362
int hintDelay( 0 );
@@ -371,6 +372,7 @@ int main( int argc_, char** argv_ ) {
371372
case ( 'd' ): hintDelay = std::stoi( (*argv_) + 1 ); break;
372373
case ( 'h' ): examples.push_back( (*argv_) + 1 ); break;
373374
case ( 'p' ): prompt = (*argv_) + 1; break;
375+
case ( 'B' ): bracketedPaste = true; break;
374376
}
375377
}
376378

@@ -412,6 +414,9 @@ int main( int argc_, char** argv_ ) {
412414
rx.set_beep_on_ambiguous_completion( false );
413415
rx.set_no_color( false );
414416
rx.set_indent_multiline( indentMultiline );
417+
if ( bracketedPaste ) {
418+
rx.enable_bracketed_paste();
419+
}
415420

416421
// showcase key bindings
417422
rx.bind_key_internal( Replxx::KEY::BACKSPACE, "delete_character_left_of_cursor" );
@@ -615,7 +620,10 @@ int main( int argc_, char** argv_ ) {
615620

616621
// save the history
617622
rx.history_sync( history_file_path );
618-
if ( promptInCallback || promptFan ) {
623+
if ( bracketedPaste ) {
624+
rx.disable_bracketed_paste();
625+
}
626+
if ( bracketedPaste || promptInCallback || promptFan ) {
619627
std::cout << "\n" << prompt;
620628
}
621629

src/replxx_impl.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,8 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::bracketed_paste( char32_t ) {
23022302
}
23032303
if ( ( c == '\r' ) || ( c == KEY::control( 'M' ) ) ) {
23042304
c = '\n';
2305+
} else if ( c == KEY::control( 'I' ) ) {
2306+
c = '\t';
23052307
}
23062308
buf.push_back( c );
23072309
}

tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,11 @@ def test_bracketed_paste( self_ ):
21182118
"x\r\n",
21192119
command = [ ReplxxTests._cSample_, "q1" ]
21202120
)
2121+
self_.check_scenario(
2122+
"<paste-pfx>aaa\n\tbbb<paste-sfx><backspace><backspace><backspace><backspace><backspace><backspace><backspace><backspace><cr><c-d>",
2123+
"<c9><ceos><c18><paste-off>\r\n",
2124+
command = [ ReplxxTests._cxxSample_, "B" ]
2125+
)
21212126
def test_embedded_newline( self_ ):
21222127
self_.check_scenario(
21232128
"<up><c-left><s-cr><cr><c-d>",

0 commit comments

Comments
 (0)