| 541 | } |
| 542 | |
| 543 | std::pair<bool, std::string> string_editor_window::query_string() |
| 544 | { |
| 545 | if( !ctxt ) { |
| 546 | create_context(); |
| 547 | } |
| 548 | |
| 549 | utf8_wrapper edit( ctxt->get_edittext() ); |
| 550 | if( _position == -1 ) { |
| 551 | _position = _utext.length(); |
| 552 | } |
| 553 | |
| 554 | // fold the text |
| 555 | bool refold = true; |
| 556 | // calculate the cursor position |
| 557 | bool reposition = true; |
| 558 | |
| 559 | ui_adaptor ui; |
| 560 | ui.on_screen_resize( [&]( ui_adaptor & ui ) { |
| 561 | _win = _create_window(); |
| 562 | _max.x = getmaxx( _win ); |
| 563 | _max.y = getmaxy( _win ); |
| 564 | _cursor_desired_x = -1; |
| 565 | refold = true; |
| 566 | ui.position_from_window( _win ); |
| 567 | } ); |
| 568 | ui.mark_resize(); |
| 569 | ui.on_redraw( [&]( ui_adaptor & ui ) { |
| 570 | if( refold ) { |
| 571 | utf8_wrapper text = _utext; |
| 572 | if( !edit.empty() ) { |
| 573 | text.insert( _position, edit ); |
| 574 | } |
| 575 | if( _show_line_numbers ) { |
| 576 | _line_number_width = get_line_number_width( text.str(), _line_number_min_width ); |
| 577 | } else { |
| 578 | _line_number_width = 0; |
| 579 | } |
| 580 | const auto gutter_width = _show_line_numbers ? _line_number_width + 1 : 0; |
| 581 | const auto fold_width = std::max( 1, _max.x - 2 - gutter_width ); |
| 582 | _folded = std::make_unique<folded_text>( text.str(), fold_width ); |
| 583 | refold = false; |
| 584 | reposition = true; |
| 585 | } |
| 586 | if( reposition ) { |
| 587 | _cursor_display = get_line_and_position( _position, _cursor_desired_x == 0 ); |
| 588 | if( _cursor_desired_x < 0 ) { |
| 589 | _cursor_desired_x = _cursor_display.x; |
| 590 | } |
| 591 | if( edit.empty() ) { |
| 592 | _ime_preview_range.reset(); |
| 593 | } else { |
| 594 | _ime_preview_range = std::make_unique<ime_preview_range>( ime_preview_range{ |
| 595 | _position, _position + static_cast<int>( edit.size() ), |
| 596 | _cursor_display, get_line_and_position( _position + edit.size() - 1, true ) |
| 597 | } ); |
| 598 | } |
| 599 | reposition = false; |
| 600 | } |
no test coverage detected